window.requestFileSystem||(window.requestFileSystem=window.webkitRequestFileSystem);
Registry.require("promise layout convert xmlhttprequest crcrc curtain tools layout/default/tabview layout/default/htmlutil helper statistics i18n syncinfo uri layout/default/layout_helper porter parser hinter cloud".split(" "),function(){var B=rea.FEATURES,z=Registry.get("promise"),w=Registry.get("crcrc").cr,f=Registry.get("crcrc").crc,Qa=Registry.get("layout/default/tabview"),n=Registry.get("layout/default/htmlutil"),nb=Registry.get("statistics"),ha=Registry.get("syncinfo"),ia=Registry.get("convert"),
Da=Registry.get("tools"),r=Registry.get("curtain"),c=Registry.get("i18n"),u=Registry.get("helper"),ua=Registry.get("uri"),da=Registry.get("porter"),Ra=window.Hinter=Registry.get("hinter"),ob=Registry.get("parser"),Sa=Registry.get("layout"),pa=Registry.get("layout/default/layout_helper"),y=pa.images,Ta=Registry.get("cloud"),Ea=Da.cache,Fa;Sa.render(function(){var va={},v={},K=[],Ua="0.0.0",ba={},Va={},Y={},C=function(){var a,b,e,d,c;if(a=B.HTML5.LOCALSTORAGE)if(b=a.getItem("export_tm_settings"),e=
"true"===b,b=a.getItem("export_externals"),d="false"!==b,b=a.getItem("export_script_storage"),c="false"!==b,b=a.getItem("cloud_config"))try{b=JSON.parse(ia.Base64.decode(b))}catch(m){}return{script_storage:c,add_tm_settings:e,include_externals:d,cloud_config:b}}(),I,A={},P=function(a,b){var e,c;if((e=A[a])&&(c=e[b]))return c.apply(this,Array.prototype.slice.call(arguments,2))},ja=-1!=window.navigator.userAgent.indexOf("Mac")?"mac":"other";window.addEventListener("keydown",function(a){var b,c=!1;if("keydown"==
a.type&&!a.defaultPrevented){if(27==a.keyCode){b=I.getTabById("dashboard");if(!b.isSelected())return;if(a.target&&"text"==a.target.type){$(a.target).blur();return}A.multiselect.toggleRow(!1);c=!0}else if(("mac"!=ja&&39==a.keyCode||"mac"==ja&&40==a.keyCode)&&!a.ctrlKey&&a.altKey&&!a.shiftKey){if(b=I.getNextTab())b.select(),c=!0}else("mac"!=ja&&37==a.keyCode||"mac"==ja&&38==a.keyCode)&&!a.ctrlKey&&a.altKey&&!a.shiftKey&&(b=I.getPreviousTab())&&(b.select(),c=!0);if(c)return a.stopPropagation(),a.preventDefault(),
!1}},!0);window.addEventListener("keydown",function(a){var b,c,d=!1;if("keydown"==a.type&&!a.defaultPrevented){if(112==a.keyCode)(b=I.getTabById("help"))&&b.select(),d=!0;else if((38==a.keyCode||40==a.keyCode)&&a.shiftKey){b=I.getTabById("dashboard");if(!b.isSelected())return;if((b=T.length&&T[T.length-1])&&(b=$(b))&&(d=!0,c=b.closest("tr"),c.length)){var g;38==a.keyCode?(c=c.prevAll("tr:visible:first"),g=!0):(c=c.nextAll("tr:visible:first"),g=!1);if(c.length){var m,h=c.find('input[name="scriptselectors"]');
-1!=T.indexOf(h[0])?(T.pop(),b.prop("checked",!1),b.removeClass("selected"),m=b):h.length&&(h.prop("checked",!0),h.addClass("selected"),T.push(h[0]),void 0===T.direction&&(T.direction=g),m=h);m&&(n.isScrolledIntoView(c,{padding:100})||$("html, body").animate({scrollTop:g?c.offset().top-100-c.height():c.offset().top-$(window).height()+100+2*c.height()},0),A.multiselect.single_click())}}}else if(70==a.keyCode&&(a.ctrlKey||a.metaKey)){b=I.getTabById("dashboard");if(!b.isSelected())return;A.multiselect.toggleRow(!0,
!0);d=!0}else if(65==a.keyCode&&(a.ctrlKey||a.metaKey)){b=I.getTabById("dashboard");if(!b.isSelected()||a.target&&"text"==a.target.type)return;A.multiselect.un_selectAll(!0);d=!0}if(d)return a.stopPropagation(),a.preventDefault(),!1}},!1);var ca,O=function(){var a={},b=function(){ca=u.getUrlArgs(!0);Object.keys(a).forEach(function(b){b=a[b];g.is(b.main,b.sub)&&b.fn()})};b();var c;window.onhashchange=function(){c||b.apply(this,arguments)};var d=function(a){c=!0;a();c=!1},g={set:function(a){var c=g.get(),
e;e="object"===typeof a?[a.main,a.sub].filter(function(a){return a}):arguments;if(c.main!==e[0]||c.sub!==e[1])!e[0]&&e[1]?g.setSub(e[1]):d(function(){window.location.hash="nav="+Array.prototype.join.call(e,"+");b()})},setSub:function(a){var c=g.get();c.sub!==a&&d(function(){window.location.hash="nav="+(c.main?c.main:"")+"+"+a;b()})},get:function(){var a=ca.nav?ca.nav.split("+"):[];return{main:a[0],sub:a[1]}},is:function(a,b){var c=g.get(),d=!b||c.sub===b;return(!a||c.main===a)&&d},isSub:function(a){return g.is(null,
a)},registerListener:function(b,c,d){void 0===d&&(d=c,c=null);var e=[b,c].join("+");a[e]={main:b,sub:c,fn:d};g.is(b,c)&&d();return e},unregisterListener:function(b){delete a[b]},clear:function(){g.set("")}},m=g.get();K.push(function(){var a=I.getTabById(m.main);if(a)return a.select(!0);if(m.main)(a=I.getTabById("dashboard"))&&a.select(!0),K.push(function(){window.setTimeout(function(){g.set(m)},1)});else window.onhashchange()});return g}();(function(){K.push(function(){v.statistics_enabled&&nb.init("opt",
rea.extension.manifest.version,!0,!1,!0)})})();var Ga=u.getDebouncer(1E3),Ha=function(){for(;K.length;)try{K.shift()()}catch(a){console.warn("doneListeners:",a)}},Da=function(a,b){var e=w("input",a.name,a.id,"Save");e.inserted||(e.type="button",e.section=a,e.disabled=!0,e.value=c.getMessage("Save"),e.addEventListener("click",function(){if(!b||!b.warning||qa(b.warning)){for(var a=$(this.section).find("input, select, textarea").toArray(),e=[],m=[],h=0;h<a.length;h++){var f=null,k=a[h],q=k.key;if(-1==
m.indexOf(k)){if("textarea"==k.tagName.toLowerCase())if(k.named)k=document.getElementsByName(k.name),f=[],u.each(k,function(a){f.push({name:a.named_name,value:a.value});m.push(a)});else if(k.array)f=k.value.split("\n").map(function(a){return a.trim()}).filter(function(a){return a});else if(k.json){var t;try{f=(t=k.value)&&(t=t.trim())?JSON.parse(t):null}catch(F){u.alert(c.getMessage("Unable_to_parse_0name0",k.name));return}}else f=k.value;else if("checkbox"==k.getAttribute("type"))f=k.checked;else if("select"==
k.getAttribute("type")){var p=0;0<=k.selectedIndex&&k.selectedIndex<k.options.length&&(p=k.selectedIndex);f=k[p]?k[p].value:k.options[0].value}else"button"!=k.getAttribute("type")&&(f=k.value);q&&e.push(wa(q,f,b&&b.reload))}}b&&b.reload&&(r.wait(),z.when(e).done(function(){rea.page.reload()}))}},!1));return e},rb=function(a,b){var e=function(a,b,c,d,e){var g,k=f("th","settingsth",a.name,a.id,b),m=f("a","settingsth_a",a.name,a.id,b+"_a");m.setAttribute("name","settingsth_a"+a.name);var q=f("a","settingsth_a_up",
a.name,a.id,b+"_a_up");q.setAttribute("name","settingsth_a_up"+a.name);var h=f("a","settingsth_a_down",a.name,a.id,b+"_a_down");h.setAttribute("name","settingsth_a_down"+a.name);var D=function(){var b=document.getElementsByName("settingsth_a_up"+a.name),c=document.getElementsByName("settingsth_a_down"+a.name);for(g=0;g<b.length;g++)b[g].style.display="none";for(g=0;g<c.length;g++)c[g].style.display="none";"up"==ka()?q.style.display="":h.style.display=""},za=function(){D()};b=function(){window.setTimeout(function(){fa()==
d?Xa("down"==ka()?"up":"down"):Ya(d);Za(za)},1)};k.inserted||(k.appendChild(m),k.appendChild(h),k.appendChild(q),m.addEventListener("click",b),q.addEventListener("click",b),h.addEventListener("click",b),m.textContent=c+" ",m.href="#",q.innerHTML="&#x25B4;",q.href="#",h.innerHTML="&#x25BE;",h.href="#");e&&!fa()?(Ya(d),Xa("up"),window.setTimeout(D,1)):d==fa()&&window.setTimeout(D,1);return k},d,g,m,h,l,k;l=w("tbody",a.name,a.id,"body");k=w("thead",a.name,a.id,"head");if(a.scriptTab){var q=pb(a),t=qb(a);
d=w("table",a.name,a.id,"main");d.inserted||d.setAttribute("class","scripttable multiselect");h=f("th","script_sel",a.name,a.id,"thead_sel");h.appendChild(q.selAllm);var p=f("th","left",a.name,a.id,"thead_multi_action");p.setAttribute("colspan",B.RUNTIME.MOBILE?3:11);p.appendChild(q.actionBox);p.appendChild(t);t=f("th","right",a.name,a.id,"thead_multi_close");t.appendChild(q.close);m=f("tr","multiselectrow",a.name,a.id,"filler_multi");m.appendChild([h,p,t]);h=f("tr","multiselectscrolldummy",a.name,
a.id,"scrolldummy");p=f("th","left",a.name,a.id,"scrolldummyth");p.setAttribute("colspan",B.RUNTIME.MOBILE?3:11);h.appendChild([p]);g=f("tr","scripttr multiselectreplaced",a.name,a.id,"filler");p=f("th","script_sel",a.name,a.id,"thead_sel");p.appendChild(q.selAll);var q=e(a,"thead_pos","#","pos"),t=e(a,"thead_en",c.getMessage("Enabled"),"enabled"),F=e(a,"thead_name",c.getMessage("Name"),"name",!0),E=f("th","settingsth",a.name,a.id,"thead_del");E.textContent=c.getMessage("Actions");if(B.RUNTIME.MOBILE)u.each([p,
q,t,F,E],function(a){g.appendChild(a)});else{var G=e(a,"thead_ver",c.getMessage("Version"),"ver"),D=f("th","settingsth ",a.name,a.id,"thead_type"),J=f("span","script_type",a.name,a.id,"thead_type_span");J.textContent=c.getMessage("Type");D.appendChild(J);var x=f("th","settingsth",a.name,a.id,"thead_sync");x.textContent="";J=e(a,"thead_sites",c.getMessage("Sites"),"sites");J.width="25%";var n=f("th","settingsth",a.name,a.id,"thead_features");n.textContent=c.getMessage("Features");var Z=e(a,"thead_homepage",
c.getMessage("Homepage"),"homepage"),e=e(a,"thead_updated",c.getMessage("Last_updated"),"updated"),r=f("th","settingsth",a.name,a.id,"thead_sort"),H=f("span","sorting",a.name,a.id,"thead_sort_span");H.textContent=c.getMessage("Sort");"pos"==fa()&&"up"==ka()||H.setAttribute("style","display: none;");r.appendChild(H);K.push(function(){v.sync_enabled&&(x.textContent=c.getMessage("Imported"))});u.each([p,q,t,F,G,D,x,J,n,Z,e,r,E],function(a){g.appendChild(a)})}k.appendChild([m,h,g]);g.inserted||(A.multiselect.checkScroll=
function(){var a=$(k),c=a.is(":visible")&&$(m).is(":visible")&&0<$(b).scrollTop();a.toggleClass("multiscrolling",c)},$(b).scroll(A.multiselect.checkScroll))}else d=f("table","settingstable",a.name,a.id,"main");d.appendChild(k);d.appendChild(l);return{table:d,head:k,body:l}},$a=function(a,b,c,d){var g,m,h,l,k,q=[];l=function(a,b){if(c)if(c.save_button)$(a).on("change",function(){c.save_button.disabled=!1}),$(b).on("input propertychange",function(){c.save_button.disabled=!1});else if(console.error("Section needs a save button!",
c),Registry.isDevVersion("layout/default/layout_helper"))throw Error("Section needs a save button!");};if(b.divider)return null;b.image&&(b.image_id=y.get(b.image));if(b.checkbox)h=function(){var a=!0,b=this;b.warning&&(a=qa(b.warning),a||(b.checked=!b.checked));a&&wa(this.key,b.checked,b.reload).always(function(){b.reload&&rea.page.reload()})},c&&c.need_save&&(h=m=null),g=n.createCheckbox(b.name,b,h),q.push(g.elem),c&&c.save_button&&l(null,g.input);else if(b.button)g=n.createButton(b.name,b,function(){var a=
!0,b=this;b.warning&&(a=qa(b.warning));a&&sb(b.key,b.data,b.ignore).always(function(){b.reload&&rea.page.reload()})}),q.push(g);else if(b.named)g=n.createNamedSettings(b.name,b),q.push({element:g.elem,validation:g.label}),l(null,g.textareas);else if(b.input)g=n.createTextarea(b.name,b),q.push({element:g.elem,validation:g.label}),l(null,g.textarea);else if(b.text)g=n.createInput(b.name,b),q.push(g.elem),l(g.input);else if(b.color)g=n.createColorChooser(b.name,b),q.push(g.elem),l(g.input);else if(b.password)g=
n.createPassword(b.name,b),q.push(g.elem),l(g.input);else if(b.select)m=function(){var a=!0,b=this;b.warning&&(a=qa(b.warning),a||(b.value=b.oldvalue));a&&wa(b.key,n.getValue(b),b.reload).always(function(){b.reload&&rea.page.reload()})},c&&c.need_save&&(m=b.enabler?function(){var a=document.getElementsByName("enabled_by_"+this.key),b=(this.selectedIndex<this.options.length?this.options[this.selectedIndex]:this.options[0]).getAttribute("enables"),c=b?JSON.parse(b):{};u.each(a,function(a){void 0===
c[a.key]||c[a.key]?a.setAttribute("style",u.staticVars.visible):a.setAttribute("style",u.staticVars.invisible)})}:null),g=n.createDropDown(b.name,b,b.select,m,function(){var a=!0;this.selectedOptions.length&&this.selectedOptions[0].warning&&this.selectedOptions[0].value!==this.oldvalue&&(a=qa(this.selectedOptions[0].warning),a||(this.value=this.previousValue||this.oldvalue));this.previousValue=this.value}),q.push(g.elem),c&&c.save_button&&l(g.select),a&&b.enabler&&function(){var a=m,b=g;K.push(function(){a.apply(b.select,
[])})}();else if(b.url)h=w("a",b.name,b.id),h.href="#",h.url=b.url,h.newtab=b.newtab,h.inserted||(m=function(){Aa(this.url,this.newtab)},h.addEventListener("click",m)),h.textContent=b.name,q=Array(13),q[3]=h;else if(b.main_menu_item){h=w("div",b.name,b.id);h.textContent=b.name;l=w("div",b.name,b.id,"tab_content");k=rb(b,l);l.appendChild(k.table);var t=null,p=d.appendTab(b.id,h,l,function(a){a.then(function(){t&&(va.global?t():K.push(t));O.set(b.id);document.title=b.name})});O.registerListener(b.id,
function(){p.select()});b.referrer&&(t=function(){t=null;R(50);la({referrer:b.referrer},function(b){b.items&&b.items.forEach(function(b){$a(a,b,c,d)});Ha();S();r.hide()})});b.items&&Ba(k.body,b.items,null,d);!va.global&&b.selected_default&&K.push(function(){d.getSelectedTab()||p.select()})}else b.sub_menu_item?(l=f("div","section type_"+b.id,b.name,b.id,"section"),h=f("div","section_head",b.name,b.id,"head"),k=f("table","section_content",b.name,b.id,"content"),h.textContent=b.name,l.appendChild(h),
b.desc&&n.setHelp(b.desc,h,h,b),l.appendChild(k),b.need_save&&(b.save_button=Da(k,b)),Ba(k,b.items,b,d),b.save_button&&k.appendChild(b.save_button),q.push(l)):b.userscript?(q=tb(b,a,d),b.userscript&&(Y[b.uuid]={dom:a,script:b}),a.setAttribute("class","scripttr"),b.nnew?a.setAttribute("style","display: none;"):Ga.is("script_refresh")||(K.push(function(){Ja.init(u.map(Y,function(a){return a.script}));A.multiselect.single_click();Za();va.scripts=!0;Ga.clear()}),Ga.add("script_refresh"))):b.version?(Ua=
b.value,f("div","version","version","version").textContent="v"+Ua+" by Jan Biniok"):b.globalhint?Ka(u.copy(b.options,{onclick:b.options.info_url?function(){Aa(b.options.info_url,!0)}:null})):(h=w("span","",b.uuid||b.id+b.name),h.textContent=b.name,q=Array(13),q[3]=h);q.forEach(function(a){if(a){void 0!==b.level&&(a.element||a).setAttribute("style",b.level>v.configMode?u.staticVars.invisible:u.staticVars.visible||"");if(b.hint){var c=w("span","",b.uuid||b.id+b.name,"hint");c.textContent=b.hint;a.appendChild(c)}b.validation&&
ub(b,a.validation||a.element||a);b.width&&a.setAttribute("class","width-172-"+b.width)}});a&&(k=a.getAttribute("class"),h=" hide",!1===b.visible?k=(k||"")+h:k&&(k=k.replace(h,"")),a.setAttribute("class",k));return q},Ba=function(a,b,c,d){Object.keys(b).forEach(function(g){var m=b[g],h=a?f("tr","settingstr",m.uuid||m.id+m.name,"pi"):null;(g=$a(h,m,c,d))&&g.length&&(a&&a.appendChild(h),u.each(g,function(a,b){var c=a,d="";"Object"===u.toType(a)&&(c=a.element,d=a.style||"");d=f("td",d+" settingstd","",
m.uuid||m.id+m.name,b);a&&d.appendChild(c);h&&h.appendChild(d)}))})},qa=function(a){var b=a.msg||a;if(a.once){if(Va[b])return!0;Va[b]=!0}var b=confirm(b),c={};b&&a.ok?c=a.ok:!b&&a.cancel&&(c=a.cancel);if(a.ok||a.cancel)b=!0;c.url&&sendMessage({method:"newTab",url:c.url},function(){});return b},ub=function(a,b){var c;a.validation&&(a.validation.url&&(c=function(){Aa(this.url,!0)}),c=n.createAfterIcon(a,c))&&(c.url=a.validation?a.validation.url:void 0,b.appendChild(c))},vb=function(a){var b=function(a){return a.url?
{meta:{name:ua.parse(a.url).pathname.split("/").pop(),url:a.url,sri:a.sri,ts:a.ts,mimetype:a.mimetype,modified:a.modified},source:a.data.content}:void 0},c=function(a){return a};return{source:a.code,meta:{name:a.name,uuid:a.uuid,modified:a.lastModified,file_url:a.file_url&&a.file_url.trim()?a.file_url:void 0},storage:a.storage,options:a.options,settings:{enabled:a.enabled,position:a.position},resources:a.resources?a.resources.map(b).filter(c):[],requires:a.requires?a.requires.map(b).filter(c):[]}},
La=function(a){var b=a.meta||{},c=a.settings||{},d=function(a){return{url:a.meta.url,sri:a.meta.sri,ts:a.meta.ts,mimetype:a.meta.mimetype,modified:a.meta.modified,content:a.source}};return{source:a.source,name:b.name,uuid:b.uuid,file_url:b.file_url,options:a.options,storage:a.storage,lastModified:b.modified,enabled:c.enabled,position:c.position,resources:a.resources?a.resources.map(d):[],requires:a.requires?a.requires.map(d):[]}},Ca=function(a,b){var c=z(),d=[];wb(a,b).done(function(a){a.scripts.forEach(function(a){a.uuid&&
a.userscript&&!a.system&&!a.nnew&&(a.code&&""!=a.code.trim()?d.push(vb(a)):console.log("options: Strange script: "+a.name))});c.resolve({scripts:d,global_settings:a.global_settings})}).fail(function(){c.reject()});return c.promise()},xb=function(a){var b,e,d=w("div","help","help","tab_help_h"),g=d.textContent=c.getMessage("Help"),m=w("div","help","help","tab_help");return a.appendTab("help",d,m,function(a){a.then(function(){O.set("help");document.title=g;if(!e){r.wait();var a=f("div","section","help",
"help","ta"),d=f("div","section_head","help","help","head_ta"),q=f("div","section_content","help","help","content_ta");d.textContent=c.getMessage("Editor");a.appendChild([d,q]);var h=f("dl","dl-horizontal shortcuts","help","help","dl");q.appendChild(h);d=f("dt","keymapping","help","help","dt_mapping");b=f("dd","keymapping","help","help","dd_mapping");d.textContent=c.getMessage("Key_Mapping");b.textContent=v.editor_keyMap;h.appendChild([d,b]);if("vim"==v.editor_keyMap)b=f("dd","keymapping","help",
"help","dd_unsup"),b.textContent=c.getMessage("Please_check_the_0editor0_documentation_for_more_details_","VIM"),h.appendChild(b);else if("emacs"==v.editor_keyMap)b=f("dd","keymapping","help","help","dd_unsup"),b.textContent=c.getMessage("Please_check_the_0editor0_documentation_for_more_details_","Emacs"),h.appendChild(b);else{var p=[];e={};var F=function(a){a=a.split(/-+/);var b=a.pop(),c=[],d="";-1!=(d=["up","down","left","right"].indexOf(b.toLowerCase()))&&c.push("#cursor");b.toLowerCase().match(/f[0-9]{1,2}/)&&
c.push("#function");return c.length?c.join("-")+a.join("-")+d+b:("0000"+(100-Math.min(b.length,4))).slice(-4)+b+a.join("-")};[u.assign({Esc:"backOrClose"},"mac"!=ja?{"Alt-Left":"previousTab","Alt-Right":"nextTab"}:{"Alt-Up":"previousTab","Alt-Down":"nextTab"}),CodeMirror.keyMap[v.editor_keyMap],"mac"!=ja?CodeMirror.keyMap.pcDefault:CodeMirror.keyMap.macDefault,CodeMirror.keyMap["default"]].forEach(function(a){Object.keys(a).forEach(function(b){e[b]||"fallthrough"==b||(p.push({name:b,fn:a[b].replace?
a[b].replace(/([A-Z])/g," $1").replace(/ [A-Z]/g,function(a){return a.toLowerCase()}):a[b],sort:F(b)}),e[b]=!0)})});p.sort(function(a,b){return a.sort<b.sort?-1:a.sort>b.sort?1:0});p.forEach(function(a){var b=w("dt","help","help","dt_"+a.sort),c=w("dd","help","help","dd_"+a.sort);b.textContent=a.name;c.textContent=a.fn;h.appendChild([b,c])})}m.appendChild(a);r.hide()}})})},sa=function(){if(B.RUNTIME.FIREFOX)return window.saveAs=function(a,c){var d=URL.createObjectURL(a);ab(d,c,function(){URL.revokeObjectURL(d)})},
z.Pledge();if(B.RUNTIME.SAFARI)return window.saveAs=function(a,c){ia.blob2str(a,function(a){a="data:application/octet-stream;base64,"+ia.Base64.encode(a);ab(a,c)})},z.Pledge();if(B.RUNTIME.EDGE&&window.navigator&&window.navigator.msSaveBlob)return window.saveAs=function(a,c){window.navigator.msSaveBlob(a,c)},z.Pledge();var a=z();Registry.vendor(["vendor/saveas/filesaver"],function(){sa=z.Pledge;a.resolve()});return a.promise()},Ab=function(a){var b={name:"utils",id:"utils"},e=w("div",b.name,b.id,
"tab_util_h"),d=e.textContent=c.getMessage("Utilities"),g=w("div",b.name,b.id,"tab_util");a.appendTab(b.id,e,g,function(a){a.then(function(){O.set(b.id);document.title=d})}).show();a=f("div","tv_util",b.name,b.id,"tab_util_cont");var m=function(){Ta.init(function(a){var b=z(),c=rea.extension.connect("tabWatch");c.onMessage.addListener(function(a){b&&((a=a.tab)?b.notify(a):(b.resolve(),b=null,c.disconnect()))});c.onDisconnect.addListener(function(){b&&b.resolve()});c.postMessage({method:"tabWatch",
url:a.url});return{promise:b.promise(),close:function(){b&&b.resolve();c.disconnect()}}});m=null},h={},l=function(a){var b,c;b="webdav"==a&&(c=C.cloud_config)?{url:c.url,basic_auth:ia.Base64.encode(c.user+":"+c.pass)}:{};return h[a]=h[a]||Ta[a](b)},k=function(){return Ca(null,{storage:C.script_storage,global_settings:C.add_tm_settings,externals:C.include_externals}).then(function(a){r.wait();return da.zip.create(a.scripts,a.global_settings).progress(r.wait)})},q=function(a){var b=z(),c=new FileReader;
c.onload=function(a){b.resolve(a.target.result)};c.readAsText(a);return b.promise()},t=function(a){for(var b=0,d;d=a[b];b++)da.zip.read(d).progress(r.wait).then(function(a){return Ma({scripts:u.map(a.scripts,function(a){return La(a)}),global_settings:a.global_settings},{reload:!0})}).done(function(a){a.err&&u.alert(a.err)}).fail(function(){u.alert(c.getMessage("Unable_to_parse_this_"))}).always(r.hide)},p=n.createButton(b.name,b.id+"_i_ta",c.getMessage("Import"),function(){da.json.read(A.value).then(function(a){return Ma({scripts:u.map(a.scripts,
function(a){return La(a)}),global_settings:a.global_settings},{reload:!0})}).done(function(a){a.err&&u.alert(a.err)}).fail(function(){u.alert(c.getMessage("Unable_to_parse_this_"))})}),F=n.createFileSelect(c.getMessage("Import"),{name:"zip",id:b.id},function(a){r.wait();return t(a)}),E=n.createFileSelect(c.getMessage("Import"),{name:"file",id:b.id},function(a){r.wait();for(var b,d=0;b=a[d];d++)q(b).then(function(a){return da.json.read(a)}).then(function(a){return Ma({scripts:u.map(a.scripts,function(a){return La(a)}),
global_settings:a.global_settings},{reload:!0})}).done(function(a){a.err&&u.alert(a.err)}).fail(function(){u.alert(c.getMessage("Unable_to_parse_this_"))}).always(r.hide)}),G=n.createButton(b.name,b.id+"_i_cloud",c.getMessage("Show_backups"),function(){r.wait();var a=Q.select.value,b=Q.select.selectedOptions[0].text;m&&m();l(a).list().progress(function(a){0<a.total&&r.wait(b+": "+Math.floor(a.loaded/a.total*100)+"%")}).then(function(a){a=a.filter(function(a){return a.name.match(/\.zip$/)});return a.length?
a:z.Breach("empty")}).then(function(b){var d=z(),e=$('<table class="nowrap file_select">');$('<thead><tr><th colspan="3">'+c.getMessage("Please_select_a_file")+":</th></tr></thead>").appendTo(e);b.sort(function(a,b){return a.modified-b.modified}).forEach(function(b){var g=$('<input class="button" type="button" value="'+c.getMessage("Import")+'">').click(function(){d.resolve(b);r.hideDialog();r.wait()}),k=$('<input class="button" type="button" value="'+c.getMessage("Delete")+'">').click(function(){m.hide();
l(a).delete(b)}),m=$("<tr><td>"+[n.safeTagsReplace(b.name),pa.formatBytes(b.size,2),(new Date(b.modified)).toLocaleString().replace((new Date).toLocaleDateString(),c.getMessage("Today"))].join("</td><td>")+"</td></tr>");$("<td>").append(g,k).appendTo(m);m.appendTo(e)});b=$('<input class="button" type="button" value="'+c.getMessage("Cancel")+'">').click(function(){d.reject("cancel");r.hideDialog()});$("<tfoot>").append($("<tr>").append($('<td colspan="3">').append(b))).appendTo(e);r.hide();r.dialog(e[0]);
return d.promise()}).then(function(c){return l(a).get(c).progress(function(a){0<a.total&&r.wait(b+": "+Math.floor(a.loaded/a.total*100)+"%")})}).then(function(a){return t([a])}).fail(function(a){var b;"empty"===a?b=c.getMessage("No_backups_found"):"cancel"!=a&&("auth_failed"==a?console.warn("cloud: Authentication failed"):b=c.getMessage("Error")+": "+(a||c.getMessage("Action_failed")));b&&u.alert(b);r.hide()})}),e=n.createButton(b.name,b.id+"_i_url",c.getMessage("Install"),function(){r.wait();return zb(ya.value,
{reload:!0}).fail(function(a){a=a.err?a.err:c.getMessage("Unable_to_parse_this_");u.alert(a)}).always(r.hide)}),D=n.createButton(b.name,b.id+"_e_ta",c.getMessage("Export"),function(){r.wait();Ca(null,{storage:C.script_storage,global_settings:C.add_tm_settings,externals:C.include_externals}).then(function(a){return da.json.create(a.scripts,a.global_settings)}).done(function(a){A.value=a}).always(r.hide)}),J=n.createButton(b.name,b.id+"_e_file",c.getMessage("Export"),function(){r.wait();Ca(null,{storage:C.script_storage,
global_settings:C.add_tm_settings,externals:C.include_externals}).then(function(a){return da.json.create(a.scripts,a.global_settings).then(function(a){return sa().done(function(){var b=new Blob([a],{type:"text/plain"});saveAs(b,u.safeFileName("tampermonkey-backup-"+B.RUNTIME.BROWSER+"-"+(new Date).toISOString()+".txt"))})})}).always(r.hide)}),x=n.createButton(b.name,b.id+"_e_zip",c.getMessage("Export"),function(){return k().then(function(a){return sa().done(function(){saveAs(a,u.safeFileName("tampermonkey-backup-"+
B.RUNTIME.BROWSER+"-"+(new Date).toISOString()+".zip"))})}).always(r.hide)}),ea=n.createButton(b.name,b.id+"_e_zip",c.getMessage("Export"),function(){var a=z(),b=Q.select.value,d=Q.select.selectedOptions[0].text,e=function(a){return k().then(function(c){r.wait(d+"...");m&&m();return l(b).put(a+".zip",c).progress(function(a){0<a.total&&r.wait(d+":"+Math.floor(a.loaded/a.total*100)+"%")})}).fail(function(a){u.alert(c.getMessage("Error")+": "+(a||c.getMessage("Action_failed")))}).always(r.hide)};u.prompt(c.getMessage("Name"),
"backup-"+B.RUNTIME.BROWSER+"-"+(new Date).toISOString(),function(b){b?a.consume(e(b)):a.reject("aborted")});return a.promise()}),Z=n.createCheckbox(c.getMessage("Include_TM_settings"),{id:b.id+"_e_export_tm_settings",enabled:"true"},function(){C.add_tm_settings=this.checked;B.HTML5.LOCALSTORAGE&&B.HTML5.LOCALSTORAGE.setItem("export_tm_settings",C.add_tm_settings)});Z.elem.setAttribute("style","padding-left: 2px");Z.input.checked=C.add_tm_settings;var N=n.createCheckbox(c.getMessage("Include_script_storage"),
{id:b.id+"_e_export_storage",enabled:"true"},function(){C.script_storage=this.checked;B.HTML5.LOCALSTORAGE&&B.HTML5.LOCALSTORAGE.setItem("export_script_storage",C.script_storage)});N.elem.setAttribute("style","padding-left: 2px; display: inline");N.input.checked=C.script_storage;var H=n.createCheckbox(c.getMessage("Include_script_externals"),{id:b.id+"_e_export_externals",enabled:"true"},function(){C.include_externals=this.checked;B.HTML5.LOCALSTORAGE&&B.HTML5.LOCALSTORAGE.setItem("export_externals",
C.include_externals)});H.elem.setAttribute("style","padding-left: 2px");H.input.checked=C.include_externals;var A=f("textarea","importta",b.name,b.id,"ta");A.setAttribute("spellcheck","false");var y=f("div","section",b.name,b.id,"ta"),M=f("div","section_head",b.name,b.id,"head_ta"),V=f("div","section_content",b.name,b.id,"content_ta");M.textContent=c.getMessage("General");V.appendChild(N.elem);V.appendChild(Z.elem);V.appendChild(H.elem);y.appendChild(M);y.appendChild(V);Z=f("div","section",b.name,
b.id,"ta");N=f("div","section_head",b.name,b.id,"head_ta");H=f("div","section_content",b.name,b.id,"content_ta");N.textContent=c.getMessage("TextArea");H.appendChild(D);H.appendChild(p);H.appendChild(A);Z.appendChild(N);Z.appendChild(H);p=f("div","section",b.name,b.id,"sb");D=f("div","section_head",b.name,b.id,"head_sb");N=f("div","section_content",b.name,b.id,"content_sb");D.textContent=c.getMessage("Zip");p.appendChild(D);p.appendChild(N);N.appendChild(x);N.appendChild(F.elem);var F=f("div","section",
b.name,b.id,"sb"),x=f("div","section_head",b.name,b.id,"head_sb"),D=f("div","section_content",b.name,b.id,"content_sb"),U=function(){$(ra).toggle("webdav"===this.value);var a=l(this.value);$(xa).toggle(a&&!!a.revoke)},Q=n.createDropDown(c.getMessage("Type"),{id:"cloud_type",value:"edge"==B.RUNTIME.BROWSER?"onedrive":"drive"},[{name:c.getMessage("Google_Drive"),value:"drive"},"safari"==B.RUNTIME.BROWSER?null:{name:c.getMessage("Dropbox"),value:"dropbox"},{name:c.getMessage("OneDrive"),value:"onedrive"},
"safari"==B.RUNTIME.BROWSER?null:{name:c.getMessage("Yandex_Disk"),value:"yandex"},"safari"==B.RUNTIME.BROWSER?null:{name:c.getMessage("WebDAV"),value:"webdav"}].filter(function(a){return a}),U),M=function(a){return function(){h={};var b;(C.cloud_config=C.cloud_config||{})[a]=this.value;(b=B.HTML5.LOCALSTORAGE)&&b.setItem("cloud_config",ia.Base64.encode(JSON.stringify(C.cloud_config)))}},N=n.createInput(c.getMessage("URL"),{id:"select_cloud_url",uuid:b.uuid,value:(C.cloud_config?C.cloud_config.url:
null)||""},M("url")),H=n.createInput(c.getMessage("Login"),{id:"select_cloud_username",uuid:b.uuid,value:(C.cloud_config?C.cloud_config.user:null)||""},M("user")),M=n.createInput(c.getMessage("Password"),{id:"select_cloud_password",uuid:b.uuid,password:!0,value:(C.cloud_config?C.cloud_config.pass:null)||""},M("pass")),ra=[N.elem,H.elem,M.elem];K.push(function(){U.apply(Q.select,[])});x.textContent=c.getMessage("Cloud");F.appendChild(x);F.appendChild(D);D.appendChild([Q.elem].concat(ra));D.appendChild(ea);
D.appendChild(G);var xa=n.createButton("revoke_token_button",b.uuid,c.getMessage("Revoke_Access_Token"),function(){$(xa).prop("disabled",!0);l(Q.select.value).revoke().always(function(){$(xa).prop("disabled",!1)})});D.appendChild(xa);G=f("div","section",b.name,b.id,"fi");ea=f("div","section_head",b.name,b.id,"head_fi");x=f("div","section_content",b.name,b.id,"content_fi");ea.textContent=c.getMessage("File");G.appendChild(ea);G.appendChild(x);x.appendChild(J);x.appendChild(E.elem);var ya=f("input",
"updateurl_input",b.name,b.id,"url");ya.setAttribute("type","text");ya.setAttribute("spellcheck","false");E=f("div","section",b.name,b.id,"ur");J=f("div","section_head",b.name,b.id,"head_ur");ea=f("div","section_content",b.name,b.id,"content_ur");J.textContent=c.getMessage("Install_from_URL");E.appendChild(J);E.appendChild(ea);ea.appendChild(ya);ea.appendChild(e);a.appendChild(y);"undefined"!==typeof Blob&&a.appendChild(F);B.RUNTIME.CAN_SAVEAS_ZIP&&a.appendChild(p);"undefined"!==typeof Blob&&a.appendChild(G);
a.appendChild(Z);a.appendChild(E);u.each([Z],function(a){var b=a.getAttribute("class"),b=50>v.configMode?b+" hide":b.replace(" hide","");a.setAttribute("class",b)});g.appendChild(a)},Bb=function(){var a=f("div","content_wrapper","options","main"),b=f("div","status","options","status");$(document.body).append(a,b).addClass("main");var b=f("div","head_container","opt","head_container"),e=f("div","tv_container_fit","opt","tv_container"),d=w("a","head_link","heads","head_link");d.href="https://www.tampermonkey.net";
d.target="_blank";var g=f("div","float","heads","head1"),m=f("img","banner","heads");m.src=y.brand("tampermonkey");var h=f("div","float head","heads","head2"),l=f("div","header_title","heads"),k=f("div","version","version","version");k.textContent=" by Jan Biniok";var q=w("div","search","box",""),t=f("div","footer","footer");l.innerHTML="Tampermonkey<sup>\u00ae</sup>";g.appendChild(m);h.appendChild(l);h.appendChild(k);d.appendChild(g);d.appendChild(h);b.appendChild(d);b.appendChild(q);a.appendChild(b);
a.appendChild(e);window.tab_view=I=Qa.create("_main",e);I.setFooter(t);K.unshift(function(){Ab(I);xb(I)});K.push(function(){void 0!==ca.contribute&&window.setTimeout(function(){bb("f")},100);va.global=!0});window.onbeforeunload=function(a){var b;I.getAllTabs().forEach(function(a){b=b||a.modified()});return b?c.getMessage("There_are_unsaved_changed_"):void 0}},aa=function(a,b,e,d){void 0===d&&(d={});var g=b.item,m=g.uuid+(d.orig||"")+b.id,h=(d.orig?"orig_":"use_")+b.id,l=function(a){return"select_"+
u.createUniqueId(a,g.uuid)+"_sel1"},k=f("div","cludes",a,m,"cb1"),q=w("span",a,m,"cb2");if(d.orig){var t="merge_"+b.id,t=n.createCheckbox(a,{id:t,uuid:g.uuid,enabled:g.options&&g.options.override&&g.options.override[t]?!0:!1},function(){if("checkbox"==this.type){var a={};a[this.key]=this.checked;ga(this.uuid,a)}});q.appendChild(t.elem)}else q.textContent=a;var p=f("select","cludes",h,g.uuid,"sel1");p.innerHTML="";p.setAttribute("size","6");p.setAttribute("multiple","true");for(h=0;h<e.length;h++)t=
document.createElement("option"),t.value=t.text=e[h],p.appendChild(t);k.appendChild(q);g.desc&&n.setHelp(g.desc,k,q,g);k.appendChild(p);var F=function(a){var b=[];a=a&&a.options;for(var c=0,d=a.length;c<d;c++)a[c].selected&&b.push(a[c]);return b},h=function(){var a=l("use_"+("excludes"==b.id?"includes":"excludes")),c=document.getElementById(a),a=F(p),d=!1,e="matches"==b.id;a.forEach(function(a){var b=e?"/"+ua.getRegExpFromMatch(a.value)+"/":a.value;a&&!c.querySelector('option[value="'+b+'"]')&&(a=
a.cloneNode(!0),e&&(a.value=b,a.textContent=b),c.appendChild(a),d=!0)});d&&G()},t=function(){var a=prompt(c.getMessage("Enter_the_new_rule"));if(a){var b=document.createElement("option");b.value=b.text=a.trim();p.appendChild(b);G()}},q=function(){var a=p.options[p.selectedIndex];if(a){var b=prompt(c.getMessage("Enter_the_new_rule"),a.value);b&&(a.value=a.text=b.trim(),G())}};e=function(){var a=!1;F(p).forEach(function(b){b&&(b.parentNode.removeChild(b),a=!0)});a&&G()};var E=function(a){for(var b=
[],c=0;c<a.options.length;c++)b.push(a.options[c].value);return b},G=function(){var a={includes:E(document.getElementById(l("use_includes"))),matches:E(document.getElementById(l("use_matches"))),excludes:E(document.getElementById(l("use_excludes"))),connects:E(document.getElementById(l("use_connects"))),temp_connects:E(document.getElementById(l("use_temp_connects"))),blockers:E(document.getElementById(l("use_blockers")))};ga(g.uuid,a);return!0};d.other_name?(a=w("button",a,m,"btn1",!0),a.textContent=
c.getMessage("Add_as_0clude0",d.other_name),a.addEventListener("click",h,!1),k.appendChild(a)):d.orig||(d=w("button",a,m,"btn2",!0),d.textContent=c.getMessage("Add")+"...",d.addEventListener("click",t,!1),k.appendChild(d),d=w("button",a,m,"btn3",!0),d.textContent=c.getMessage("Edit")+"...",d.addEventListener("click",q,!1),k.appendChild(d),a=w("button",a,m,"btn4",!0),a.textContent=c.getMessage("Remove"),a.addEventListener("click",e,!1),k.appendChild(a));return{elem:k}},Na=function(a){return a.homepage?
a.homepage:a.namespace&&0==a.namespace.search(/https?:\/\//)?a.namespace:null};Ea.create("sites").setOptions({timeout:600,check_interval:300,retimeout_on_get:!0}).init();var Ja=function(){var a={},b=function(a){return 7>a.toString().length?b("0"+a):a},c=function(a){if(a.includes||a.matches){for(var b={},c=[],e=a.includes.length?a.includes:a.matches,f=0;f<e.length;f++){var k=e[f];if(k){var q=Ea.items.sites.get(k),t=void 0!==q?q:n.getInfoFromUrl(k);void 0===q&&Ea.items.sites.set(k,t);t&&t.dom?b[t.dom]||
(b[t.dom]=!0,c.push({include:k,info:t})):c.push({include:k})}else console.log("o: Warn: script '"+a.name+"' has invalid include (index: "+f+")")}return c}};return{init:function(b){a={};b.forEach(function(b){(b=c(b))&&b.length&&b.forEach(function(b){b.info&&(a[b.info.dom]=(a[b.info.dom]||0)+1)})})},get:function(d){d=c(d);if(!d||!d.length)return b(0);d=u.map(d,function(b){return b.info?{score:1E3*a[b.info.dom]+b.info.dom.charCodeAt(0)||0,dom:b.info.dom}:{score:0,dom:""}}).sort(function(a,b){return b.score-
a.score})[0];return b(d.score)+d.dom},topIcons:function(b,g){var m,h=[],l=c(b);if(!l||!l.length)return[];l=u.map(l,function(b){b.score=b.info?a[b.info.dom]||0:0;return b}).sort(function(a,b){return b.score-a.score});u.each(l,function(a){var c=a.info;if(0==g--)return a=f("span","",b.uuid,"tbc"),a.textContent="...",h.push(a),!1;if(c){if("*"==c.tld)return m=n.createIcon(y.get("web"),"web",b.uuid,a.include,a.include),h.push(m),!1;var e="com",p="";"*"!=c.tld&&"tld"!=c.tld&&(e=c.tld);c.subdom.length&&(p=
c.subdom.join(".")+".");e=(p+c.dom+"."+e).replace(/\*/g,"");p="http://"+e+"/";c=B.RUNTIME.CHROME?"chrome://favicon/"+p:null;e=0==p.search("http://userscripts.org/")||0==p.search("http://userscripts.com/")?y.origin("uso"):"native"==v.favicon_service?p+"favicon.ico":"duckduckgo"==v.favicon_service?"https://icons.duckduckgo.com/ip2/"+encodeURIComponent(e)+".ico":"https://www.google.com/s2/favicons?domain="+encodeURIComponent(e);m=n.createFavicon([e,c,function(){return y.get("question_mark")}].filter(function(a){return a}),
"favicon",b.uuid,a.include,a.include)}else m=n.createIcon(y.get("question_mark"),"favicon",b.uuid,a.include,a.include);h.push(m)});return h}}}(),fa=function(){if(B.HTML5.LOCALSTORAGE)return B.HTML5.LOCALSTORAGE.getItem("sort_key")},ka=function(){if(B.HTML5.LOCALSTORAGE)return B.HTML5.LOCALSTORAGE.getItem("sort_sequence")},Ya=function(a){if(B.HTML5.LOCALSTORAGE)return B.HTML5.LOCALSTORAGE.setItem("sort_key",a)},Xa=function(a){if(B.HTML5.LOCALSTORAGE)return B.HTML5.LOCALSTORAGE.setItem("sort_sequence",
a)},Za=function(a){var b=function(a,c){return a.tagName==c?a:a.parentNode?b(a.parentNode,c):null},e="down"==ka(),d=null,g=[],f=0,h=Date.now();Object.keys(Y).forEach(function(a){var e=Y[a];if(e)if(a=b(e.dom,"TR")){var t=b(a,"TBODY");d?t&&d!=t&&console.warn("options: different parents?!?!"):d=t;f++;var p,l;if(!(p=e.script.lastModified||e.script.lastUpdated)||(l=h-parseInt(p))&&isNaN(l))l=0;g.push({tr:a,sites:Ja.get(e.script),enabled:e.script.enabled,position:e.script.position?e.script.position:1E3+
f,name:c.getTranslation(e.script,"name").toLowerCase(),homepage:[e.script.origin?ua.parse(e.script.origin.url).hostname:"z",Na(e.script)?ua.parse(Na(e.script)).hostname:"z"].join("_"),updated:l,version:e.script.version||""});a.inserted=!1;a.parentNode&&a.parentNode.removeChild(a)}else console.log("options: unable to sort script at pos "+e.pos);else console.warn("options: something went wrong!",a)});g=function(a){var b;b=function(a){return function(b,c){return b[a]-c[a]}};var c=function(a){return function(b,
c){return ob.versionCmp(String(b[a]),String(c[a]))}},d=function(a){return function(b,c){return b[a]<c[a]?-1:b[a]>c[a]?1:0}},g=function(a,b){return function(c,d){var e=(b^c[a]?"a":"b")+c.name,g=(b^d[a]?"a":"b")+d.name;return e<g?-1:e>g?1:0}},f=fa();"pos"==f?b=b("position"):"enabled"==f?(b=g("enabled",e),e=null):b="ver"==f?c("version"):"updated"==f?b("updated"):d(f);a.sort(b);return a}(g);e&&(g=g.reverse());for(var l=0;l<f;l++)d.appendChild(g[l].tr);$(".sorting").each(function(a,b){var c=$(b),d="pos"==
fa()&&"up"==ka();c[d?"fadeIn":"fadeOut"]()});a&&a()},Fb=function(a,b,e,d,g){e=w("div",b.uuid,"script_tab_head");var m=e.inserted,h=f("table","noborder p100100 heading",b.uuid,"h_table"),l=f("tr","",b.uuid,"h_tr1"),k=f("td","nameNicon64",b.uuid,"h_td1"),q=f("td","",b.uuid,"h_td2");h.appendChild(l);l.appendChild(k);l.appendChild(q);q.setAttribute("style","width: 99%");var l=w("img",b.uuid,"heading_icon"),t=b.icon64?b.icon64:b.icon;l.src=t;var p=f("div","nameNname64",b.uuid,"heading_name");p.textContent=
c.getTranslation(b,"name");t&&k.appendChild(l);q.appendChild(p);k=f("div","author",b.uuid,"author");b.author?k.textContent="by "+b.author:b.copyright&&(k.innerHTML="&copy; ",k.textContent+=b.copyright);q.appendChild(k);q=f("table","noborder p100100",b.uuid,"table");k=f("tr","script_tab_head",b.uuid,"tr1");l=f("tr","details",b.uuid,"tr2");t=f("td","",b.uuid,"td1");p=f("td","",b.uuid,"td2");e.appendChild(h);t.appendChild(e);k.appendChild(t);l.appendChild(p);q.appendChild(k);q.appendChild(l);d.appendChild(q);
var n=Qa.create("_details"+b.uuid,p,{tv:"tv tv_alt",tv_table:"tv_table tv_table_alt",tr_tabs:"tr_tabs tr_tabs_alt",tr_content:"tr_content tr_content_alt",td_content:"td_content td_content_alt",td_tabs:"td_tabs td_tabs_alt",tv_tabs_align:"tv_tabs_align tv_tabs_align_alt",tv_tabs_fill:"tv_tabs_fill tv_tabs_fill_alt",tv_tabs_table:"tv_tabs_table tv_tabs_table_alt",tv_contents:"tv_contents tv_contents_alt",tv_tab_selected:"tv_tab tv_selected tv_tab_alt tv_selected_alt",tv_tab_close:"tv_tab_close",tv_tab:"tv_tab tv_tab_alt",
tv_content:"tv_content tv_content_alt"},!0),E=cb(b,n,{do_close:g,set_tab_class:function(b,c){a.toggleClass(b,c)},navid:"editor",treeid:"source"}),G=b.nnew||b.system?{}:Cb(b,n),D=b.nnew||b.system||!b.storage_key_count||80>v.configMode?{}:Db(b,n),J=b.nnew||b.system||!b.requires.length&&!b.resources.length?{}:Eb(b,n);if(m)return ba["tab"+b.uuid];var x=function(){var a;return(a=n.getSelectedTab())&&a.isCloseable()?J.getEditor():E.getEditor()},r=function(b){var c=!1;if("keydown"==b.type&&a.isSelected()&&
!b.defaultPrevented){if(27==b.keyCode){if(!v.editor_enabled||"vim"!=v.editor_keyMap){var d;(d=n.getSelectedTab())&&d.isCloseable()?d.close():window.setTimeout(g,1);c=!0}}else if(v.editor_enabled){var e={save:!0,find:!0,findNext:!0,findPrev:!0,replace:!0,replaceAll:!0},k=x();d=CodeMirror.keyName(b);k&&!k.hasFocus()&&"handled"==CodeMirror.lookupKey(d,k.getOption("keyMap"),function(a){if(e[a])return k.execCommand(a),!0})&&(c=!0)}else 83==b.keyCode&&(b.ctrlKey||b.metaKey)&&(d=x())&&(d.save(),c=!0);if(c)return b.stopPropagation(),
b.preventDefault(),!1}};d={onShow:function(){u.each([G,E,D,J],function(a){if(a.onShow)a.onShow()});window.addEventListener("keydown",r,!1)},onClose:function(a){var b;u.each([G,E,D,J],function(c){if(c.onClose&&c.onClose(a))return b=!0,!1});b||window.removeEventListener("keydown",r,!1);return b},onSelect:function(a){a.then(function(){if(b.uuid){var a=O.get().sub,d=n.getTabById(a);O.set(b.uuid,(d?a:null)||"editor");document.title=c.getTranslation(b,"name")}});u.each([G,E,J],function(b){if(b.onSelect)b.onSelect(a)})}};
return ba["tab"+b.uuid]=d},Cb=function(a,b){var e=w("div",a.uuid,"script_setting_h"),d=w("div",a.uuid,"script_settings_c");e.textContent=c.getMessage("Settings");var g=function(){var a={};if("checkbox"==this.type)a[this.key]=!!this.checked,ga(this.uuid,a);else if("button"==this.type)a[this.key]=!this.oldvalue,ga(this.uuid,a);else if("text"==this.type||"textarea"==this.type||"select-one"==this.type){var b=n.getValue(this);a[this.key]=b;ga(this.uuid,a)}},m=n.createCheckbox(c.getMessage("Enabled"),{id:"enabled",
uuid:a.uuid,name:"upd",enabled:a.enabled},g).elem,h=n.createPosition(c.getMessage("Position_")+": ",{id:"position",uuid:a.uuid,name:"pos",pos:a.position,posof:a.positionof},g),l=n.createDropDown(c.getMessage("Run_at"),{id:"run_at",uuid:a.uuid,name:"run-at",value:a.run_at},[{name:"document-start",value:"document-start"},{name:"document-body",value:"document-body"},{name:"document-end",value:"document-end"},{name:"document-idle",value:"document-idle"},{name:"context-menu",value:"context-menu"},{name:c.getMessage("Default"),
value:null}],g),k=n.createDropDown(c.getMessage("No_frames"),{id:"noframes",uuid:a.uuid,name:"no_frames",value:a.noframes},[{name:c.getMessage("Yes"),value:!0},{name:c.getMessage("No"),value:!1},{name:c.getMessage("Default"),value:null}],g),q=n.createCheckbox(c.getMessage("Check_for_Updates"),{id:"check_for_updates",uuid:a.uuid,name:"upd",enabled:a.check_for_updates}),t=n.createInput(c.getMessage("Update_URL_"),{id:"file_url",uuid:a.uuid,name:"uu",value:a.file_url});t.input.setAttribute("class","updateurl_input");
t.elem.setAttribute("class","updateurl");a.is_external&&t.input.setAttribute("readonly","true");var p=function(b){return(a.options&&a.options.override?a.options.override[b]:null)||[]},F=aa(c.getMessage("Original_includes"),{id:"includes",item:a},p("orig_includes"),{orig:!0,other_name:c.getMessage("User_excludes")}),E=aa(c.getMessage("Original_matches"),{id:"matches",item:a},p("orig_matches"),{orig:!0,other_name:c.getMessage("User_excludes")}),G=aa(c.getMessage("Original_excludes"),{id:"excludes",
item:a},p("orig_excludes"),{orig:!0,other_name:c.getMessage("User_includes")}),D=f("div","clear",a.uuid,"clear"),J=aa(c.getMessage("User_includes"),{id:"includes",item:a},p("use_includes")),x=aa(c.getMessage("User_matches"),{id:"matches",item:a},p("use_matches")),r=aa(c.getMessage("User_excludes"),{id:"excludes",item:a},p("use_excludes")),u=aa(c.getMessage("Original_domain_whitelist"),{id:"connects",item:a},a.connects,{orig:!0}),v=aa(c.getMessage("Temporary_domain_whitelist"),{id:"temp_connects",
item:a},a.temp_connects),A=aa(c.getMessage("User_domain_whitelist"),{id:"connects",item:a},p("use_connects")),p=aa(c.getMessage("User_domain_blacklist"),{id:"blockers",item:a},p("use_blockers")),y=n.createCheckbox(c.getMessage("Apply_compatibility_options_to_required_script_too"),{id:"compatopts_for_requires",uuid:a.uuid,name:"",enabled:a.compatopts_for_requires},g),B=n.createCheckbox(c.getMessage("Fix_wrappedJSObject_property_access"),{id:"compat_wrappedjsobject",uuid:a.uuid,name:"",enabled:a.compat_wrappedjsobject},
g),M=n.createCheckbox(c.getMessage("Convert_CDATA_sections_into_a_chrome_compatible_format"),{id:"compat_metadata",uuid:a.uuid,name:"",enabled:a.compat_metadata},g),V=n.createCheckbox(c.getMessage("Replace_for_each_statements"),{id:"compat_foreach",uuid:a.uuid,name:"",enabled:a.compat_foreach},g),U=n.createCheckbox(c.getMessage("Fix_for_var_in_statements"),{id:"compat_forvarin",uuid:a.uuid,name:"",enabled:a.compat_forvarin},g),Q=n.createCheckbox(c.getMessage("Convert_Array_Assignements"),{id:"compat_arrayleft",
uuid:a.uuid,name:"",enabled:a.compat_arrayleft},g),z=n.createCheckbox(c.getMessage("Add_toSource_function_to_Object_Prototype"),{id:"compat_prototypes",uuid:a.uuid,name:"",enabled:a.compat_prototypes},g),C=[y,B,M,V,U,Q,z],y=f("div","section",a.uuid,"ta_opt"),M=f("div","section_head",a.uuid,"head_ta_opt"),B=f("div","section_content",a.uuid,"content_ta_opt");M.textContent=c.getMessage("Settings");y.appendChild(M);y.appendChild(B);M=f("div","section",a.uuid,"ta_upd");U=f("div","section_head",a.uuid,
"head_ta_upd");V=f("div","section_content",a.uuid,"content_ta_upd");U.textContent=c.getMessage("Updates");M.appendChild(U);M.appendChild(V);U=f("div","section",a.uuid,"ta_cludes");z=f("div","section_head",a.uuid,"head_ta_cludes");Q=f("div","section_content",a.uuid,"content_ta_cludes");z.textContent=c.getMessage("Includes_Excludes");U.appendChild(z);U.appendChild(Q);var z=f("div","section",a.uuid,"ta_security"),K=f("div","section_head",a.uuid,"head_ta_security"),I=f("div","section_content",a.uuid,
"content_ta_security");K.textContent=c.getMessage("XHR_Security");z.appendChild(K);z.appendChild(I);var K=f("div","section",a.uuid,"ta_compat"),P=f("div","section_head",a.uuid,"head_ta_compat"),za=f("div","section_content",a.uuid,"content_ta_compat");P.textContent=c.getMessage("GM_compat_options_");K.appendChild(P);K.appendChild(za);B.appendChild(m);B.appendChild(h);B.appendChild(l.elem);B.appendChild(k.elem);m=n.createButton("save_update_button",a.uuid,c.getMessage("Save"),function(){g.apply(q.input,
[]);a.is_external||g.apply(t.input,[])});V.appendChild([q.elem,t.elem,m]);Q.appendChild([F.elem,E.elem,G.elem,D,J.elem,x.elem,r.elem]);I.appendChild([u.elem,v.elem,A.elem,p.elem]);d.appendChild([y,M,U,z]);for(F=0;F<C.length;F++)za.appendChild(C[F].elem);a.awareOfChrome&&Object.keys(C).forEach(function(a){C[a].input.setAttribute("disabled","disabled");C[a].elem.setAttribute("title",c.getMessage("This_script_runs_in_Chrome_mode"))});d.appendChild(K);var Ia=n.createTextarea(null,{name:"",uuid:a.uuid,
id:"comment",value:a.options.comment});Ia.elem.setAttribute("class","script_setting_wrapper");F=w("div",a.uuid,"save");E=n.createButton("save_button",a.uuid,c.getMessage("Save"),function(){g.apply(Ia.textarea,[])});F.appendChild(E);E=f("div","section",a.uuid,"ta_comment");G=f("div","section_head",a.uuid,"head_ta_comment");D=f("div","section_content",a.uuid,"content_ta_comment");G.textContent=c.getMessage("Comment");E.appendChild(G);E.appendChild(D);D.appendChild(Ia.elem);D.appendChild(F);d.appendChild(E);
F=f("div","section",a.uuid,"ta_det");E=f("div","section_head",a.uuid,"head_ta_det");G=f("div","section_content",a.uuid,"content_ta_det");E.textContent=c.getMessage("Details");F.appendChild(E);F.appendChild(G);E.textContent=c.getMessage("Details");var Wa=f("table","script_details",a.uuid,"script_details");[{label:c.getMessage("Size"),value:pa.formatBytes((a.code?a.code:a).length,2)},{label:c.getMessage("UUID"),value:a.uuid}].forEach(function(b){var c=f("tr","external_desc",a.uuid,b.label,"tr"),d=f("td",
"external_desc",a.uuid,b.label,"td1"),e=f("td","",a.uuid,b.label,"td2");d.textContent=b.label;e.textContent=b.value;c.appendChild(d);c.appendChild(e);Wa.appendChild(c)});G.appendChild(Wa);d.appendChild(F);var yb=b.appendTab("settings",e,d,function(a){a.then(function(){O.setSub("settings")})});O.registerListener(a.uuid,"settings",function(){yb.select()});return{}},db=function(a,b,e,d){var g=f("table","externals",a.uuid,"outer_req2html",b,!0),m=0,h=[{label:c.getMessage("URL"),prop:"display_url"},{label:c.getMessage("Size"),
prop:"data",fn:function(a){var b="?";a&&(void 0!==a.length?b=a.length:void 0!==a.content&&(b=a.content.length));return pa.formatBytes(b,2)}},{label:c.getMessage("MIME_Type"),prop:"mimetype"},{label:c.getMessage("Subresource_Integrity"),prop:"sri",fn:function(a){return a?a.type+"="+a.value:c.getMessage("_not_set_")}},{label:c.getMessage("Last_updated"),prop:"ts",fn:function(a){return a?(new Date(a)).toString():null}}];h.push({label:c.getMessage("User_modified"),prop:"modified",klass:"validation",title:c.getMessage("This_external_resource_will_not_auto_update__Please_delete_it_in_order_to_enable_updates_again_"),
icon:y.get("info"),fn:function(a){return a?c.getMessage("Yes"):null}});a[b].forEach(function(k){var l=m+u.createUniqueId(k.url)+b;h.forEach(function(b){var c,d=f("tr","",a.uuid,b.prop,"tr"+l),e=f("td","external_label",a.uuid,b.prop,"td1"+l),h=f("td","external_desc",a.uuid,b.prop,"td2"+l);e.textContent=b.label;h.textContent=c=(b.fn?b.fn:function(a){return a})(k[b.prop]);null!==c&&(b.klass&&$(h).addClass(b.klass),b.title&&h.setAttribute("title",b.title),b.icon&&(c=f("span","validation",a.uuid,"validation",
"span"+l),c.appendChild(n.createIcon(b.icon+" red","warning",a.uuid,l+"no_require_update_warning")),h.appendChild(c)),d.appendChild(e),d.appendChild(h),g.appendChild(d))});var p=f("tr","external_desc_buttons",a.uuid,k.url,"tr"+l),F=f("td","",a.uuid,"buttons","td"+l);p.appendChild(F);g.appendChild(p);if(k.ts){if("requires"==b||k.editable){var p=w("span",a.uuid,"edit_external"+l),E=n.createImageTextButton(a.uuid,"edit_external"+l,c.getMessage("Edit"),"edit",function(){Gb(e,a.uuid,k,d)});p.appendChild(E);
F.appendChild(p)}var p=w("span",a.uuid,"delete_external"+l),G=n.createImageTextButton(a.uuid,"delete_external"+l,c.getMessage("Delete"),"delete",function(){Hb(a.uuid,k.url);G.parentNode&&G.parentNode.removeChild(G)});p.appendChild(G);F.appendChild(p)}m++});if(!m){var l=f("tr","script_desc",a.uuid,m,"tr"),k=f("td","script_desc",a.uuid,m,"td1");k.textContent=c.getMessage("No_entry_found");l.appendChild(k);g.appendChild(l)}return g},Gb=function(a,b,e,d){var g="externals-"+b+"-"+e.url;A[g]={};var f=Ib({uuid:g,
script_uuid:b,mimetype:e.mimetype,name:c.getMessage("Externals")+" - "+e.url,file_url:e.url,referrer:"options.scripts.userscripts"},a,function(){d(f.getEditor())},function(){delete ba["tab"+g];delete ba["editor"+g];delete A[g]});f.show()},Eb=function(a,b){var e,d=function(a){e=a},g=w("div","",a.uuid,"script_external_h");g.textContent=c.getMessage("Externals");var m=w("div","",a.uuid,"script_externals_c"),h=f("div","section",a.uuid,"ta_requires"),l=f("div","section_head",a.uuid,"head_ta_requires"),
k=f("div","section_content",a.uuid,"content_ta_requires");l.textContent=c.getMessage("Requires");h.appendChild(l);h.appendChild(k);k.appendChild(db(a,"requires",b,d));var l=f("div","section",a.uuid,"ta_resources"),k=f("div","section_head",a.uuid,"head_ta_resources"),q=f("div","section_content",a.uuid,"content_ta_resources");k.textContent=c.getMessage("Resources");l.appendChild(k);l.appendChild(q);q.appendChild(db(a,"resources",b,d));m.appendChild(h);m.appendChild(l);var t=b.appendTab("externals",
g,m,function(a){a.then(function(){O.setSub("externals")})});O.registerListener(a.uuid,"externals",function(){t.select()});return{getEditor:function(){return e}}},Db=function(a,b){var e=function(a,b){if("string"===typeof a){var c=a[0];a=a.substr(1);switch(c){case "b":return"true"===a;case "n":return Number(a);case "o":try{return JSON.parse(a)}catch(d){console.log("values: parseValueFromStorage: "+d)}return b;default:return a}}else return b},d=w("div","",a.uuid,"script_storage_h");d.textContent=c.getMessage("Storage");
var g=w("div","",a.uuid,"script_storages_c"),m=f("div","section",a.uuid,"ta_storage"),h=f("div","section_head",a.uuid,"head_ta_storage"),l=f("div","section_content",a.uuid,"content_ta_storage");h.textContent=c.getMessage("Storage");m.appendChild(h);m.appendChild(l);var k=f("textarea","storageta",a.uuid,"storage");k.setAttribute("wrap","off");k.setAttribute("wrap","off");k.setAttribute("spellcheck","false");h=n.createButton("storage_save_button",a.uuid,c.getMessage("Save"),function(){var b=null;try{b=
JSON.parse(k.value)}catch(d){u.alert(c.getMessage("Unable_to_parse_this_"));return}var e=Object.keys(b),g=Object.keys(a.storage);e.concat(g).filter(function(a,b,c){return c.lastIndexOf(a)===b}).forEach(function(c){if(-1==e.indexOf(c))eb(a.uuid,c);else if(-1==g.indexOf(c)||b[c]!==a.storage[c]){var d=eb,k=a.uuid,f;a:{f=b[c];var h=(typeof f)[0];switch(h){case "o":try{f=h+JSON.stringify(f)}catch(m){console.log(m);f=void 0;break a}break;default:f=h+f}}d(k,c,f)}})});l.appendChild(k);l.appendChild(h);g.appendChild(m);
var q=b.appendTab("storage",d,g,function(a){a.then(function(){O.setSub("storage")})});O.registerListener(a.uuid,"storage",function(){(function(){if(a.referrer&&void 0===a.storage){var b=z();la({referrer:a.referrer+".storage",uuid:a.uuid},function(a){if(a.items){var c={},d=a.items[0];Object.keys(d).forEach(function(a){c[a]=e(d[a])});b.resolve(c)}else b.reject();r.hide()});return b.promise()}return z.Pledge(a.storage)})().done(function(b){k.value=k.value||JSON.stringify(b,null,4);a.storage=b;k.removeAttribute("disabled")}).fail(function(){k.setAttribute("disabled",
!0)});q.select()});return{}},Ib=function(a,b,c,d){var g;a.is_external=!0;var f=function(){g&&!h.onClose()&&(d(),g&&g.remove(),g=null)},h=cb(a,b,{tab_name:a.name,navid:a.uuid,treeid:"external",mimetype:a.mimetype,tree_opts:{url:a.file_url,uuid:a.script_uuid},do_close:function(){window.setTimeout(f,100)},on_tab_close:f,on_tab_select:c,on_editor_load:c});g=h.getTab();h.show=function(){h.onShow();g.select()};return h},cb=function(a,b,e){var d=f("tr","editor_container p100100",a.uuid,"container"),g=e.mimetype||
"text/javascript",m=!g||/(application|text)\/(?:x-)?(?:java|ecma)script/.test(g);if(!a.nnew&&P(a.uuid,"lastI"))return ba["editor"+a.uuid]||{};a.nnew&&(a.code=v.script_templates[0].value.replace("<$URL$>",ca.url?ia.Base64.decode(ca.url):"http://*/*"));var h=w("div",a.uuid,"script_editor_h"),l=h.inserted,k=w("div",a.uuid,"script_editor_c"),q=f("tr","editormenubar",a.uuid,"container_menu"),t=f("tr","editorbuttonbar",a.uuid,"container_button_menu"),p=f("table","editor_container_o p100100 noborder",a.uuid,
"container_o");p.appendChild(t);p.appendChild(q);p.appendChild(d);k.appendChild(p);var F=function(){var b=!1;d.editor&&(b=v.editor_enabled?b|(d.editor.changed&&d.editor.mirror.historySize().undo):d.editor.value!=a.code);return b},E=function(){CodeMirror.commands.trimTrailingSpacesIfEnabled(d.editor.mirror);P(a.uuid,"saveEm")},G=function(a,b,c){e.do_close&&e.do_close(b,c)},p=function(){confirm(c.getMessage("Really_factory_reset_this_script_"))&&A[a.uuid].fullReset(function(a){a.cleaned&&G(null,!0,
!1)})},D=function(a){d.editor.changed!=a&&(e.set_tab_class&&e.set_tab_class("modified",a),I.toggleClass("modified",a));d.editor.changed=a},J=function(){window.setTimeout(function(){var a;v.editor_enabled&&(a=d.editor)&&(r.wait(),window.setTimeout(function(){(function(){var b=a.mirror.performLint(!0);return b&&b.then?b:z.Pledge(b)})().then(function(){var b=a.mirror.state.lint?a.mirror.state.lint.marked:null;if(b&&b.length){1===b.length?fb(c.getMessage("One_error_or_hint_was_found_")):fb(c.getMessage("0count0_errors_or_hints_were_found_",
b.length));for(var d,e=0;d=b[e];e++){var g,k;void 0!==d.line&&void 0!==d.column?(g=d.line,k=d.column):d.lines&&d.lines.length&&(d=d.lines[0],g=d.lineNo()+1,k=d.markedSpans&&d.markedSpans.length?d.markedSpans[0].from+1:1);if(g&&k){a.mirror.setCursor(g-1,k-1);a.mirror.focus();break}}}else gb(c.getMessage("No_syntax_errors_were_found_"));r.hide()})},100))},1)},x=f("td","",a.uuid,"editor_buttonmenu_td");t.appendChild(x);var B=f("ul","editormenu",a.uuid,"editormenu"),t=f("td","",a.uuid,"editormenu_td");
t.appendChild(B);var C,N,H=function(a,b){var c,d;a&&(c=$(a),d=b?c.hasClass("visible"):!1);$("ul.editormenu .submenu").removeClass("visible");a?(c.toggleClass("visible",!d),N=d?null:a):N=null;a&&d||(C=function(a){var b;C&&(b=$(a.target))&&!b.closest(".editormenu").length&&(H(),document.body.removeEventListener("click",C),C=null)},document.body.addEventListener("click",C))},L=function(b,c){var d=f("li","entry",a.uuid,b,"editormenuentry",!0),e=w("label",a.uuid,b,"editormenulabel_id");e.textContent=c;
var g=f("table","submenu noborder",a.uuid,"editormenucontent"+b);d.appendChild([e,g]);d.addEventListener("click",function(a){$(a.target).closest(".entry").hasClass("list")||H(g,!0)});d.addEventListener("mousemove",function(){N&&N!=this&&H(g)});return{elem:d,content:g}},K=function(a){return function(){d.editor.mirror.focus();d.editor.mirror.execCommand(a)}},M={file:{text:c.getMessage("File"),entries:[{text:c.getMessage("Save"),command:"save",image:y.get("filesave"),cb:E},{text:c.getMessage("Save_to_disk"),
command:"save_to_disk",image:y.get("save_to_disk"),cb:function(){P(a.uuid,"saveToDisk")}},{type:"sep"},{command:"cancel",text:c.getMessage("Editor_reset"),image:y.get("editor_cancel"),cb:function(){confirm(c.getMessage("Really_reset_all_changes_"))&&d.editor&&(v.editor_enabled?(d.editor.mirror.setValue(a.code),D(!1)):d.editor.value=a.code)}},{type:"sep"},{text:c.getMessage("Close"),command:"close",image:y.get("exit"),cb:G}]},edit:{text:c.getMessage("Edit"),entries:[{text:c.getMessage("Undo"),command:"undo"},
{text:c.getMessage("Redo"),command:"redo"},{type:"sep"},{text:c.getMessage("Cut"),command:"cut"},{text:c.getMessage("Copy"),command:"copy"},{text:c.getMessage("Paste"),command:"paste"},{text:c.getMessage("Select_All"),command:"selectAll"},{type:"sep"},{text:c.getMessage("Toggle_Comment"),command:"toggleComment"},{text:c.getMessage("Toggle_Comment_Indented"),command:"toggleCommentIndented"},{text:c.getMessage("Toggle_Block_Comment"),command:"toggleBlockComment",modes:["js"]},{type:"sep"},{id:"edit_lines",
text:c.getMessage("Lines"),modes:["js"],entries:[{text:c.getMessage("Indent"),command:"intelligentTab"},{text:c.getMessage("Indent_Less"),command:"indentLess"},{text:c.getMessage("Indent_More"),command:"indentMore"},{text:c.getMessage("Auto_Indent_all"),command:"reindentall"},{type:"sep"},{text:c.getMessage("Move_Line_Up"),command:"swapLineUp"},{text:c.getMessage("Move_Line_Down"),command:"swapLineDown"},{text:c.getMessage("Duplicate_Lines"),command:"duplicateLine"},{text:c.getMessage("Delete_Line"),
command:"deleteLine"},{text:c.getMessage("Join_Lines"),command:"joinLines"},{type:"sep"},{text:c.getMessage("Insert_Line_Before"),command:"insertLineBefore"},{text:c.getMessage("Insert_Line_After"),command:"insertLineAfter"}]},{id:"edit_text",text:c.getMessage("Text"),entries:[{text:c.getMessage("Upper_Case"),command:"upcaseAtCursor"},{text:c.getMessage("Lower_Case"),command:"downcaseAtCursor"},{type:"sep"},{text:c.getMessage("Delete_Line_Left"),command:"delLineLeft"},{text:c.getMessage("Delete_Line_Right"),
command:"delLineRight"},{text:c.getMessage("Delete_to_Previous_Word_Boundary"),command:"delGroupBefore"},{text:c.getMessage("Delete_to_Next_Word_Boundary"),command:"delGroupAfter"},{text:c.getMessage("Delete_Line"),command:"deleteLine"},{type:"sep"},{text:c.getMessage("Transpose"),command:"transposeChars"}]},{id:"edit_sort",text:c.getMessage("Sort"),entries:[{text:c.getMessage("Lines"),command:"sortLines"},{text:c.getMessage("Line_Case_Insensitive"),command:"sortLinesInsensitive"}]},{id:"edit_folding",
text:c.getMessage("Folding"),entries:[{text:c.getMessage("Fold"),command:"fold"},{text:c.getMessage("Unfold"),command:"unfold"},{text:c.getMessage("Fold_All"),command:"foldAll"},{text:c.getMessage("Unfold_All"),command:"unfoldAll"}]},{id:"edit_sublime_mark",text:c.getMessage("Sublime_Mark"),entries:[{text:c.getMessage("Set_Sublime_Mark"),command:"setSublimeMark"},{text:c.getMessage("Select_to_Sublime_Mark"),command:"selectToSublimeMark"},{text:c.getMessage("Swap_with_Sublime_Mark"),command:"swapWithSublimeMark"},
{text:c.getMessage("Delete_to_Sublime_Mark"),command:"deleteToSublimeMark"},{text:c.getMessage("Yank_Sublime_Mark"),command:"sublimeYank"}]}]},selection:{text:c.getMessage("Selection"),entries:[{text:c.getMessage("Incremental_Find"),command:"selectMatchingPartsOfCurrentSelection"},{text:c.getMessage("Add_Selection_Above"),command:"selectLinesUpward"},{text:c.getMessage("Add_Selection_Below"),command:"selectLinesDownward"},{text:c.getMessage("Split_into_Lines"),command:"splitSelection"},{type:"sep"},
{text:c.getMessage("Incremental_Find"),command:"selectMatchingPartsOfCurrentSelection"},{type:"sep"},{text:c.getMessage("Select_Line"),command:"selectLine"},{text:c.getMessage("Select_Scope"),command:"selectScope"},{text:c.getMessage("Select_Bookmarks"),command:"selectBookmarks"},{text:c.getMessage("Select_between_Brackets"),command:"selectBetweenBrackets"},{text:c.getMessage("Select_Next_Occurrence"),command:"selectNextOccurrence"}]},find:{text:c.getMessage("Find"),entries:[{text:c.getMessage("Find"),
command:"find"},{text:c.getMessage("Replace"),command:"replace"},{text:c.getMessage("Replace_All"),command:"replaceAll"},{type:"sep"},{text:c.getMessage("Find_Next"),command:"findNext"},{text:c.getMessage("Find_Previous"),command:"findPrev"},{text:c.getMessage("Find_Under"),command:"findUnder"},{text:c.getMessage("Find_All_Under"),command:"findAllUnder"},{text:c.getMessage("Find_Under_Previous"),command:"findUnderPrevious"},{type:"sep"},{text:c.getMessage("Incremental_Find"),command:"selectMatchingPartsOfCurrentSelection"}]},
goto:{text:c.getMessage("GoTo"),entries:[{text:c.getMessage("Jump_to_line"),command:"jump"},{text:c.getMessage("Document_Start"),command:"goDocStart"},{text:c.getMessage("Document_End"),command:"goDocEnd"},{text:c.getMessage("Group_Left"),command:"goGroupLeft"},{text:c.getMessage("Group_Right"),command:"goGroupRight"},{text:c.getMessage("Closing_Bracket"),command:"goToBracket"},{text:c.getMessage("Line_Up"),command:"goLineUp"},{text:c.getMessage("Line_Down"),command:"goLineDown"},{type:"sep"},{text:c.getMessage("Center_Cursor"),
command:"showInCenter"},{type:"sep"},{id:"bookmarks",text:c.getMessage("Bookmarks"),entries:[{text:c.getMessage("Toggle"),command:"toggleBookmark"},{text:c.getMessage("Clear_All"),command:"clearBookmarks"},{type:"sep"},{text:c.getMessage("Next_Bookmark"),command:"nextBookmark"},{text:c.getMessage("Prev_Bookmark"),command:"prevBookmark"}]}]},dev:{text:c.getMessage("Developer"),entries:[{command:"macro",text:c.getMessage("Insert_constructor"),modes:["js"]}].concat(!a.system&&v.editor_enabled&&m?[{type:"sep"},
{text:c.getMessage("Run_syntax_check"),command:"lint_script",image:y.get("check"),cb:J},{text:c.getMessage("Auto_Indent_all"),command:"reindentall"}]:[]).concat(a.nnew||a.is_external?[]:[{type:"sep"},{text:c.getMessage("Full_reset"),command:"reset",image:y.get("script_cancel"),cb:p}]).concat(a.nnew?[{type:"sep"},{id:"templates",text:c.getMessage("Templates"),entries:v.script_templates.map(function(a){return{text:a.name,command:a.name,image:y.get("dot"),cb:function(){if(!F()||confirm(c.getMessage("Really_reset_all_changes_"))){var b=
a.value;d.editor&&(v.editor_enabled?(d.editor.mirror.setValue(b),D(!1)):d.editor.value=b)}}}})}]:[])}},V=function(a,b){var c=b[0],d,e;if(d=a[c])return V(d,b.slice(1));a.entries&&a.entries.some(function(a){if(a.command==c)return e=a,!0;if(a.entries&&(e=V(a,b)))return!0});return e};"file.save_to_disk file.save file.cancel dev.reset find.findNext find.findPrev edit.replace goto.jump edit.reindentall dev.lint_script file.close".split(" ").forEach(function(b){(b=V(M,b.split(".")))&&(b.image?x.appendChild(n.createImageButton(a.uuid,
b.id||b.command,b.text,b.image,b.cb||K(b.command))):x.appendChild(n.createButton(b.id||b.command,a.uuid,b.text,b.cb||K(b.command))))});var U=function(a,b){var c=b||CodeMirror.keyMap[v.editor_keyMap],d,e;Object.keys(c).every(function(b){return c[b]==a?(d=b,!1):!0});if(d)return d;if(c.fallthrough&&(e=CodeMirror.keyMap[c.fallthrough])&&e!==c)return U(a,e)},Q=function(b,c){return c.map(function(c,d){if(!c.modes||-1!=c.modes.indexOf(m?"js":"other")){if("sep"==c.type){var e=b+d,g=f("tr","entry sep",a.uuid,
"editorsubmenusep_tr"+e),k=w("td",a.uuid,"editorsubmenusep_td"+e),e=w("hr",a.uuid,"editorsubmenusep"+e);k.setAttribute("colspan",4);g.appendChild(k);k.appendChild(e);return g}if(c.command){var h=b+"_"+c.command,l=c.text,p=c.image,g=U(c.command),k=c.cb||K(c.command),e=!!c.cb||CodeMirror.commands.hasOwnProperty(c.command),q=f("tr","entry "+(e?"":"disabled"),a.uuid,h,"editorsubmenuentry_tr",!0),n;n=p?f("i","far fa-"+p,a.uuid,h,"editorsubmenuentry_i",!0):f("i","far",a.uuid,h,"editorsubmenuentry_i",!0);
p=w("td",a.uuid,"editorsubmenuentry_td_i"+h);p.appendChild(n);n=f("td","label",a.uuid,"editorsubmenuentry_td_l"+h);n.textContent=l;h=f("td","shortcut",a.uuid,"editorsubmenuentry_td_m"+h);h.setAttribute("colspan",2);g&&(h.textContent=g);q.appendChild([p,n,h]);e&&q.addEventListener("click",k);return q}k=b+c.id;e=c.text;q=c.image;g=f("tr","entry list",a.uuid,k,"editorsubmenulistentry",!0);h=q?f("i","far fa-"+q,a.uuid,k,"editorsubmenulistentry_i",!0):f("i","far",a.uuid,k,"editorsubmenulistentry_i",!0);
q=w("td",a.uuid,"editorsubmenulistentry_td_i"+k);q.appendChild(h);h=f("td","label",a.uuid,"editorsubmenulistentry_td_l"+k);h.textContent=e;l=f("td",a.uuid,"editorsubmenulistentry_td_m"+k);e=w("td",a.uuid,"editorsubmenulistentry_td_s"+k);g.appendChild([q,h,l,e]);q=f("span","submenulist",a.uuid,"editorsubmenulistcontent"+k);h=f("span","submenumore",a.uuid,"editorsubmenulistmore"+k);l=f("i","more far fa-caret-right",a.uuid,k,"editorsubmenulistentrymore_i",!0);h.appendChild([l,q]);e.appendChild([l,h]);
k=Q(k,c.entries);if(0<k.length)return q.appendChild(k),g}}).filter(function(a){return a})};Object.keys(M).forEach(function(a){var b=M[a],c=L(a,b.text);a=Q(a,b.entries);0<a.length&&(B.appendChild(c.elem),c.content.appendChild(a))});p=f("textarea","editorta",a.uuid,"editor");p.setAttribute("wrap","off");p.setAttribute("spellcheck","false");var J=f("td","editor_outer",a.uuid,"edit"),ra=f("div","editor_100 editor_border",a.uuid,"edit");J.appendChild(ra);q.appendChild(t);d.inserted||(ra.appendChild(p),
d.appendChild(J));A[a.uuid].saveToDisk=function(){if(d.editor){var b=v.editor_enabled?d.editor.mirror.getValue():d.editor.value;r.wait();return sa().done(function(){var c=new Blob([b],{type:"text/plain"});saveAs(c,u.safeFileName(a.name+(a.is_external?"":".user.js")))}).always(function(){r.hide()})}};a.system||(A[a.uuid].saveEm=a.is_external?function(b){if(d.editor){var e=v.editor_enabled?d.editor.mirror.getValue():d.editor.value;Jb(a.script_uuid,e,{url:a.file_url,mimetype:a.mimetype,auto_save:b&&
b.auto_save}).done(function(a){a.success?D(!1):a.aborted||b&&b.auto_save||(a.messages&&a.messages.errors&&a.messages.errors.length?u.alert(a.messages.errors.join("\n")):u.alert(c.getMessage("Unable_to_parse_this_")))})}}:function(b){if(d.editor){var e=!0;v.showFixedSrc&&(e=confirm(c.getMessage("Do_you_really_want_to_store_fixed_code_",c.getMessage("Show_fixed_source"))));var g=v.editor_enabled?d.editor.mirror.getValue():d.editor.value;e&&Oa(a.uuid,g,{clean:!1,new_script:a.nnew,auto_save:b&&b.auto_save,
reload:!0,lastModTime:A[a.uuid].saveEm_lastModTime}).done(function(d){d.installed?a.nnew?G(null,!0,!1):(D(!1),d.lastModified&&(a.lastModTime=d.lastModified)):d.aborted||b&&b.auto_save||(d.messages&&d.messages.errors&&d.messages.errors.length?u.alert(d.messages.errors.join("\n")):u.alert(c.getMessage("Unable_to_parse_this_")))});return e}});var I=b.insertTab(null,e.navid,h,k,function(a){a.then(function(){O.setSub(e.navid);if(e.on_tab_select)e.on_tab_select()})},e.on_tab_close);I.setHeading(e.tab_name||
c.getMessage("Editor"),50);O.registerListener(a.uuid,e.navid,function(){I.select();v.editor_enabled&&d.editor&&(d.editor.refresh(),d.editor.mirror.focus())});if(l)return ba["editor"+a.uuid];var R=function(a,b,c,d){a=d.getValue();if((a=d.getHelper(CodeMirror.Pos(0,0),"lint")(a,c,d))&&a.then)return a.then(b);b(a)},S=function(a){wa("editor_theme",a,!0).done(function(){gb("Theme switched to "+a)})},T=function(){v.editor_autoSave&&F()&&P(a.uuid,"saveEm",{auto_save:!0})};b={getTab:function(){return I},
getEditor:function(){if(d.editor)return v.editor_enabled?d.editor.mirror:{save:E}},onShow:function(){(function(){if(a.referrer&&void 0===a.code){var b=z();la(u.copy(e.tree_opts||{},{referrer:a.referrer+"."+e.treeid,uuid:a.uuid}),function(c){c.items?(a.code=c.items[0],b.resolve()):b.reject();r.hide()});return b.promise()}return z.Pledge()})().done(function(){var b=k.getElementsByTagName("textarea");A[a.uuid].lastI=function(){return a};if(b.length&&!d.editor){var b=b[0],f=function(){d.editor&&D(!!d.editor.mirror.historySize().undo)};
if(v.editor_enabled){var h=b.parentNode;h.removeChild(b);d.editor=new MirrorFrame(h,{mode:g,theme:v.editor_theme,fontSize:v.editor_fontSize,themeOptions:{all:Sa.getEditorThemes().map(function(a){return a.value}),onChange:S},value:a.code,indentUnit:Number(v.editor_indentUnit),indentWithTabs:"tabs"==v.editor_indentWithTabs,smartIndent:"classic"!=v.editor_tabMode,indentByTab:"indent"==v.editor_tabMode,electricChars:"true"==v.editor_electricChars.toString(),lineNumbers:!0,lineWrapping:v.editor_lineWrapping,
extraKeys:{Enter:"newlineAndIndentContinueComment"},keyMap:v.editor_keyMap,bookmarkGutter:!0,gutters:["gutter","CodeMirror-linenumbers","CodeMirror-foldgutter","CodeMirror-lint-markers","CodeMirror-bookmarks"],matchBrackets:!0,foldGutter:!0,styleActiveLine:!0,specifyMoreJsTokens:m,styleSelectedText:!0,autoTrimTrailingSpace:"true"==v.editor_trimTrailingSpacesFromModifiedLines.toString(),hintOptions:m?{keywords:Object.keys(Ra.globals)}:void 0,lint:m?{lintOnChange:v.editor_autoLint,autoLintMaxLen:v.editor_autoLintMaxLen,
async:!0,getAnnotations:R,hint_config:v.editor_linter_config||Ra.config}:void 0,showTrailingSpace:v.editor_highlightTrailingWhitespace},{save:E,close:G},{change:f,blur:T},c.getMessage)}else d.editor=b,b.value=a.code;if(e.on_editor_load)e.on_editor_load()}}).fail(function(){G(null,!1,!0)})},onClose:function(b){var e=function(){d.editor=null;delete A[a.uuid].lastI};if(!b&&F())return(b=confirm(c.getMessage("There_are_unsaved_changed_")))&&e(),!b;e();return!1}};return ba["editor"+a.uuid]=b},tb=function(a,
b,e){A[a.uuid]||(A[a.uuid]={});var d,g,m=a.icon,h=[];h.push("clickable");(a.blacklisted||a.foisted)&&h.push("crossedout");var l=f("span",h.join(" "),a.uuid,"sname"),k=f(m?"img":"span","nameNicon16 icon16 "+(m?"nameNicon16":"nameNOicon16"),a.uuid,"sname_img"),q=f("span","nameNname16 "+(a.enabled?"":"greyed"),a.uuid,"sname_name");l.appendChild(k);var h=Na(a),t=c.getTranslation(a,"name");q.textContent=t;var p=w("span",a.uuid,"spos");p.textContent=a.position||"";t=w("span",a.uuid,"sversion");t.textContent=
a.version?a.version:"";m&&(k.src=a.icon);var m=[],k=function(a,b,c){var d=f("span",c||"",a.uuid,"wrap");b&&("Array"===u.toType(b)?u.each(b,function(a){d.appendChild(a)}):d.appendChild(b));return d},r=function(){window.setTimeout(function(){for(var c=Object.keys(Y),d,g=0;d=c[g];g++)if(d=Y[d].script,d.uuid==a.uuid){Ba(b,[d],null,e);break}Ha()},1)},E=function(b,c){void 0===c&&(c=!b);g&&g.onClose&&g.onClose(b)||(a.uuid&&O.is(a.uuid)&&O.clear(),d&&(d.remove(),d=null),delete ba["tab"+a.uuid],delete ba["editor"+
a.uuid],l.parentNode&&l.parentNode.removeChild(l),c&&r())},G=function(a){if(g&&g.onSelect)g.onSelect(a)},D=A[a.uuid].scriptClick=function(k,h){if(!d){var m=null;a.nnew?(m=f("div","head_icon",a.uuid,"details_h"),m.appendChild(n.createIcon(a.image_id,"",a.uuid,"new_script_head"))):m=w("div",a.uuid,"details_h");var l=w("div",a.uuid,"details_c");d=e.insertTab(null,a.uuid,m,l,G,a.nnew?null:E);a.nnew||d.setHeading(c.getMessage("Edit")+" - "+c.getTranslation(a,"name"),50);g=Fb(d,a,b,l,E)}if(g&&g.onShow)g.onShow();
d.show();k&&1==k.button||h||d.select();q.setAttribute("open","true")};"true"==q.getAttribute("open")&&D(null,!0);var J=function(a,b){var c=a.getTime(),d=b.getTime(),e=Math.abs(c-d),c=Math.round(e/6E4),d=Math.round(e/36E5),e=Math.round(e/864E5);return 60>=c?c+" min":48>=d?d+" h":e+" d"},x=w("span","",a.uuid,"last_updated",!0),z="?";if(a.nnew||a.system)z="";else if(A[a.uuid].scriptUpdate=function(){var b=x.textContent;x.textContent="";x.appendChild(n.createIcon(y.get("download"),"down",a.uuid,"spinner"));
Kb(a.uuid,function(d){x.textContent=b;d?($(x).addClass("green"),x.title=c.getMessage("There_is_an_update_for_0name0_avaiable_",a.name),E(!0),hb()):($(x).addClass("red"),x.title=c.getMessage("No_update_found__sry_"))})},a.options.check_for_updates&&a.file_url&&"none"!=a.file_url?(x.addEventListener("click",function(){P(a.uuid,"scriptUpdate")}),x.setAttribute("class","clickable"),x.title=c.getMessage("Check_for_Updates")):(x.setAttribute("class","greyed italic"),x.title=c.getMessage("Update_check_is_disabled")),
a.lastModified||a.lastUpdated)try{z=J(new Date,new Date(a.lastModified||a.lastUpdated))}catch(M){console.log("o: error calculating time "+M.message)}x.textContent=z;var C=w("div",a.uuid,"imported"),N="";K.push(function(){v.sync_enabled&&(N=a.nnew||a.system?"":a.sync&&a.sync.imported?a.sync.imported==ha.types.eCHROMESYNC?B.RUNTIME.FIREFOX?'<img src="'+y.brand("firefox")+'" class="icon16" title="Firefox Sync"/>':'<img src="'+y.brand("chrome")+'" class="icon16" title="Google Sync"/>':a.sync.imported==
ha.types.eGDRIVE?'<img src="'+y.brand("gdrive")+'" class="icon16" title="Google Drive"/>':a.sync.imported==ha.types.eDROPBOX?'<img src="'+y.brand("dropbox")+'" class="icon16" title="Dropbox"/>':a.sync.imported==ha.types.eWEBDAV?'<img src="'+y.brand("webdav")+'" class="icon16" title="WebDAV"/>':a.sync.imported==ha.types.eYANDEX?'<img src="'+y.brand("yandex")+'" class="icon16" title="Yandex"/>':a.sync.imported==ha.types.eONEDRIVE?'<img src="'+y.brand("onedrive")+'" class="icon16" title="OneDrive"/>':
'<i class="icon16 far fa-'+y.get("question_mark")+'" />':"",C.innerHTML=N,C=null)});var H,J=w("span",a.uuid,"hp");if(a.origin){H=w("a",a.uuid,"hp_origin");H.setAttribute("href",a.origin.url);H.setAttribute("target","_blank");var L=n.createImage(y.origin(a.origin.token),"",a.uuid,a.origin.token);H.appendChild(L);J.appendChild(H)}!h||a.origin&&a.origin.url===h||(H=w("a",a.uuid,"hp_script"),H.setAttribute("href",h),H.setAttribute("target","_blank"),L=n.createIcon(y.get("home"),"",a.uuid,"homepage",""),
H.appendChild(L),J.appendChild(H));A[a.uuid].saveEm_lastModTime=a.lastModified;A[a.uuid].fullReset=function(c){Oa(a.uuid,null,{clean:!0,reload:!0}).done(c||function(){});b.parentNode.removeChild(b)};A[a.uuid].reportAnIssue=function(b){Lb(a.uuid,b)};A[a.uuid].deleteScript=function(d,e){1==(e||confirm(c.getMessage("Really_delete_0name0__",a.name)))&&(Oa(a.uuid,null,{reload:!e}),b.parentNode.removeChild(b))};H=[];!a.nnew&&!a.system&&a.origin&&a.origin.abuse_url&&(L=n.createIcon(y.get("flag"),"",a.uuid,
"issue",c.getMessage("Report_an_issue_to_the_script_hoster_"),function(){P(a.uuid,"reportAnIssue","hoster")}),H.push(L));a.nnew||a.system||!a.origin&&!a.supportURL||(L=n.createIcon(y.get("bug"),"",a.uuid,"bug",c.getMessage("Report_a_bug"),function(){P(a.uuid,"reportAnIssue","author")}),H.push(L));a.nnew||a.system||(a.remote_url&&(L=n.createIcon(y.get("cloud"),"",a.uuid,"cloud_edit",c.getMessage("Edit"),function(){sendMessage({method:"newTab",url:a.remote_url},function(){})}),H.push(L)),L=n.createIcon(y.get("edit"),
"",a.uuid,"edit",c.getMessage("Edit"),function(){P(a.uuid,"scriptClick")}),H.push(L));a.nnew||a.system||(L=n.createIcon(y.get("delete"),"",a.uuid,"delete",c.getMessage("Delete"),function(){P(a.uuid,"deleteScript")}),H.push(L));B.RUNTIME.MOBILE?l.inserted||q.addEventListener("click",function(){$(b).toggleClass("show_details")}):l.inserted||(l.addEventListener("click",D),l.addEventListener("auxclick",D));l.appendChild(q);L=[a.name];a.description&&L.push(c.getTranslation(a,"description"));if(a.blacklisted||
a.foisted)L=[a.blacklisted||a.foisted];l.title=L.join("\n\n").replace(/\"/g,'"');m.push(a.nnew||a.system?null:{element:Mb(a),style:"script_sel"});m.push(p);m.push(function(){var b=null,b=a.blacklisted||a.foisted?"enabler_warning":a.enabled?a.contexter?"enabler_enabled enabler_later":"enabler_enabled":"enabler_disabled",d=a.blacklisted||a.foisted||(a.enabled?c.getMessage("Enabled"):c.getMessage("Disabled")),b=n.createEnabler(b,a.uuid,"enabled",{append:"enabled",disabled:!!a.blacklisted,title:d},function(){P(a.uuid,
"switchEnabled")});A[a.uuid].switchEnabled=function(b,c,d){void 0===c&&(c=!a.enabled);ga(a.uuid,{enabled:c,whitewash:!!a.foisted},d)};return b}());m.push({element:l,style:"script_name"});if(B.RUNTIME.MOBILE){p=function(b,c,d,e){var g=f("dt","script_info "+(e?e:""),a.name,a.uuid,"dt_mapping"+c);e=f("dd","script_info "+(e?e:""),a.name,a.uuid,"dd_mapping"+c);g.textContent=c;"string"===typeof d?e.textContent=d:e.appendChild(d);b.appendChild([g,e])};L=f("dl","script_details",a.name,a.uuid,"script_details_dl");
l.appendChild(L);p(L,c.getMessage("Version"),t);p(L,c.getMessage("Type"),ib(a),"script_type");p(L,c.getMessage("Sites"),jb(a));var I;(I=kb(a))&&p(L,c.getMessage("Features"),I);h&&p(L,c.getMessage("Homepage"),J);z&&p(L,c.getMessage("Last_updated"),x);m.push(k(a,H,"actions"))}else for(m.push({element:t,style:"script_version"}),m.push(ib(a)),m.push(C),m.push(jb(a)),m.push(kb(a)),m.push(J),m.push(x),m.push(Nb(a)),m.push(k(a,H,"actions")),I=m.length;10>I;I++)m.push(null);O.registerListener(a.uuid,function(){D()});
a.nnew&&K.push(function(){D(null,!0)});return m},ib=function(a){var b=f("span","script_type","",a.uuid,"pos_type",!0);if(a.nnew)return b;a.userscript&&(a=n.createImage(y.origin("uso"),"",a.uuid,"user_script",c.getMessage("This_is_a_userscript")),b.appendChild(a));return b},kb=function(a){var b,e,d,g=null,f=[];if(a.nnew)return null;a.system&&(b=n.createIcon(y.get("lock"),"",a.uuid,"lock",c.getMessage("This_is_a_system_script")),f.push(b));a.warnings&&a.warnings.forEach(function(c,d){b=n.createIcon(y.get("critical"),
"compat",a.uuid,"warning_"+d,c);$(b).addClass("flashing");f.push(b)});a.awareOfChrome&&(b=n.createImage("https://www.google.com/images/icons/product/chrome-16.png","",a.uuid,"chrome_mode",c.getMessage("This_script_runs_in_Chrome_mode")),f.push(b));a.requires.length&&(d=!a.requires.filter(function(a){return a.modified}).length,b=n.createIcon(y.get("script_download")+(d?"":" red"),"",a.uuid,"requires",u.map(u.select(a.requires,function(a){return a&&a.url}),function(a){return a.url}).join("\n"),function(){O.set(a.uuid,
"externals")}),f.push(b));a.resources.length&&(d=!a.resources.filter(function(a){return a.modified}).length,b=n.createIcon(y.get("resources")+(d?"":" red"),"",a.uuid,"resources",u.map(u.select(a.resources,function(a){return a&&a.url}),function(a){return a.url}).join("\n"),function(){O.set(a.uuid,"externals")}),f.push(b));d=!1;var h={includes:!0,matches:!0};for(e in h)if(a[e]){for(h=0;h<a[e].length;h++)if(a[e][h]&&(0==a[e][h].search(/\/\^?http(s|\.\*?|s\?|\[[^\]]*s[^\]]*\]|\([^\)]*s[^\)]*\))+/)||0==
a[e][h].search(/http[s\*]{1,1}|\*/))){b=n.createIcon(y.get("encrypted"),"",a.uuid,"encrypt",c.getMessage("This_script_has_access_to_https_pages"));f.push(b);d=!0;break}if(d)break}var l={};a.grant.forEach(function(a){l[a]=!0});l.GM_xmlhttpRequest&&(b=n.createIcon(y.get("web"),"",a.uuid,"web",c.getMessage("This_script_has_full_web_access")),f.push(b));l.GM_setValue&&(b=n.createIcon(y.get("db"),"",a.uuid,"db",c.getMessage("This_script_stores_data")),f.push(b));l.unsafeWindow&&(b=n.createIcon(y.get("windowlist"),
"",a.uuid,"unsafeWindow",c.getMessage("This_script_has_access_to_webpage_scripts")),f.push(b));for(e in a.options)if(-1!=e.search("compat_")&&a.options[e]){b=n.createIcon(y.get("critical"),"compat",a.uuid,"crit",c.getMessage("One_or_more_compatibility_options_are_set"));f.push(b);break}f.length&&(g=w("span","",a.uuid,"pos_features",!0),g.appendChild(f,!0));return g},lb=!1,bb=function(a){if(!lb){var b=c.getLocale(),e=$("<div>").hide(),d=function(a){a?(e.html(""),e.append($('<div class="contrib_iframe" style="font-size: 2.5em;"></div>').append($('<div style="padding-top: 150px;">').text(a))),
window.setTimeout(d,1E3)):(e.fadeOut(1E3),window.setTimeout(r.hideDialog,1E3))};a=$('<iframe src="https://www.tampermonkey.net/contrib.php?embedded=2'+(b?"&locale="+b:"")+"&src="+(a||"e")+'" class="contrib_iframe"></iframe>');var g=[$('<button class="contrib_button">').html(c.getMessage("Remind_me_later")).click(function(){ma("later");d(c.getMessage("Ok"))}),$('<button class="contrib_button">').html(c.getMessage("I_contributed_already")).click(function(){ma("contributed");d(c.getMessage("Thank_you_very_much_"))}),
$('<button class="contrib_button">').html(c.getMessage("I_dont_want_to_contribute")).click(function(){ma("hide");d(c.getMessage("Ok"))})],f=function(){h&&window.clearTimeout(h);g.forEach(function(a){a.prop("disabled",!1)})};g.forEach(function(a){a.prop("disabled",!0)});e.append(a,g);a.bind("load",f);var h=window.setTimeout(function(){h=null;f()},15E3),l=function(){var a=r.dialog(e[0]);!0===a?(e.fadeIn(1E3),ma("dialog")):void 0===a&&window.setTimeout(l,500);lb=!0};l();window.addEventListener("message",
function(a){var b,g=a.data.clicked||a.data.type;b=a.data.amount;var f=a.data.currency,h=a.data.redirect_url;g&&(h&&Aa(h,!0),a.data.success?(b=$(".contrib_iframe"),f=b.data("oheight"),!f||0>f||1E3<f||(b.animate({height:f},1E3),ma("contributed",g,{id:a.data.id}))):a.data.clicked&&(ma("clicked",g,{amount:b||"?",currency:f||"?"}),$(".contrib_button").remove(),e.append($('<button class="contrib_button">').html(c.getMessage("Ok")).click(function(){d()})),a.data.enlarge&&(b=$(".contrib_iframe"),b.data("oheight",
b.height()),b.animate({height:740},1E3))))},!1)}},Ob=function(){var a=null,b=null,c=null,d=0,g=0,f=0,h=function(b){var d=c.x+b.pageX;a.style.top=c.y+b.pageY+"px";a.style.left=d+"px"},l,k,q,t=function(c){if(a&&!l){var e,D=null,r,x,u,v;h(c);k&&(window.clearTimeout(k),k=null);for(;D!=f;)D=f,r=b.previousSibling,x=b.nextSibling,u=b.parentNode,v=p(b),c.pageY>v.y+d+g&&x?(u.removeChild(x),u.insertBefore(x,b),f++,e=!1):c.pageY<v.y&&1<f&&(u.removeChild(r),x?u.insertBefore(r,x):u.appendChild(r),f--,e=!0);D=
Math.min(.03*document.documentElement.clientHeight,100);if(void 0!==e){x=e?$(r):$(x);if(x.length&&!n.isScrolledIntoView(x,{padding:D})){e=e?x.offset().top-D-x.height():x.offset().top-document.documentElement.clientHeight+D+2*x.height();l=!0;var F=e-document.body.scrollTop;$("html, body").animate({scrollTop:e},0,function(){window.setTimeout(function(){l=!1;k=window.setTimeout(function(){k=null;q===c&&t({pageX:q.pageX,pageY:q.pageY+F})},100)},100)})}c.stopPropagation&&(c.stopPropagation(),c.preventDefault());
q=c;return!1}}},p=function(a){a=a.getBoundingClientRect();return{x:Math.floor(a.left+window.pageXOffset),y:Math.floor(a.top+window.pageYOffset)}},r=function(d){a.style.position="static";var g={};g[a.key]=f;ga(a.uuid,g);a=b=c=null;document.removeEventListener("mousemove",t);document.removeEventListener("scroll",t);document.removeEventListener("mouseup",r);d.stopPropagation();d.preventDefault();return!1};return{start:function(k,l){var q=this.parentNode.parentNode,n=q.parentNode,x=n.parentNode.parentNode;
a=this;b=n;d=b.offsetHeight;g=b.offsetHeight-q.clientHeight;c=p(x);c.x=-c.x-a.offsetWidth/2;c.y=-c.y-b.offsetHeight/2+2*g;a.style.position="absolute";h(k);f=l;document.addEventListener("mousemove",t);document.addEventListener("scroll",t);document.addEventListener("mouseup",r);k.stopPropagation();k.preventDefault();return!1}}}(),Nb=function(a){var b=f("span","sorting","",a.uuid,"pos_images",!0);if(a.nnew)return b;"pos"==fa()&&"up"==ka()||b.setAttribute("style","display: none;");if(1<a.position||a.position<
a.positionof){var e=f("span","clickable movable","position",a.uuid,!0);e.innerHTML="&#9776;";e.title=c.getMessage("Click_here_to_move_this_script");e.uuid=a.uuid;e.key="position";e.addEventListener("mousedown",function(b){Ob.start.apply(this,[b,a.position])});b.appendChild(e)}return b},jb=function(a){var b=w("span","",a.uuid,"site_images"),c=null;b.inserted&&(c=b,c.setAttribute("id",c.id+"foo"),b=w("span","",a.uuid,"site_images"));Ja.topIcons(a,7).forEach(function(a){b.appendChild(a,!0)});c&&c.parentNode.removeChild(c);
return b},qb=function(a){var b=f("div","search_filter",a.name,a.id,"filter");if(b.inserted)return b;var e=$(b);A.filter={onShow:function(a){l(!0);a&&$(r).focus()},onHide:function(){r.value="";l(!0,1)}};var d=null,g,m,h,l=function(a,b){if(!g||a)d&&window.clearTimeout(d),w.show(),d=window.setTimeout(function(){m=q;h=r.value;for(var a=document.getElementsByName("scriptselectors"),b=[],c=0;c<a.length;c++)b.push(a[c]);g=!0;"matching_url"!=m&&"auto"!=m||!h.match(k.matching_url.match)?a=z.Pledge():(t=k.matching_url.update_interval||
t,a=Pb(h));a.then(function(a){var c=new RegExp(u.escapeForRegExp(h),"i"),d=b.map(function(b){return function(){var d,g,f,l;return(g=Y[b.s_id])&&(f=g.script)&&(l=g.dom)&&m==q&&h==r.value?function(){if(e.is(":visible")){if("auto"==m)return z.or(Object.keys(k).map(function(b){return function(){var d=k[b];return d.check?d.check(f,d.ignore_case?c:h,a):z.Breach()}}));var b=k[m];if(b.check)return b.check(f,b.ignore_case?c:h,a)}else return z.Pledge();return z.Breach()}().done(function(){d=!0}).fail(function(){d=
!1}).always(function(){$(l).toggle(!!d);b.is_hidden=!d}):z.Breach()}});return z.onebyone(d)}).always(function(){g=!1;m!=q||h!=r.value?l(!1,1):w.fadeOut()})},b||t)},k={auto:{name:c.getMessage("Auto"),update_interval:500},name:{name:"@name",sync:function(a,b){return-1!=a.name.search(b)},ignore_case:!0},namespace:{name:"@namespace",sync:function(a,b){return a.namespace&&-1!=a.namespace.search(b)},ignore_case:!0},author:{name:"@author",sync:function(a,b){return a.author&&-1!=a.author.search(b)},ignore_case:!0},
grant:{name:"@grant",default:"GM_",sync:function(a,b){return a.grant&&0<a.grant.filter(function(a){return-1!=a.search(b)}).length},ignore_case:!0},includes:{name:"@include/@match",sync:function(a,b){return a.includes&&0<a.includes.filter(function(a){return-1!=a.search(b)}).length||a.matches&&0<a.matches.filter(function(a){return-1!=a.search(b)}).length},ignore_case:!0},code:{name:c.getMessage("Source_Code"),async:function(a,b){var c=z();Qb(a.uuid,{code:b.toString()},function(a){(a?c.resolve:c.reject)()});
return c.promise()},ignore_case:!0},comment:{name:c.getMessage("Comment"),sync:function(a,b){return a.comment&&-1!=a.comment.search(b)},ignore_case:!0},url:{name:c.getMessage("Update_URL_"),default:"https://",sync:function(a,b){return a.file_url&&-1!=a.file_url.search(b)},ignore_case:!0},matching_url:{name:c.getMessage("Matching_URL"),update_interval:1500,default:"http://",match:/^https?:\/\/.*/,sync:function(a,b,c){return c&&-1!=c.indexOf(a.uuid)}}};Object.keys(k).forEach(function(a){var b=k[a];
b.check=b.sync||b.async?function(){if(b.sync)return b.sync.apply(this,arguments)?z.Pledge():z.Breach();if(b.async)return b.async.apply(this,arguments)}:null});var q="auto",t=k.auto.update_interval,p=n.createDropDown(c.getMessage("Filter_by"),{value:0,uuid:"sms-filter",name:"select"},Object.keys(k).map(function(a){return{name:k[a].name,value:a}}),function(){var a;a=this.value;a!=q&&(q=a,t=((a=k[q])?a.update_interval:null)||k.auto.update_interval,a=(a?a.default:null)||"",r.value=r.value||a,l())});p.elem.setAttribute("class",
"label");var r=f("input","filter_text","sms","all",null);r.setAttribute("spellcheck","false");var v="";r.inserted||r.addEventListener("keyup",function(){v!=r.value&&(v=r.value,l())});var w=$(n.createIcon(y.get("download"),"wait_for_filter",a.uuid));w.attr("style","vertical-align: middle;");w.hide();b.appendChild(p.elem);b.appendChild(r);b.appendChild(w[0]);ca.filter&&K.push(function(){A.multiselect.toggleRow(!0,!0);r.value=ca.filter});return b},T=[],Mb=function(a){var b=w("input","",a.uuid,"sel");
b.type="checkbox";b.s_id=a.uuid;b.name="scriptselectors";b.inserted||b.addEventListener("click",function(a){T=[];b&&T.push(b);a.ctrlKey||a.metaKey?A.multiselect.un_selectAll():A.multiselect.single_click()});return b},pb=function(a){var b=f("input","multiselectcb","sms","all",null),e=f("div","filter multiselectcb clickable","sms2","all",null);b.inserted||(b.type="checkbox",b.addEventListener("click",A.multiselect.un_selectAll),e.addEventListener("click",function(){A.multiselect.toggleRow()}));var d=
0,g=[{name:c.getMessage("__Please_choose__"),value:0},{name:c.getMessage("Enable"),value:1},{name:c.getMessage("Disable"),value:2},{name:c.getMessage("Toggle_Enable"),value:7}];(B.RUNTIME.CAN_SAVEAS_ZIP||"undefined"!==typeof Blob)&&g.push({name:c.getMessage("Export"),value:3});var g=g.concat([{name:c.getMessage("Trigger_Update"),value:5},{name:c.getMessage("Factory_Reset"),value:8},{name:c.getMessage("Remove"),value:6}]),g=n.createDropDown(c.getMessage("Apply_this_action_to_the_selected_scripts"),
{value:0,uuid:"sms-select",name:"select"},g,function(){0==this.value?m.setAttribute("disabled","true"):m.removeAttribute("disabled");d=this.value}),m=n.createButton("MultiSelectButton","start_button",c.getMessage("Start"),function(){if(0==d)console.log("option: ?!?!");else{var a=null;6==d?a=c.getMessage("Really_delete_the_selected_items_"):8==d&&(a=c.getMessage("Really_factory_reset_the_selected_items_"));if(!a||confirm(a)){for(var b=document.getElementsByName("scriptselectors"),e=[],a=0;a<b.length;a++)e.push(b[a]);
for(var b={},g,f=!1,m=100,a=0;a<e.length;a++)if(e[a].checked&&!e[a].is_hidden)if(1==d||2==d||7==d){g="switchEnabled";var n,u=Y[e[a].s_id]?Y[e[a].s_id].script:null;7==d?u&&(n=!u.enabled||!!u.foisted):2==d&&u&&u.foisted||(n=1==d);void 0!==n&&(P(e[a].s_id,g,null,n,!1),f=!0)}else 3==d?b[e[a].s_id]=!0:5==d?(g="scriptUpdate",P(e[a].s_id,g)):6==d?(g="deleteScript",P(e[a].s_id,g,null,!0),f=!0,m=1500):8==d&&(g="fullReset",P(e[a].s_id,g),f=!0,m=1500);3==d&&(r.wait(),Ca(b,{storage:C.script_storage,externals:C.include_externals}).then(function(a){r.wait();
return B.RUNTIME.CAN_SAVEAS_ZIP?da.zip.create(a.scripts).progress(r.wait):da.json.create(a.scripts).then(function(a){return new Blob([a],{type:"text/plain"})})}).then(function(a){return sa().done(function(){saveAs(a,"tampermonkey_scripts"+(B.RUNTIME.CAN_SAVEAS_ZIP?".zip":".txt"))})}).always(function(){r.hide()}));f&&(r.wait(c.getMessage("Please_wait___")),window.setTimeout(function(){hb()},m))}}});m.setAttribute("class","action_button");m.setAttribute("disabled","true");g.elem.appendChild(m);a=f("div",
"actions",a.name,a.id,"actions");a.appendChild(g.elem);g=n.createButton("MultiSelectButton","close_button",c.getMessage("Close"),function(){A.multiselect.toggleRow(!1)});$(g).addClass("close_button");return{selAllm:b,selAll:e,actionBox:a,close:g}};(function(){var a=0;A.multiselect={};var b=!1;A.multiselect.toggleRow=function(a,c){var g=$(".multiselect");void 0===a&&(a=!b);a?(b=!0,g.addClass("multiselectvisible"),A.filter.onShow(c)):(b=!1,g.removeClass("multiselectvisible"),A.filter.onHide(),A.multiselect.un_selectAll(!1))};
A.multiselect.single_click=function(){for(var b=0,c=document.getElementsByName("scriptselectors"),g=!0,f=!1,h=0,l=0;l<c.length;l++){var f=!0,g=g&&c[l].checked,k=$(c[l]).closest("tr");c[l].checked?(h++,k.addClass("selected")):k.removeClass("selected")}f&&g&&(b+=2);b!=a&&(a=b,$(".multiselectcb").prop("checked",0!=b?"checked":""));h&&A.multiselect.toggleRow(!0);A.multiselect.checkScroll&&A.multiselect.checkScroll()};A.multiselect.un_selectAll=function(b){3<++a&&(a=0);1==a&&a++;var c=!1,g=0,f=document.getElementsByName("scriptselectors");
T=[];!0===b&&(a=2);for(var h=0;h<f.length;h++){var l=$(f[h]).closest("tr");!1===b?(f[h].checked=!1,l.removeClass("selected")):(0==h&&3==a&&(a=0),c=!0,f[h].checked=3==a||2==a,f[h].checked?(g++,l.addClass("selected"),T.push(f[h])):l.removeClass("selected"));g&&A.multiselect.toggleRow(!0)}void 0===b?1<a&&!c&&(a=0):b||(a=0);$(".multiselectcb").prop("checked",0!=a?"checked":"")}})();var na=null,S=function(){na&&(window.clearTimeout(na),na=null)},W=function(){Pa(c.getMessage("Operation_completed_successfully"),
"button_ok","notice")},gb=function(a,b){void 0===b&&(b="button_ok");Pa(a,b,"information",8E3)},fb=function(a,b){void 0===b&&(b="error");Pa(a,b,"warning",8E3)},Pa=function(a,b,c,d){void 0===d&&(d=3E3);Ka({key:"success",text:a,image:b,class:c,delay:500,timeout:d,done:function(){}})},Ka=function(a){var b,c=a.key||"general";(b=mb[c])&&$(b).remove();mb[c]=n.createGobalHint(a,$("body > div.status")[0])},R=function(a){na||(na=window.setTimeout(function(){na=null;r.wait(c.getMessage("Please_wait___"))},a||
500))},ta=null,oa=null,X=function(a,b){null!=ta?(window.clearTimeout(ta),ta=null,X(a?a:oa.items,a?b:oa.with_scripts)):(oa={items:a,with_scripts:b},ta=window.setTimeout(function(){ta=null;oa.with_scripts&&(Y={});Ba(null,oa.items,null,I);r.hide();Ha();oa=null},50))},Pb=function(a){var b=z();sendMessage({method:"determineScriptsToRun",url:a},function(a){b.resolve(a.scripts||[])});return b.promise()},ma=function(a,b,c){var d=z();sendMessage({method:"begEvent",action:a,type:b,extra:c},function(a){d.resolve(a)});
return d.promise()},Aa=function(a,b){try{var c=function(){b&&B.OPTIONPAGE.CLOSE_ALLOWED&&window.close()};b?sendMessage({method:"newTab",url:a},c):rea.tabs.getSelected(null,function(d){rea.tabs.sendMessage(d.id,{method:"loadUrl",url:a,newtab:b},c)})}catch(d){console.log("lU: "+d.message)}},zb=function(a,b){var c=z();try{R(),sendMessage({method:"installScript",url:a,reload:b.reload},function(a){S();a.items?(W(),X(a.items,!1)):r.hide();a.err?c.reject(a):c.resolve(a)})}catch(d){console.log("sS: "+d.message),
c.reject({err:d.message})}return c.promise()},wb=function(a,b){var c=z();try{R(),sendMessage({method:"exportToJson",ids:a,options:b},function(a){W();S();r.hide();a.json?c.resolve(a.json):c.reject()})}catch(d){console.log("eJ: "+d.message),c.reject({})}return c.promise()},Ma=function(a,b){var c=z();try{R(),sendMessage({method:"importFromJson",json:a,reload:b.reload},function(a){S();a.reload?window.setTimeout(function(){rea.page.reload()},500):a.items?(W(),X(a.items,!0)):r.hide();a.err?c.reject(a):
c.resolve(a)})}catch(d){console.log("sS: "+d.message),c.reject({err:d.message})}return c.promise()},Jb=function(a,b,c){var d=z();try{c.auto_save||R(),sendMessage({method:"saveExternal",uuid:a,code:b,mimetype:c.mimetype,url:c.url,auto_save:c.auto_save},function(a){c.auto_save||(W(),S());a=a||{};a.items?X(a.items,!0):r.hide();d.resolve(a)})}catch(g){console.log("sS: "+g.message),d.reject({err:g.message})}return d.promise()},Oa=function(a,b,c){var d=z();void 0===c.reload&&(c.reload=!0);try{c.auto_save||
R(),sendMessage({method:"saveScript",uuid:a,code:b,clean:c.clean,force:c.force,new_script:c.new_script,auto_save:c.auto_save,lastModTime:c.lastModTime,reload:c.reload},function(a){c.auto_save||(W(),S());a=a||{};a.items?X(a.items,!0):r.hide();!b&&c.reload&&r.hide();d.resolve(a)})}catch(g){console.log("sS: "+g.message),d.reject({err:g.message})}return d.promise()},wa=function(a,b,c){var d=z();try{R(),sendMessage({method:"setOption",name:a,value:b},function(a){S();W();v=a.options||v;!c&&a.items?X(a.items,
!1):r.hide();d.resolve(a)})}catch(g){console.log("sO: "+g.message),d.reject({err:g.message})}return d.promise()},sb=function(a,b,c){var d=z();try{R(),sendMessage({method:"buttonPress",name:a,data:b},function(a){S();!c&&a.items?(W(),X(a.items,!1)):r.hide();d.resolve(a)})}catch(g){console.log("sO: "+g.message),d.reject({err:g.message})}return d.promise()},la=function(a,b){R();sendMessage({method:"loadTree",complete:a.complete,uuid:a.uuid,url:a.url,referrer:a.referrer,layout:a.layout,filter:a.filter},
function(a){S();v=a.options||v;!Fa&&a.xhr&&(Fa=Registry.get("xmlhttprequest"),Fa.setConfig(a.xhr));a.items?a.begging&&K.push(function(){window.setTimeout(function(){bb(a.begging)},100)}):a.error?alert(a.error):confirm(c.getOriginalMessage("An_internal_error_occured_Do_you_want_to_visit_the_forum_"))&&(window.location.href="https://www.tampermonkey.net/bug");b(a)})},Qb=function(a,b,c){la({referrer:"options.scripts.userscripts.matches",uuid:a,filter:b},function(a){r.hide();c(a.items[0])})},hb=function(){la({referrer:"options.scripts"},
function(a){a.items?X(a.items,!0):r.hide()})},ga=function(a,b,e){void 0==e&&(e=!0);try{a={method:"modifyScriptOptions",uuid:a,reload:e};for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);R();sendMessage(a,function(a){S();v=a.options||v;a.i18n&&c.setLocale(a.i18n);W();a.items?X(a.items,!0):r.hide()})}catch(g){console.log("mSo: "+g.message)}},eb=function(a,b,c){try{a={method:"saveStorageKey",uuid:a,key:b,value:c,id:"options"},R(),sendMessage(a,function(){S();W();r.hide()})}catch(d){console.log("sSk: "+
d.message)}},ab=function(a,b,c){try{a={method:"download",details:{url:a,name:b,saveAs:!0},id:"options"},R(),sendMessage(a,function(){S();W();r.hide();c&&c()})}catch(d){console.log("dDU: "+d.message)}},Hb=function(a,b){try{R(),sendMessage({method:"buttonPress",name:"externals_delete",scriptuid:a,safe_url:b},function(a){S();W();a.items?X(a.items,!1):r.hide()})}catch(c){console.log("dEx: "+c.message)}},Kb=function(a,b){try{sendMessage({method:"buttonPress",name:"run_script_updates",scriptuid:a},function(a){W();
b&&b(a.updatable)})}catch(c){console.log("rSu: "+c.message)}},Lb=function(a,b,c){try{sendMessage({method:"reportAnIssue",uuid:a,to:b},function(){c&&c()})}catch(d){console.log("rRi: "+d.message)}},mb={};rea.extension.onMessage.addListener(function(a,b,c){if("updateOptions"==a.method)v=a.options||v,X(a.items,!1),c({});else if("confirm"==a.method)u.confirm(a.msg,function(a){c({confirm:a})});else if("showMsg"==a.method)u.alert(a.msg),c({});else if("status"==a.method)Ka(a.options),c({});else return!1;
return!0});pa.addStyle(function(){Bb(!0);la({referrer:"options"},function(a){if(a.options&&a.options.layout_user_css&&"reset"!==ca.layout){var b=document.createElement("style");b.innerHTML=a.options.layout_user_css;(document.head||document.body||document.documentElement||document).appendChild(b)}a.items?X(a.items,!1):r.hide()})})})});
