'use strict';var trup,init,sycl,cfgo,uris,dast,perm,blak,scbr,exts,down;
Registry.require("promise statistics convert xmlhttprequest downloads tools storage uri compat parser layout helper syncinfo notify asker i18n native".split(" "),function(){var n=Registry.log,p=rea.FEATURES,fa=function(){var d=[],e=!0,f=function(d,f,b){var a={title:d.join("\n\n")};f.path=rea.extension.getURL("images/icon"+(f.frag?"_"+f.frag:"")+".png");n.warn(d.join("\n"));rea.browserAction.setIcon({path:f.path});rea.browserAction.setTitle(a);f=function(a,b,k){a={name:"1",sub_menu_item:!0,pos:"left",
items:[]};a.items.push({name:d[0],image:"info"});1<d.length&&a.items.push({name:d[1]});k({items:[a],options:{enabled:!1}})};b||rea.extension.onMessage.addListener(f)};return{run:function(){try{Registry.verify("5828").length&&(e=!1,f(["Tampermonkey detected that browser is caching some outdated code parts.","In order to avoid unexpected behavior TM will be kept paused until your browser was restarted."],{frag:"paused"}))}catch(d){e=!1,n.error(d.message)}if("chromeStorage"==p.DB.USE&&!p.DB.NO_WARNING){var B=
function(){if(!t)return window.setTimeout(B,2E3);t.isWorking().fail(function(){confirm("Tampermonkey detected that the extension storage is unreliable!\n\nUnfortunately this means that all your settings and userscripts are inaccessible at the moment.\n\nDo you want to visit the FAQ entry that explains how to recover from that?")&&rea.tabs.create({url:"https://tampermonkey.net/faq#Q206"},function(){});f(["Tampermonkey detected that the extension storage is unreliable!"],{frag:"paused"},!0)})};window.setTimeout(B,
1E3)}return e},pause:f,setWarning:function(f,e,b){d.push({text:f,description:e,url:b})},getWarnings:function(){return d}}}();if(fa.run()){var m=Registry.get("promise"),w=Registry.get("helper"),ua=Registry.get("tools"),M=Registry.get("statistics"),t=Registry.get("storage"),R=Registry.get("notify"),W=Registry.get("asker"),P=Registry.get("native"),Ca=Registry.get("permission"),ga=Registry.get("layout"),z=Registry.get("uri"),d=Registry.get("i18n"),G=Registry.get("downloads"),K=ua.cache,J=Registry.get("convert");
uris=z;down=G;perm=Ca;dast=t;var va=w.createUUID(),ca={};n.debug("Starting background fred @"+va);K.create("rundata").setOptions({timeout:5,check_interval:10,retimeout_on_get:!0}).init();K.create("regexp").setOptions({timeout:300,check_interval:120,retimeout_on_get:!0}).init();var Da=function(){var d=m(),q,f,g=rea.extension.manifest.version,l=t.getSchemaVersion(),b=l;t.getVersion("0.0.0.0").then(function(a){f=a;q=E.versionCmp(g,f)==E.versionCmp.eNEWER;return t.isWiped()}).then(function(a){!q&&a&&
(a=["Tampermonkey detected inconsistencies that indicate that your browser wiped the extension database!","You can continue to use Tampermonkey normally, but your settings and scripts might be lost. Click here to get more information.","https://tampermonkey.net/faq.php#Q207"],n.warn(a.join("\n")),fa.setWarning.apply(this,a))}).always(function(){var a=[],c=0,h=function(){if(c<a.length){var k=a[c].schema;a[c].cond(k)?a[c].fn().done(function(){k&&(n.log("Converted database from",b,"to",k),b=k);c++;h()}).fail(function(){d.reject()}):
(c++,h())}},k=function(){n.warn("Incognito mode detected. Database conversion can only be done in non-incognito mode! Stopping now...");fa.pause(["Tampermonkey needs to convert its database but this can't be done in incogonito mode!","Please open a non-incognito mode window and/or restart your browser."],{frag:"paused"})},a=[{cond:function(){return q&&!p.RUNTIME.FIREFOX&&!p.RUNTIME.EDGE&&"chromeStorage"==p.DB.USE&&!t.getValue(p.CONSTANTS.STORAGE.LEGACY_VERSION)&&E.versionCmp("3.5.3603",f)==E.versionCmp.eNEWER},
fn:function(){var a=m();rea.extension.inIncognitoContext?(k(),a.reject()):(n.log("Update database..."),b="3.5.3603",t.migrate("sql","chromeStorage").done(function(){n.log("Copied config for default usage of chrome storage");a.resolve()}));return a.promise()}},{cond:function(){return q&&E.versionCmp("3.6.3650",b)==E.versionCmp.eNEWER&&E.versionCmp("3.5.3650",f)==E.versionCmp.eNEWER},fn:function(){var a=m();if(rea.extension.inIncognitoContext)k(),a.reject();else{b="3.6.3650";var c=[];[{o:"TM_config",
n:p.CONSTANTS.STORAGE.CONFIG},{o:"TM_update_check",n:p.CONSTANTS.STORAGE.UPDATE},{o:"TM_version"},{o:"TM_unload_ts"}].forEach(function(a){if(a.n){var b=t.getValue(a.o);void 0!==b&&c.push(t.setValue(a.n,b))}c.push(t.deleteValue(a.o))});var h=/@re$/,d=[];t.listValues().forEach(function(a){-1!=a.search(h)&&(a=a.replace(h,""),d.push(a))});d.forEach(function(a){var b=t.getValue(a+"@st"),h=t.getValue(a),k=t.getValue(a+"@re"),v=t.getValue(a+"@source"),d=A.getUidByName(a)||w.createUUID();c.push(t.deleteValue(a+
"@st"));c.push(t.deleteValue(a));c.push(t.deleteValue(a+"@re"));c.push(t.deleteValue(a+"@source"));h&&k&&v?(c.push(t.setValue(p.CONSTANTS.PREFIX.SCRIPT_UID+d,a)),c.push(t.setValue(p.CONSTANTS.PREFIX.COND+d,k)),c.push(t.setValue(p.CONSTANTS.PREFIX.STORE+d,b)),c.push(t.setValue(p.CONSTANTS.PREFIX.SCRIPT+d,v)),c.push(t.setValue(p.CONSTANTS.PREFIX.META+d,h))):n.warn("invalid script entry",{source:v,meta:h,cond:k})});h=/@st$/;t.listValues().forEach(function(a){-1!=a.search(h)&&c.push(t.deleteValue(a))});
m.when(c).done(function(){n.log("Converted database from",f,"to",b);a.resolve()})}return a.promise()}},{schema:"3.7.0",cond:function(a){return E.versionCmp(a,b)==E.versionCmp.eNEWER},fn:function(){var a=m();if(rea.extension.inIncognitoContext)k(),a.reject();else{var c=[],b=new RegExp("^"+p.CONSTANTS.PREFIX.META);t.listValues().forEach(function(a){if(-1!=a.search(b)){var h=t.getValue(a);h.options&&h.options.override&&!h.options.override.orig_run_at&&(h.options.override.orig_run_at=h.options.run_at||
"document-idle",h.options.run_at=null,c.push(t.setValue(a,h)))}});m.when(c).done(function(){a.resolve()})}return a.promise()}},{schema:"4526",cond:function(a){return q&&p.RUNTIME.SAFARI&&"chromeStorage"==p.DB.USE&&E.versionCmp(a,b)==E.versionCmp.eNEWER},fn:function(){var a=m();if(rea.extension.inIncognitoContext)k(),a.reject();else{n.log("Update database...");var c=t.migrate("localStorage","chromeStorage").done(function(){n.log("Copied config for default usage of setting storage")});a.consume(c)}return a.promise()}},
{schema:"4871",cond:function(a){return q&&E.versionCmp(a,b)==E.versionCmp.eNEWER},fn:function(){var a=m(),c,b,h=t.getValue(p.CONSTANTS.STORAGE.CONFIG);h&&h.scriptTemplate&&(b=e.getDefaults())&&(c=b.script_templates)&&c[0]&&c[0].value&&(c[0].value=h.scriptTemplate,delete h.scriptTemplate,t.setValue(p.CONSTANTS.STORAGE.CONFIG,h));a.resolve();return a.promise()}},{schema:"5465",cond:function(a){return E.versionCmp(a,b)==E.versionCmp.eNEWER},fn:function(){var a=m();if(rea.extension.inIncognitoContext)k(),
a.reject();else{var c=t.getValue(p.CONSTANTS.STORAGE.CONFIG);c&&1==c.sync_version&&(c.sync_enabled=!1,t.setValue(p.CONSTANTS.STORAGE.CONFIG,c));a.resolve()}return a.promise()}},{cond:function(){return q||E.versionCmp(b,l)==E.versionCmp.eNEWER},fn:function(){var a=m();t.setVersion(g,b).done(function(){a.resolve()});return a.promise()}},{cond:function(){return q},fn:function(){n.log("First run of version "+g+"!");wa.scheduleNotification(f,"0.0.0.0"==f);return m.Pledge()}},{cond:function(){return!0},
fn:function(){var a=m();d.resolve();window.setTimeout(a.resolve,p.MISC.TIMEOUT);return a.promise()}}];h()});return d.promise()},X=function(){return{get:function(d,q){var f=(0==d)+"#"+q,g=K.items.rundata.getj(f);if(g)g=g.oldret;else{var g=[],l=[],b=[],a={};if(q)for(var c=y.determineScriptsToRun(q,!0),h=0;h<c.length;h++){var k=c[h];y.isContexter(k)||0!=d&&(!0===k.options.noframes||null===k.options.noframes&&!0===k.options.override.orig_noframes)||(k.evilness&&k.evilness>=e.values.script_blacklist_severity?
b.push(k):k.enabled?(a[k.uuid]=q,g.push(k)):l.push(k))}g={runners:g,disabled:l,evilness:b,script_map:a};q&&K.items.rundata.setj(f,{frameId:d,oldret:g})}return g},answer:function(d,q){var f=w.select(d,function(a){return a}),g=[{m:"native",t:[G.staticVars.DEFAULT,G.staticVars.NATIVE]},{m:"disabled",t:[G.staticVars.OFF]},{m:"browser",t:[G.staticVars.CHROME]}].filter(function(a){if(-1!=a.t.indexOf(e.values.downloads_mode))return!0}).map(function(a){return a.m})[0]||"disabled",l=rea.extension.inIncognitoContext,
b=!l&&"off"!=e.values.external_connect&&y.validUrl(q,xa.externally_connectable_reg);return{scripts:f,contexters:ha.getContexterCount(),raw:{},external_connect:b,inIncognitoContext:l,downloadMode:g,enforce_strict_mode:"on"==e.values.runtime_strict_mode,statistics:M.isActive("api"),measure_scripts:e.values.debug,logLevel:e.values.logLevel,version:rea.extension.manifest.version}},getContexters:function(d,e){for(var f=[],g=y.determineScriptsToRun(e),l=0;l<g.length;l++){var b=g[l];b.enabled&&(0==d||!0!==
b.options.noframes&&(null!==b.options.noframes||!0!==b.options.override.orig_noframes))&&y.isContexter(b)&&f.push(b)}return f}}}(),C=function(){var d={},q=1,f=q++,g=q++,l=q++,b=q++,a=q++,c=q++,h=q++,k=function(){var a={frames:{0:{state:f}},tabs:{reset_ts:Date.now()},scripts:{},urls:{},maps:{},contexts:{onUnload:{}},stats:{running:0,disabled:0},extra:{}};Object.defineProperties(a.urls,{length:{value:0,enumerable:!1,writable:!0,configurable:!0}});return a},v={updateStats:function(a,c,b,h){d[a].stats.running+=
b;d[a].stats.disabled+=h;d[a].contexts.onUnload[c]=d[a].contexts.onUnload[c]||[];d[a].contexts.onUnload[c].push(function(){d[a].stats.running-=b;d[a].stats.disabled-=h});d[a].tabs.ts=Date.now()},updateMaps:function(a,c,b){var h=1,k=function(c,b){var k=1===h;void 0===d[a].maps[b]&&k&&(d[a].maps[b]={count:0,all_time:0,urls:[]});k&&(d[a].maps[b].urls.push(c),d[a].maps[b].all_time++);d[a].maps[b].count+=h};w.each(b,k);d[a].contexts.onUnload[c]=d[a].contexts.onUnload[c]||[];d[a].contexts.onUnload[c].push(function(){d[a]&&
(h=-1,w.each(b,k))})},updateUrls:function(a,c,b){var h=function(h){1===h&&(void 0===d[a].urls[b]?d[a].urls[b]={frameId:c,count:0}:0===c&&(d[a].urls[b].frameId=c));d[a].urls[b].count+=h;d[a].urls.length=-1};h(1);d[a].contexts.onUnload[c]=d[a].contexts.onUnload[c]||[];d[a].contexts.onUnload[c].push(function(){d[a]&&h(-1)})},determine:function(a,c,b){var h;U.isAllowed(b)?h=X.get(c,b):(n.debug("This URL is filtered by the security settings:",b,"-> Do nothing!"),C.set.forbidden(a,c),h={runners:[],disabled:[],
evilness:[],script_map:{}});d[a].scripts[b]=h;h.runners.forEach(function(b){b.webRequest&&da.scripts.set(a,c,b.uuid,b.webRequest)});return h.runners.length},run:function(a,c,b,h,k){a=[];for(c=0;c<h.length;c++)a.push(Aa.bundle({url:b},h[c]));var d;m.when(a).always(function(a){k?k(a):d=a});return d}},u={},I={},r={},H={},x={listeners:{once:{whenReady:function(a,c){if(!d[a]||d[a].frames[0].state<l)x.listeners.once.onReady(a,c);else c()},onReady:function(a,c){var b=function(a){x.listeners.remove.onCommited(h);
x.listeners.remove.onCompleted(k);a&&c()},h=x.listeners.add.onCommited(function(c){c===a&&b(!0)}),k=x.listeners.add.onCompleted(function(c){c===a&&b(!0)})}},add:{onReset:function(a){var c=w.createUUID();u[c]=a;return c},onCommited:function(a){var c=w.createUUID();I[c]=a;return c},onCompleted:function(a){var c=w.createUUID();r[c]=a;return c},onRemoved:function(a){var c=w.createUUID();H[c]=a;return c}},remove:function(){return{onReset:function(a){delete u[a]},onCommited:function(a){delete I[a]},onCompleted:function(a){delete r[a]},
onRemoved:function(a){delete H[a]}}}()},events:{reset:function(a,c){var b;p.RUNTIME.FAST_EXEC_SUPPORT&&(b=d[a])&&Object.keys(b.frames).forEach(function(c){x.events.clean(a,c)});b=d[a]=k();b.frames[0].state=f;w.each(u,function(b){b&&b(a,c)})},response:function(a,c,b){if(e.values.enabled){var h=d[a]=d[a]||k(),u=h.frames[c]=h.frames[c]||{},x=u.state||f;0===c&&(h.tabs.response_ts=Date.now());b=z.woHash(b);x<g&&(v.determine(a,c,b),u.state=g);return(a=h.scripts[b])?a.runners.length:0}},commited:function(a,
c,b){if(e.values.enabled){var h=z.parse(b);if("http:"===h.protocol||"https:"===h.protocol||"file:"===h.protocol){var h=d[a]=d[a]||k(),h=h.frames[c]=h.frames[c]||{},u=h.state||f;u>=l||(h.state=l,u<g&&(b=z.woHash(b),v.determine(a,c,b)),w.each(I,function(c){c&&c(a)}))}}},loading:function(a,c,h){if(e.values.enabled){var u=z.parse(h);if(("http:"===u.protocol||"https:"===u.protocol||"file:"===u.protocol)&&0===c&&"file:"===u.protocol){u=d[a]=d[a]||k();u.frames[c]=u.frames[c]||{};var x=u.frames[c].state||
f;x>=b||(u.frames[c].state=b,x<g&&(h=z.woHash(h),v.determine(a,c,h)))}}},run:function(c,b,h,u,f){if(e.values.enabled){var r=0===b||p.RUNTIME.FAST_EXEC_SUPPORT?b:h,g=d[c]=d[c]||k();g.frames[r]=g.frames[r]||{};var I=z.woHash(u),H=g.scripts[I];if(!H&&(n.debug("tv: lazy init @ events.run("+c+", "+b+", "+h+", "+u+")"),v.determine(c,b,I),H=g.scripts[I],!H)){n.warn("tv: no script run info for tab "+c+" @ "+I,n.D?g.scripts:"");return}h=g.frames[r].state;g.frames[r].state=a;h!=a&&(v.updateMaps(c,r,H.script_map),
v.updateUrls(c,r,I),v.updateStats(c,r,H.runners.length,H.disabled.length));return v.run(c,b,I,H.runners,f?function(a){x.events.clean(c,r,u);f(a)}:null)}},clean:function(a,c,b){if(e.values.enabled){var h,k;if(h=d[a])b&&(b=z.woHash(b),delete h.scripts[b]),(k=C.get.objurl(a,c))&&URL.revokeObjectURL(k)}},complete:function(b,h,u){u=z.parse(u);if(e.values.enabled&&("http:"===u.protocol||"https:"===u.protocol||"file:"===u.protocol)){if(0===h){var v=d[b]=d[b]||k();v.frames[h]=v.frames[h]||{};var x=v.frames[h].state||
f;v.frames[h].state=c;if(!C.get.empty(b)&&C.get.stats(b).running){if(x<a){n.warn("tv: no script run info!");return}"file:"===u.protocol?window.setTimeout(function(){rea.tabs.sendMessage(b,{method:"onLoad",frameId:h},function(){})},500):rea.tabs.sendMessage(b,{method:"onLoad",frameId:h},function(){})}}w.each(r,function(a){a&&a(b)})}},unload:function(a,c,b){b=0===c||p.RUNTIME.FAST_EXEC_SUPPORT?c:b;p.RUNTIME.FAST_EXEC_SUPPORT&&x.events.clean(a,c);a=d[a]=d[a]||k();a.frames[b]=a.frames[b]||{};a.frames[b].state=
h;if(a.contexts.onUnload[b]){for(c=0;c<a.contexts.onUnload[b].length;c++)a.contexts.onUnload[b][c]();a.contexts.onUnload[b]=[]}},remove:function(a){var c;p.RUNTIME.FAST_EXEC_SUPPORT&&(c=d[a])&&Object.keys(c.frames).forEach(function(c){x.events.clean(a,c)});delete d[a];w.each(H,function(c){c&&c(a)})}},set:{extra:function(a,c,b,h){a=d[a]=d[a]||k();null===c?a.extra[b]=h:(a.extra[b]=a.extra[b]||{},a.extra[b][c]=h)},objurl:function(a,c,b){x.set.extra(a,c,"objurl",b)},blocker:function(a){x.set.extra(a,
null,"blocker",!0)},forbidden:function(a,c){0===c&&x.set.extra(a,null,"forbidden",!0)},requests:function(a,c,b,h){a=d[a]=d[a]||k();c=a.frames[c]=a.frames[c]||{};(c.requests=c.requests||{})[b]=h}},get:{extra:function(a,c,b,h,k){void 0===h&&(h=null);a=(d[a]?d[a].extra:{})[b];null!==c&&a&&k&&delete a[c];return a||h},empty:function(a){var c=!0;if(d[a]&&0!=d[a].urls.length){if(-1==d[a].urls.length)return d[a].urls.length=0,w.each(d[a].urls,function(c,b){"length"!==b&&0<c.count&&d[a].urls.length++}),x.get.empty(a);
c=!1}return c},urls:function(a,c){var b;return c?(b=d[a].maps[c])?b.urls:[]:(b=d[a])?b.urls:{}},history:function(a){return d[a].maps},stats:function(a,c){var b={};d[a]&&(b.running=d[a].stats.running,b.disabled=d[a].stats.disabled,c&&(b.unique=0,Object.keys(d[a].maps).forEach(function(c){0<d[a].maps[c].count&&b.unique++})));return b},tabs:function(){var a={};w.each(d,function(c,b){a[b]={ts:c.response_ts}});return a},objurl:function(a,c){return x.get.extra(a,c,"objurl",null,!0)},blocker:function(a){return x.get.extra(a,
null,"blocker")},forbidden:function(a){return x.get.extra(a,null,"forbidden")},requests:function(a,c){return d[a]&&d[a].frames[c]?d[a].frames[c].requests:null}}};return x}(),ia=function(){var d={};return{get:function(e,f){d[e]||(d[e]={});d[e][f]||(d[e][f]={});return d[e][f]},getAll:function(e){var f={};Object.keys(d).forEach(function(g){f[g]={};f[g]=d[g][e]});return f},set:function(e,f,g){d[e]||(d[e]={});var l={};g&&Object.keys(g).forEach(function(b){l[b]=g[b]});d[e][f]=l},cleanTab:function(e){delete d[e]}}}(),
ja=function(){return{isScriptUrl:function(d,e){if(!d||-1!=d.search(/\#bypass=true/)||-1!=d.search(p.REQUESTS.GET_INTERNAL_PAGE_REGEXP())||"data:"===d.substr(0,5))return!1;var f=e?d:d.split(/[\?#$]/)[0],g=-1!=f.search(/.+\.user\.(js\#|js\?|js$)/)||-1!=f.search(/.+\.tamper\.(js\#|js\?|js$)/);return g?!(-1!=f.search(/^htt[ps]{1,2}:\/\/code\.google\.com/)||-1!=f.search(/^htt[ps]{1,2}:\/\/(github|gitlab)\.com/)&&!y.determineOriginOfUrl(f)||-1!=f.search(/^htt[ps]{1,2}:\/\/bitbucket\.org/)&&!y.determineOriginOfUrl(f)):
g}}}(),U=function(){return{init:function(){var d=function(){K.items.regexp.remove("PageFilter")};e.addChangeListener("forbiddenPages",d);e.addChangeListener("page_whitelist",d);e.addChangeListener("page_filter_mode",d)},isAllowed:function(d){var q=!1,f=!1,g=L.getSyncRemoteDomains().map(function(a){return"*://"+a+"/*"}),g=e.values.forbiddenPages.concat(g),l=0!=g,b=0!=e.values.page_whitelist.length;switch(e.values.page_filter_mode){case "black":f=l;break;case "off":break;case "white":q=b;break;default:q=
b,f=l}(l=K.items.regexp.get("PageFilter"))||(l=y.regexify({inc:q?e.values.page_whitelist:void 0,exc:f?g:void 0}),K.items.regexp.set("PageFilter",l));return!f&&!q||y.validUrl(d,l)}}}(),S=function(){var B=function(d,g){var e=!1;if(g.length)return(e="/"==g.substr(0,1)?y.matchUrl(d,y.convertToRegExp(g)):-1!=d.search(g))&&n.debug('black: entry "'+g+'" matched'),e},q={init:function(){var d=m(),g=function(){"server"===e.values.script_blacklist_type&&window.setTimeout(q.checkUpdate,2E4)};g();e.addChangeListener("script_blacklist_type",
g);d.resolve();return d.promise()},getWarningsFor:function(f){var g=[];f&&w.each(e.values.script_blacklist_server,function(e){if(e){var b;w.each(e.rules,function(a){b|=B(f,a);return 1!=b});if(b)if(e.reasons){var a=Object.keys(e.reasons),c,h;void 0!==(c=d.getBestLocale(a))&&(h=a[c]);g.push(e.reasons[h||"en"])}else e.reason&&g.push(e.reason)}});return g},getEvilnessOf:function(d){if("off"===e.values.script_blacklist_type)return!1;if(!d)return 0;var g=!1,l=0;w.each(e.values.require_blacklist,function(b){g|=
B(d,b);return 1!=g});g?l=11:"server"===e.values.script_blacklist_type&&w.each(e.values.script_blacklist_server,function(b){if(b&&(w.each(b.rules,function(a){g|=B(d,a);return 1!=g}),g))return l=b.severity,!1});return Number(l)},checkUpdate:function(d){var g=m(),l=Y.getConfig(),b;if(d||6048E5<Date.now()-l.black.last){var a=function(a,b){var d=m();pa({method:"GET",url:a,nocache:b,retries:p.XMLHTTPREQUEST.RETRIES,overrideMimeType:"text/plain; charset=x-user-defined"},{ondone:function(a){d.resolve(a)}});
return d.promise()};a("https://blacklist.tampermonkey.net/get.php?version=get").then(function(c){if(4==c.readyState&&200==c.status){try{b=JSON.parse(c.responseText).version}catch(h){n.warn("black: unable to parse version response! "+c.responseText)}n.info("black: local version: "+l.black.version+" remote: "+b);if(b>l.black.version||d)return a("https://blacklist.tampermonkey.net/get.php",!0)}}).then(function(a){if(a&&4==a.readyState&&200==a.status)try{var b=JSON.parse(a.responseText);b&&b.blacklist&&
1==b.version&&(e.values.script_blacklist_server=b.blacklist);n.info("black: updated blacklist to ",b)}catch(d){n.warn("black: blacklist update failed! ",a.responseText)}}).always(function(){l=Y.getConfig();l.black.last=Date.now();l.black.version=b||l.black.version;Y.setConfig(l);g.resolve()})}else g.resolve();return g.promise()}};return q}();blak=S;var Fa=function(){for(var d=[],e=[],f=0;f<d.length;f++){var g=Registry.getRaw("system/"+d[f]+".tamper.js");g&&e.push(g)}return e},L=function(){var B=0,
q=[],f={to:null,force:null,t:0},g={},l=ua.createQueue(1),b={},a=function(a){return l.add(function(){n.debug("sync: import",a.uuid,a.name,a.url);var c={imported:e.values.sync_type},b={},h;for(h in r.SYNCED)!0===r.SYNCED[h]&&(b[h]=a.options[h]);var d={uuid:a.uuid,ask:!1,internal:!0,sync:c,force_meta:{lastModified:a.lastModified,fileURL:a.url},force_options:b},k={silent_fail:!0};return D.caps.syncsSource?D.getSource(a.uuid).then(function(a){return y.installFromSource(a,d,k)}):y.installFromUrl(a.url,
d,k)})},c=function(a,c){return l.add(function(){if(!D.caps.syncsSource){var b;if(!a.url||!(b=z.parse(a.url))||!b.protocol.match(/https?:/))return n.debug("sync: skip export due to missing URL",a.name,a.url),m.Pledge(!1)}n.debug("sync: export",a.name,a.url);return D.setMeta(a,{lastModified:a.lastModified}).then(function(){if(D.setSource&&c)return D.setSource(a.uuid,c)}).then(function(){return!0})})},h=function(a){var c=a.downloadURL?a.downloadURL.split("#")[0]:null,b=a.fileURL?a.fileURL.split("#")[0]:
null,h=w.select([b,c],function(a){if(!a||"file:"!==z.parse(a).protocol)return a})[0],c={uuid:a.uuid,name:a.name,options:{},durl:c,furl:b,url:h,lastModified:a.lastModified||a.lastUpdated},d;for(d in r.SYNCED)!0===r.SYNCED[d]&&null!==a.options[d]&&(c.options[d]=a.options[d]);return c},k=function(){var a=[];A.getUidList().forEach(function(c){c=A.getByUid(c);if(c.script&&c.cond){var b=h(c.script);b.lastModified||Registry.isDevVersion("test")?a.push(b):n.warn("sync: script without updated/modified timestamps found",
c.script)}});return a},v=function(h){if(r.enabled)if(0<B)h&&r.addSyncDoneCallback(function(a){a&&r.sync(50,h)});else{B++;var u=null,v=null,f=0,I=0,l=!0,p=function(a){if(a)for(var c=0;c<v.length;c++)if(v[c].uuid==a)return v[c];return null},t=function(a){if(!a)return null;for(var c=0;c<u.length;c++)if(u[c].uuid==a)return u[c]},w=function(a,c,b){return b?Math.floor(a/b)*b>Math.floor(c/b)*b:a>c},z=function(a,c,b){return b?Math.floor(a/b)*b<Math.floor(c/b)*b:a<c},Ea=function(a,c,b){return b?Math.floor(a/
b)*b!=Math.floor(c/b)*b:a!=c};O.all("status",{key:"sync_status",class:"information",title:d.getMessage("Script_Sync"),text:d.getMessage("Sync_is_running"),timeout:9E5});return m.Pledge().then(function(){u=k();return D.list().done(function(a){v=a}).fail(function(){n.warn("sync: unable to get remotelist!")})}).then(function(){var c=v.map(function(c){var h,k=t(c.uuid),u,v;if(k){if(!c.lastModified&&e.values.sync_type==D.types.eCHROMESYNC)for(var x in r.SYNCED)if(!0===r.SYNCED[x]&&k.options[x]!=c.options[x]){n.debug("sync: importable change detected!",
c.name,"key:",x,c);u=!0;break}c.lastModified&&z(k.lastModified,c.lastModified,c.precision)&&(v=c.lastModified,u=!0,n.debug("sync: importable change detected!",c.name,"local ts:",new Date(k.lastModified),"remote ts:",new Date(c.lastModified),c))}else(h=b[c.uuid])&&c.lastModified&&z(h.lastModified,c.lastModified,c.precision)&&(v=c.lastModified,u=!0,n.debug("sync: changed cache entry detected!",c.name,"local ts:",new Date(h.lastModified),"remote ts:",new Date(c.lastModified),c));if(!k&&!h||u)return function(){return m.Pledge().then(function(){return D.caps.specialMeta?
D.getMeta(c.uuid):m.Pledge(c)}).then(function(c){if(c){var x;if(k)if(c.options.removed)f++,n.debug("sync: remove local script",c.uuid,c.name,c.url),y.doRemove(k.uuid,!1);else{if(u){Ea(v,c.lastModified,c.precision)&&(c.lastModified&&n.warn("sync: list and meta data lastModified differ, this will cause extra traffic!","file ts:",new Date(v),"meta ts:",new Date(c.lastModified),c),c.lastModified=v);f++;n.debug("sync: update local script",c.uuid,c.name,c.url);var e=A.getByUid(k.uuid);if(e.script&&e.cond){for(x in r.SYNCED)!0===
r.SYNCED[x]&&(e.script.options[x]=c.options[x]);e.script.lastModified=c.lastModified;return m.Pledge().then(function(){if(D.caps.syncsSource){var a=m();D.getSource(c.uuid,e.script.textContent).done(function(a){e.script.textContent=a}).fail(function(){n.warn("sync: getting source of",c.uuid,"failed",c)}).always(a.resolve);return a.promise()}}).then(function(){return y.doModify(e.script.uuid,e.script,!1)})}n.warn(d.getMessage("fatal_error")+"("+k.name+")!!!")}}else if(k||c.options.removed)!h&&c.options.removed&&
(b[c.uuid]=c);else if(x=m(),c.url&&g[c.url]||c.uuid&&g[c.uuid])n.warn("sync: skip previously failed import",c);else return a(c).done(function(a){a?f++:(n.warn("sync: unable to import",c),g[c.url]=!0,g[c.uuid]=!0)}).fail(function(){n.warn("sync: unable to load",c);g[c.url]=!0;g[c.uuid]=!0}).always(x.resolve),x.promise()}})}}).filter(function(a){return a});return m.onebyone(c)}).then(function(){f&&(y.reorderScripts(),O.all("status",{key:"sync",class:"information",title:d.getMessage("Script_Sync"),text:d.getMessage("0count0_changes_imported",
f),timeout:1E4}));u=k();return m.Pledge()}).then(function(){for(var a=[],b=0;b<u.length;b++)a.push(function(){var a=u[b],h,d;if(!D.caps.syncsSource&&!a.url)return m.Pledge();var k=p(a.uuid);if(k){if(!k.lastModified||w(a.lastModified,k.lastModified,k.precision))h=!0,n.debug("sync: exportable change detected!",a.name,"remote ts:",new Date(k.lastModified),"local ts:",new Date(a.lastModified),a)}else n.debug("sync: export because remotely missing!",a.name,"local ts:",new Date(a.lastModified),a);return!k||
h||D.caps.syncsSource&&!k.source?(D.caps.syncsSource&&(h=A.getByUid(a.uuid),h.script&&h.cond&&(d=h.script.textContent)),c(a,d).then(function(a){a&&I++})):m.Pledge()}());return m.when(a)}).fail(function(){l=!1}).done(function(){l=!0}).always(function(){n.debug("sync: finished");if(0==--B){O.all("status",{key:"sync_status",class:"information",title:d.getMessage("Script_Sync"),text:d.getMessage("Sync_finished"),timeout:15E3});I&&O.all("status",{key:"sync",class:"information",title:d.getMessage("Script_Sync"),
text:d.getMessage("0count0_changes_exported",I),timeout:5E3});for(var a=l;q.length;)q.shift()(a)}})}},u=function(){r.enabled&&r.sync(500,!0)},I=null,r={enabled:!1,SYNCED:{comment:!0},configChangeListener:function(){I||(I=window.setTimeout(function(){I=null;r.init().done(function(){r.enabled&&r.sync(3E3)})},3E3))},init:function(){var a=m();r.enabled=!1;(function(){return e.values.sync_enabled&&e.values.sync_type?D.init(e.values.sync_type,{url:e.values.cloud_url,basic_auth:J.Base64.encode(e.values.cloud_user+
":"+e.values.cloud_pass)}).done(function(a){r.enabled=a;r.enabled?D.addChangeListener(u):n.warn("sync: init failed!")}).fail(function(){n.warn("sync: init failed!")}):m.Pledge()})().always(function(){a.resolve(r.enabled)});return a.promise()},finalize:function(){},reset:function(){return r.enabled?D.reset():m.Breach()},addSyncDoneCallback:function(a){q.push(a)},sync:function(a,c){var b=Date.now();a=a||500;c=f.force||c;f.to?(window.clearTimeout(f.to),f.ts<b+a&&(a=f.ts-b,1>a&&(a=1))):n.debug("sync: schedule sync for run in "+
a+" ms");f.force=c;f.ts=b+a;f.to=window.setTimeout(function(){v(f.force);f.to=null;f.force=null},a)},scriptAddedCb:function(a,b){if(r.enabled){var d=h(b);c(d,b.textContent)}},scriptChangedCb:function(){r.enabled&&r.sync(6E4)},scriptRemovedCb:function(a,c){if(r.enabled){var b=h(c);n.debug("sync: remove",b.name,b.url);D.remove(b)}},getSyncRemoteUrl:function(a){if(r.enabled)return D.getRemoteUrl(a)},getSyncRemoteDomains:function(){return D.getRemoteDomains()||[]}};return r}();sycl=L;var Ga=function(){e.addChangeListener(["sync_enabled",
"sync_type","cloud_url","cloud_user","cloud_pass"],L.configChangeListener);e.addChangeListener("logLevel",function(){n.set(e.values.logLevel)});e.addChangeListener("i18n",function(){d.setLocale(e.values.i18n)});e.addChangeListener("native_import_path",function(){P.setPath(e.values.native_import_path)});e.addChangeListener("incognito_mode",function(){Ba()});e.addChangeListener("statistics_enabled",function(){M.setEnabled(e.values.statistics_enabled)});e.addChangeListener(["require_blacklist","script_blacklist_server",
"script_blacklist_type"],y.blackCheckAll);e.addChangeListener(["downloads_extension_whitelist","downloads_mode"],G.config_changed_listener);e.addChangeListener("webrequest_modHeaders",function(d,e,f,g){g.done(window.setTimeout(V.reset,1))})},e=function(){var d={},e={enabled:!0,configMode:0,debug:!1,logLevel:0,showFixedSrc:!1,webrequest_modHeaders:"yes",webrequest_fixCSP:"yes",webrequest_fixContentCSP:"no",notification_showUpdate:"changelog",notification_silentScriptUpdate:!0,script_templates:[{name:"ECMAScript 5",
value:"// ==UserScript==\n// @name         New Userscript\n// @namespace    http://tampermonkey.net/\n// @version      0.1\n// @description  try to take over the world!\n// @author       You\n// @match        <$URL$>\n// @grant        none\n// ==/UserScript==\n\n(function() {\n    'use strict';\n\n    // Your code here...\n})();"},{name:"ECMAScript 6",value:'// ==UserScript==\n// @name         New ES6-Userscript\n// @namespace    http://tampermonkey.net/\n// @version      0.1\n// @description  shows how to use babel compiler\n// @author       You\n// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js\n// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js\n// @match        <$URL$>\n// ==/UserScript==\n\nvar inline_src = (<><![CDATA[\n\n    // Your code here...\n\n]]\x3e</>).toString();\nvar c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });\neval(c.code);'},
{name:"CoffeeScript",value:"// ==UserScript==\n// @name         New Coffee-Userscript\n// @namespace    http://tampermonkey.net/\n// @version      0.1\n// @description  shows how to use coffeescript compiler\n// @author       You\n// @require      http://coffeescript.org/browser-compiler/coffeescript.js\n// @match        <$URL$>\n// ==/UserScript==\n\nvar inline_src = (<><![CDATA[\n\n    // Your code here\n\n]]\x3e</>).toString();\nvar compiled = this.CoffeeScript.compile(inline_src);\neval(compiled);"}],
scriptUpdateCheckPeriod:864E5,scriptUpdateHideNotificationAfter:15E3,scriptUpdateCheckDisabled:!1,scriptUrlDetection:"auto",script_file_access:p.RUNTIME.FIREFOX?"off":"externals",runtime_strict_mode:"byscript",runtime_inject_mode:"default",autoReload:!1,appearance_badges:"running",appearance_badge_color:"gcal"===rea.runtime.short_id?"#444":"#ee3131",editor_enabled:!0,editor_fontSize:100,editor_theme:function(){return"default#dark"==k.values.layout?"default-dark":"default"},editor_keyMap:"windows",
editor_indentUnit:4,editor_indentWithTabs:"spaces",editor_tabMode:"indent",editor_electricChars:!0,editor_autoSave:!1,editor_easySave:!0,editor_autoLint:!0,editor_autoLintMaxLen:3E5,editor_lineWrapping:!1,editor_highlightTrailingWhitespace:!0,editor_trimTrailingSpacesFromModifiedLines:!0,editor_linter_config:null,favicon_service:"google",native_import:!0,native_import_path:null,native_import_post_action:"disable",i18n:null,action_menu_columns:1,action_menu_scripts_hide_disabled:!1,action_menu_scripts_sort:"auto",
incognito_mode:"temporary",layout:"default",layout_user_css:"",sync_enabled:!1,sync_type:2,statistics_enabled:p.RUNTIME.FIREFOX&&"firb"!=rea.runtime.short_id?null:!0,downloads_mode:"default",downloads_extension_whitelist:"/^[^\\.]*$/ /\\.mp[34]$/ .wav /\\.(avi|mkv|flv|divx|mpe?g|webm)$/ /\\.(ico|gif|png|jpe?g)/ /\\.(srt|sub|idx)$/ .txt .iso .zip /\\.r(ar|[0-9]{2,2})$/".split(" "),external_update_interval:6048E5,external_connect:"all",require_timeout:2E4,require_blacklist:["/^https?:\\/\\/example.com(:[0-9]{1,5})?\\/.*/"],
require_sri_mode:"supported",script_blacklist_server:[],script_blacklist_type:"server",script_blacklist_severity:4,connect_mode:"ask",page_filter_mode:"black",page_whitelist:["/https?:\\/\\/greasyfork\\.org\\/.*/","http://xkcd.com/970/"],forbiddenPages:"*example.org/* *paypal.tld/* *stripe.com/* https://*deutsche-bank-24.tld/* https://*bankofamerica.tld/* /^.*:\\/\\/apis\\.google\\.com\\/((?!render)([^\\/]+)\\/)+([^\\/]+)?$/ *://www.facebook.com/plugins/* *://platform.twitter.com/widgets/*".split(" ")},
f={cloud_url:null,cloud_user:null,cloud_pass:null},g=function(a){var c;return void 0!==(c=t.getValue(p.CONSTANTS.STORAGE.CONFIG,{})[a])?c:"function"==typeof(c=e[a])?c():c},l=function(a,c){var b=t.getValue(p.CONSTANTS.STORAGE.CONFIG,{}),h=g(a);b[a]=c;var k=t.setValue(p.CONSTANTS.STORAGE.CONFIG,b);d[a]&&JSON.stringify(h)!=JSON.stringify(c)&&d[a].forEach(function(b){try{b(a,h,c,k)}catch(d){n.warn("config: changeListener error",d)}});return k},b,a;if(p.HTML5.LOCALSTORAGE&&(a=p.HTML5.LOCALSTORAGE.getItem(p.CONSTANTS.STORAGE.SESSION)))try{b=
JSON.parse(J.Base64.decode(a))}catch(v){}b=b||{};var c=function(a){var c;return void 0!==(c=b[a])?c:f[a]},h=function(a,h){var k=c(a);void 0===h?delete b[a]:b[a]=h;p.HTML5.LOCALSTORAGE&&p.HTML5.LOCALSTORAGE.setItem(p.CONSTANTS.STORAGE.SESSION,J.Base64.encode(JSON.stringify(b)));d[a]&&JSON.stringify(k)!=JSON.stringify(h)&&d[a].forEach(function(c){try{c(a,k,h)}catch(b){n.warn("config: changeListener error",b)}});return m.Pledge()},k={init:function(){var a=m();k.values={};k.__defineGetter__("snapshot",
function(){return w.assign({},k.values)});Object.keys(e).forEach(function(a){k.values.__defineGetter__(a,function(){return g(a)});k.values.__defineSetter__(a,function(c){l(a,c)})});Object.keys(f).forEach(function(a){k.values.__defineGetter__(a,function(){return c(a)});k.values.__defineSetter__(a,function(c){h(a,c)})});k.initialized=!0;var b=Fa();Object.keys(b).forEach(function(a){var c=b[a];window.setTimeout(function(){y.doSave({url:null,src:c,ask:!1,replace:!0,internal:!0})},1)});a.resolve();return a.promise()},
getValue:function(a){return f.hasOwnProperty(a)?c(a):g(a)},setValue:function(a,c){return f.hasOwnProperty(a)?h(a,c):l(a,c)},getDefaults:function(){return e},addChangeListener:function(a,c){Array.isArray(a)||(a=[a]);a.forEach(function(a){d[a]||(d[a]=[]);d[a].push(c)})}};return k}(),pa=function(d,e){return ka(d,e,{internal:!0})},la=function(){var d=m();rea.tabs.getSelected(null,function(e){d.resolve(e)});return d.promise()},ea=function(){var d={},q=function(a){if(z.isIpOrHostname(a))return null;var c=
a.split(".");if(3>c.length)return a;a=z.isSecondLevelDomain(c.slice(-2).join("."))?-3:-2;return c.slice(a).join(".")},f=function(a){return a&&-1!=a.indexOf("*")},g=function(a){var c=m();U.isAllowed(a)?c.resolve({allowed:!0}):c.resolve({allowed:!1});return c.promise()},l=function(a,c){var b=function(a){return a?a.map(function(a){if(a.match(/^'?self'?$/))a=z.parse(c.url).hostname||null;else if("'none'"==a)a="none";else if(-1===["none","localhost","*"].indexOf(a)&&!z.isIpOrHostname(a)&&(0===a.indexOf(".")||
1===(a.match(/\./g)||[]).length&&z.isSecondLevelDomain(a)))return null;return a}):[]};return{connects:a.options.override.merge_connects&&"paranoid"!=e.values.connect_mode?b(a.connects):[],userconnects:b(a.options.override.use_connects),blockers:b(a.options.override.use_blockers)}},b=function(a,c,b){var h=m(),k=function(){h.resolve({permitted:!0})},v=function(a){h.resolve({permitted:!1,reason:a})},g=function(){h.resolve({unknown:!0})},l,q=function(a,c){var b=null,h=z.isIpOrHostname(a);c.every(function(c){if(c.a)for(var d=
0;d<c.a.length;d++)if(c.a[d]&&(h||z.isIpOrHostname(c.a[d])?c.a[d]===a:-1!=a.search(new RegExp("(^|.+\\.)"+w.escapeForRegExp(c.a[d])+"$"))))return b=c.blocker?v:k,!1;return!0});return b};if("off"==e.values.connect_mode)k();else if((l=z.parse(b))&&l.hostname)if((b=q(l.hostname,[{a:d[a.uuid]}]))||(b=f(d[a.uuid])?k:null))b();else if(0===c.connects.length&&0===c.userconnects.length&&0===c.blockers.length)"casual"==e.values.connect_mode?k():"strict"==e.values.connect_mode?v("No @connects given, but strict mode enabled"):
g();else if(-1!=c.connects.indexOf("none"))v("None value found");else{if("casual"!=e.values.connect_mode||f(c.blockers)||!(b=f(c.connects)?k:null))(b=f(c.userconnects)?k:null)||(b=q(l.hostname,[{a:c.blockers,blocker:!0},{a:c.connects},{a:c.userconnects}])||g);b()}else v("URL can not be parsed");return h.promise()},a=function(){var a=function(a){for(var c=0;c<h.length;c++)if(h[c].tabId===a)return h.splice(c,1)[0];return h.pop()},b;la().then(function(h){for(;!c&&(b=a(h.id));)b.fn()})},c,h=[],k=function(b,
k,v,e,g){var l,oa=m(),p=function(){oa.resolve({approved:!0})},t=function(){oa.resolve({forbidden:!0})};n.debug('cor: "'+b.name+'" is asking for permission to access',e,k);if((l=z.parse(e))&&l.hostname){var za=q(l.hostname),ya=k.tab?k.tab.id:null;c=!0;la().then(function(a){return W.askForConnect({src_url:k.url,hostname:l.hostname,domain:za,all_domains:f(v.connects),tabid:ya,active:ya===a.id,timeout:g,url:e,settings_url:rea.extension.getURL("options.html")+"#nav="+b.uuid+"+settings",connect_url:"https://tampermonkey.net/documentation.php#_connect",
script:{name:b.name,uuid:b.uuid,icon:b.icon64||b.icon||rea.extension.getURL("images/txt.png")}})}).done(function(a){var c,h=a.whole_domain?za:l.hostname;a.allow?a.once?(n.debug('cor: allowing "'+b.name+'" to access',h,"once"),p()):a.temporary?(n.debug('cor: allowing "'+b.name+'" to access',h,"temporarily"),void 0===d[b.uuid]&&(d[b.uuid]=[]),-1==d[b.uuid].indexOf(h)&&d[b.uuid].push(h),p()):(c=p,a.all_domains?(n.debug('cor: allowing "'+b.name+'" to access all domains always'),b.options.override.use_connects.push("*")):
(n.debug('cor: allowing "'+b.name+'" to access',h,"always"),b.options.override.use_connects.push(h),c=p)):a.once||a.aborted?(n.debug('cor: denying "'+b.name+'" to access',h,"once"),t()):(b.options.override.use_blockers||(b.options.override.use_blockers=[]),c=t,a.all_domains?(n.debug('cor: denying "'+b.name+'" to access any domains (additional) domain'),b.options.override.use_blockers.push("*")):(n.debug('cor: denying "'+b.name+'" to access',h,"always"),b.options.override.use_blockers.push(h)));c&&
y.doModify(b.uuid,b,!1).always(c)}).fail(t).always(function(){c=!1;h.length&&window.setTimeout(a,1)})}else t();return oa.promise()},v=function(a,d,r,H){var x=l(a,d),q=arguments;return g(r).then(function(c){if(!0!==c.allowed)return m.Breach("URL is blacklisted");var h,k;return(h=z.parse(r))&&h.origin&&(k=z.parse(d.url))&&k.origin&&h.origin===k.origin?m.Pledge({permitted:!0}):b(a,x,r)}).then(function(b){if(!1===b.permitted)return m.Breach("URL is not permitted"+(b.reason?": "+b.reason:""));if(!0===
b.permitted)return m.Pledge();if(0===x.connects.length||f(x.connects)){if(-1==["ask","paranoid"].indexOf(e.values.connect_mode))return m.Breach();if(f(x.blockers))return m.Breach("URL was permanently blocked by the user");if(c){n.debug('cor: queuing access permission check from "'+a.name+'" to',r,d);var g=m();h.push({tabId:d.tab?d.tab.id:null,fn:function(){g.consume(v.apply(this,q))}});return g.promise()}return k(a,d,x,r,H).then(function(a){return!0===a.approved?m.Pledge():m.Breach("Request was blocked by the user")})}return m.Breach("URL is not a part of the @connect list")})};
return{getSessionConnects:function(a){return d[a]||[]},setSessionConnects:function(a,c){d[a]=c||[]},purgeAppeals:function(a){h=h.filter(function(c){return c.tabId!==a})},exec:function(a,c,b,h){var d,k,f,e,g=a.url,l=[],q=Math.max(Math.min(a.timeout||0,6E4),2E4),m=function(){for(var a;!f&&!e&&(a=l.shift());)a()},B=function(c,b){var d='Refused to connect to "'+(b||a.url)+'": '+(c||"Blocked by @connect CORS check"),k=ma.makeErrorResponse(d);["onerror","ondone"].forEach(function(a){if(h[a])h[a]({response:k,
exception:d})})};if(!(b&&b.url&&b.tab&&a.url&&c&&(k=A.getByUid(c))&&k.script&&k.cond))return B();v(k.script,b,a.url,q).done(function(){var c={};Object.keys(h).forEach(function(a){c[a]=function(u){var I=arguments;f||(e?l.push(function(){c[a].apply(this,I)}):function(){return u&&u.finalUrl&&g!==u.finalUrl?(e=!0,v(k.script,b,u.finalUrl,q).fail(function(){f||(d&&d.abort(),f=!0,B("Request was redirected to a not whitelisted URL",u.finalUrl),n.warn("cor: request to",g,"was redirect to a not whitelisted URL",
u.finalUrl))}).always(function(){g=u.finalUrl;e=!1;l.length&&window.setTimeout(m,1)})):{always:function(a){a()}}}().always(function(){if(!f)h[a]({response:u})}))}});d=ka(a,c)}).fail(function(a){B(a);n.warn("cor: access to",g,"was denied")});return{abort:function(){f=!0;d&&d.abort()}}}}}(),qa=function(){var d=function(a){var c=[];a=new DataView(a);for(var b=0;b<a.byteLength;b+=4){var d=("00000000"+a.getUint32(b).toString(16)).slice(-8);c.push(d)}return c.join("")},e={md5:function(a,c){return m.Pledge(J.MD5(a,
c))}},f={};["SHA-1","SHA-256","SHA-384","SHA-512"].forEach(function(a){var c=a.toLowerCase().replace("-","");f[c]=function(){var c=function(c,b){var h=m();window.crypto.subtle.digest(a,J.str2arrbuf(c,b)).then(function(a){h.resolve(d(a))},function(){h.reject()});return h.promise()};try{return c("").then(function(a){if(a&&a.substr(0,4).toLowerCase().match(/[0-9a-f]{4,4}/))return c})}catch(b){return m.Breach()}}});var g=function(a){return-1!=Object.keys(e).indexOf(a)},l=function(a){return function(){if(!1!==
b){var c=arguments,h=m();b.push(function(){h.consume(a.apply(this,c))});return h.promise()}return a.apply(this,arguments)}},b=[];return{init:function(){n.D&&Object.keys(e).forEach(function(a){n.debug("sri:",a,"is supported")});return m.sidebyside(Object.keys(f).map(function(a){return f[a]().done(function(c){n.debug("sri:",a,"is supported");e[a]=c}).fail(function(){n.debug("sri:",a,"is unsupported")})})).always(function(){b.forEach(function(a){a()});b=!1})},isSupported:l(function(a){return m.Pledge(g(a))}),
getHash:l(function(a,c){var b=m();"string"===typeof a&&(a=z.parse(a));if(a&&a.hash){for(var k,f,e=a.hash.replace(/^#/,"").split(/,|;/g),l=0;l<e.length;l++)if((f=e[l].match(/([^=|:|-]+)[=|:|-](.+)/))&&3==f.length&&g(f[1])){k=f[2];if(!/^[0-9a-fA-F]+$/.exec(k)){var r;var q=decodeURIComponent(k);try{r=d(J.str2arrbuf(J.Base64.decode(q)))}catch(x){r=null}k=r||k}k={type:f[1],value:k}}b.resolve(k||(c?k:{type:"unsupported",value:""}))}else b.resolve();return b.promise()}),check:l(function(a,c,b){return c&&
a&&g(a.type)?e[a.type](c,b).then(function(c,b){return((b=c===a.value)?m.Pledge:m.Breach)(b||{type:a.type,value:c})}):m.Breach()})}}(),N=function(){var d={key:function(a,c){return p.CONSTANTS.PREFIX.EXTERNAL+w.select([a,c?J.MD5(c):null],function(a){return a}).join(":")},list:function(a){var c=new RegExp("^"+a);return w.select(t.listValues(),function(a){return-1!=a.search(c)})},set:function(a,c,b,k){a=d.key(a,c);var f={};w.each(b,function(a,c){"content"==c&&(c="base",a=J.encodeS(a));f[c]=a});t.setValue(a,
{ts:Date.now(),url:c,resource:f,modified:k})},get:function(a,c){var b=d.key(a,c),b=t.getValue(b),k;if(b&&b.resource){var f={};w.each(b.resource,function(a,c){"base"==c&&(c="content",a=J.decodeS(a));f[c]=a});k={ts:b.ts,url:b.url,data:f,modified:b.modified}}return k},clean:function(a,c){var b=d.key(a,c);t.deleteValue(b)},cleanAll:function(a,c){var b,k=d.list(d.key(a));if(c){var f={};w.each(c,function(c){c=d.key(a,c);f[c]=!0});b=[];w.each(k,function(a){f[a]||b.push(a)})}else b=k;b.forEach(function(a){t.deleteValue(a)})}},
q=function(a,c){var b=m(),d=function(d){var k={content:""};if(4!=d.readyState||200!=d.status&&0!=d.status||d.error)b.reject(k);else{for(var f,e=d.responseHeaders?d.responseHeaders.split("\n"):[],g,u=0;u<e.length;u++){var v=e[u].split(":"),l=v.shift()||"",v=v.join(":")||"";if("content-type"==l.trim().toLowerCase()&&(g=v.match("(image/|text/)([.-a-zA-Z0-9]+)"))){f=g[0];break}}f||(a.match(".*.(ico|jpg|jpeg)+($|\\?|#).*")?f="image/x-icon":(g=a.match(".*.(gif|png)+($|\\?|#).*"))?f="image/"+g[1]:-1!=a.search(".*.(js)+($|\\?|#).*")?
f="text/javascript":(g=a.match(".*.(css|html|xml)+($|\\?|#).*"))?f="text/"+g[1]:w.isLocalImage(a)&&(f="image/x-icon"));k.meta=f;k.content=J.arrbuf2str(d.response,c.encoding)||"";b.resolve(k)}},f=function(){b.reject({})},g=z.parse(a);-1!=["file:",p.REQUESTS.INTERNAL_PAGE_PROTOCOL].indexOf(g.protocol)?"file:"!=g.protocol||p.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS&&-1!=["externals","all"].indexOf(e.values.script_file_access)?rea.file.get(a,function(a){d({readyState:4,status:0,response:a})},function(a){f({error:!0,
responseText:a})}):(n.warn("externals:","Access to this local file is forbidden!","Loading the following @resource failed:",a,"-> more info:","https://tampermonkey.net/faq.php#Q204"),f({error:!0,responseText:"Access to this local file is forbidden!"})):(g={method:"GET",url:a,retries:p.XMLHTTPREQUEST.RETRIES,nocache:!1,responseType:"arraybuffer"},g.timeout=e.values.require_timeout,pa(g,{onload:d,onerror:f,ontimeout:f}));return b.promise()},f=w.getDebouncer(9E3),g=function(a,c,b,k){var f=m(),g={sync:!1};
q(c,{encoding:k.encoding}).done(function(l){b&&(l.sri=b);var r=function(b){var h=z.parse(c);h.protocol&&-1==["file:",p.REQUESTS.INTERNAL_PAGE_PROTOCOL].indexOf(h.protocol)&&d.set(a,c,b)};b&&-1!=["supported","given"].indexOf(e.values.require_sri_mode)?qa.check(b,l.content,k.encoding).done(function(){g.resource=l;r(g.resource);f.resolve(g)}).fail(function(a){g.resource={forbidden:!0,sri:{mode:e.values.require_sri_mode,type:b.type,value:"invalid"},determined:a,content:""};r(g.resource);f.reject(g)}):
(g.resource=l,r(g.resource),f.resolve(g))}).fail(function(b){n.debug("externals: get.failed",a,c,b);g.resource={failed:!0,content:""};f.reject(g)});return f.promise()},l=function(a,c,b){var k=m(),v=z.parse(c),u={sync:b.sync},l;c?S.getEvilnessOf(c)>=e.values.script_blacklist_severity?(u.resource={blacklisted:!0,content:""},k.reject(u)):qa.getHash(v,"supported"==e.values.require_sri_mode).done(function(r){if("enforce"!=e.values.require_sri_mode||r)if("file:"!==v.protocol&&(l=d.get(a,c))){var q=d.key(a,
c),x=Date.now();0<e.values.external_update_interval&&x-l.ts>e.values.external_update_interval&&!f.is(q)&&(1<e.values.external_update_interval&&f.add(q),l.modified?n.debug("externals: resource is not updated due to user modifications",c,(new Date(l.ts)).toISOString(),(new Date(x)).toISOString()):(n.debug("externals: resource needs update",c,(new Date(l.ts)).toISOString(),(new Date(x)).toISOString()),window.setTimeout(function(){g(a,c,r,b)},3E3)));u.resource=l.data;u.resource.forbidden||u.resource.blacklisted?
k.reject(u):k.resolve(u)}else k.consume(g(a,c,r,b));else u.resource={forbidden:!0,sri:{mode:e.values.require_sri_mode},content:""},k.reject(u)}):(u.resource={forbidden:!0,content:""},k.reject(u));return k.promise()},b={setElement:function(a,c,b,k){return d.set(a,c,b,k)},getElement:function(a,c){return d.get(a,c)},cleanElement:function(a,c){return d.clean(a,c)},dropAll:function(a){d.cleanAll(a);return m.Pledge()},dropAllBut:function(a,c){d.cleanAll(a,c);return m.Pledge()},loadResources:function(a,
c){var h=m();b.getResources(a,c).always(function(){h.resolve()});return h.promise()},loadRequires:function(a,c){var h=m();b.getRequires(a,c).always(function(){h.resolve()});return h.promise()},getResources:function(a,c){var b={elements:[]},d=m(),f=[],g={sync:!0};c.forEach(function(c){var d=c.url||z.sanitize(c.unsafe_url,c.abs_url),k={name:c.name,url:d},d=l(a,d,g),e=m();d.done(function(a){a=a.resource;k.content=a.content;k.meta=a.meta||"application"}).fail(function(a){a.resource&&a.resource.forbidden?
a.resource.sri?n.warn("externals: can't load @resource",c.name,"from URL",c.unsafe_url,"due to a SRI error"):n.warn("externals: can't load @resource",c.name,"from forbidden URL",c.unsafe_url):a.resource&&a.resource.blacklisted?n.warn("externals: can't load @resource",c.name,"from blacklisted URL",c.unsafe_url):(n.warn("externals: can't load @resource",c.name,"from URL",c.unsafe_url),k.failed=!0);k.content=null}).always(function(a){g.sync&=a.sync;b.elements.push(k);e.resolve()});f.push(e)});m.when(f).always(function(){b.sync=
g.sync;d.resolve(b)});return d.promise()},getRequires:function(a,c){var b={elements:[]},d=m(),f=[],g={encoding:"UTF-8",sync:!0};w.each(c,function(c,d){var k=c.url||z.sanitize(c.unsafe_url,c.abs_url),e={},k=l(a,k,g),q=m();k.done(function(a){e.textContent=a.resource.content||""}).fail(function(a){a=a.resource&&a.resource.forbidden?a.resource.sri?"couldn't load @require from URL "+c.unsafe_url+" due to a SRI error":"couldn't load @require from forbidden URL "+c.unsafe_url:a.resource&&a.resource.blacklisted?
"couldn't load @require from blacklisted URL "+c.unsafe_url:"couldn't load @require from URL "+c.unsafe_url;e.textContent='console.warn("Tampermonkey: " + decodeURIComponent("'+encodeURIComponent(a)+'"));\n';n.warn("externals: "+a)}).always(function(a){g.sync&=a.sync;b.elements[d]=e;q.resolve()});f.push(q)});m.when(f).always(function(){b.sync=g.sync;b.elements=b.elements.filter(function(a){return a});d.resolve(b)});return d.promise()}};return b}();exts=N;var Aa=function(){var d=function(d,g,l){var b=
m(),a=[];l.forEach(function(c){c=c.textContent||"";c=na.mkCompat(c,d.options.compatopts_for_requires?d:null,"off"!=e.values.runtime_strict_mode);a.push(c)});l="\n"+a.join("\n")+"\n";var c=A.getStorageByUid(d.uuid);g=na.mkCompat(g,d,"off"!=e.values.runtime_strict_mode);if(e.values.debug){g=g.split("\n");for(var h=!1,k,v=0;v<g.length;v++)if(k=g[v],!k.match(/^\s*$|^\s*\/\/\s*|^\s*\/\*.*\*\/\s*$|^\s*["']+use strict["']+;*\s*$/))if(k.match(/^\s*\/\*/)&&(h=!0),h)if(k.match(/\*\/\s*$/))h=!1;else{if(-1!=
(k=k.search(/\*\//))){g[v]=w.insert(g[v],k+2,0,"debugger;");break}}else{g[v]="debugger;"+g[v];break}g=g.join("\n")}l={header:d.header,code:g,requires:l,storage:c,script:d,source_url:rea.extension.getURL("userscript.html")+"?id="+d.uuid};b.resolve(l);return b.promise()},q={};return{bundle:function(f,g){var e,b,a=!0;if(e=q[g.uuid])return e;var c={},h="includes matches requires resources excludes connects textContent".split(" ");Object.keys(g).forEach(function(a){-1==h.indexOf(a)&&("options"==a?(c[a]=
JSON.parse(JSON.stringify(g[a])),c[a].run_at=c[a].run_at||g.options.override.orig_run_at||"document-idle"):c[a]=g[a])});e=N.getResources(c.uuid,g.resources).then(function(b){a&&!b.sync&&(n.debug("ri: uncached @external detected -> fast script start disabled"),a=b.sync);c.resources=b.elements;return N.getRequires(c.uuid,g.requires)}).then(function(b){a&&!b.sync&&(n.debug("ri: uncached @external detected -> fast script start disabled"),a=b.sync);b=b.elements;n.debug("run script "+c.name+" @ "+f.url);
return d(c,g.textContent,b)}).always(function(){b=!0;delete q[c.uuid]});b||(q[c.uuid]=e);return e}}}(),O=function(){var d={},e={},f=function(b,a){var c,h=a.key||"general",d=a.timeout||3E5,f=window.setTimeout(function(){delete b[h]},d);(c=b[h])&&window.clearTimeout(c.to);b[h]={ts:Date.now()+d,options:a,to:f}},g=function(b){var a=Date.now();return Object.keys(b).map(function(c){var h=b[c];c=w.copy(h.options,{});if(h=Math.max(0,h.ts-a))return c.timeout=h,c}).filter(function(a){return a})},l={all:function(b,
a){l.actionPage(b,a);l.optionsPage(b,a)},actionPage:function(b,a){var c=rea.extension.getViews({type:"popup"});c&&c.length&&rea.extension.sendMessage({method:b,options:a},function(){});a&&f(d,a)},optionsPage:function(b,a){var c=rea.extension.getViews({type:"tab"});c&&c.length&&rea.extension.sendMessage({method:b,options:a},function(){});a&&f(e,a)},actionStatus:function(){return g(e)},optionsStatus:function(){return g(d)}};return l}(),Y=function(){return{getConfig:function(){var d={version:0,last:0},
e={scripts:0},f=t.getValue(p.CONSTANTS.STORAGE.UPDATE,e);"object"!==typeof f&&(f=e);f||(f=e);void 0==f.black&&(f.black=d);void 0==f.scripts&&(f.scripts=0);return f},setConfig:function(d){d&&t.setValue(p.CONSTANTS.STORAGE.UPDATE,d)}}}(),Z=function(){var B=function(g,l){var b=0,a=0,c=d.getMessage("Script_Update"),h=d.getMessage("Check_for_userscripts_updates")+"...";g&&R.show(c,h,rea.extension.getURL("images/icon128.png"),1E4);O.all("status",{key:"script_update",class:"information",title:c,text:h,timeout:1E4});
c=A.getUidList().map(function(c){var h,g,q,r,H,x;return function(){r=A.getByUid(c);if(!r.script||!r.cond)return n.warn("update: inconsistent script entry",c,r),m.Breach();var a=!e.values.scriptUpdateCheckDisabled&&!r.script.enabled&&!l||!r.script.options.check_for_updates;if(l&&r.script.uuid!==l||a||!(x=y.determineSourceURL(r.script)))return m.Breach();var b;if((b=y.determineOrigin(r.script))&&b.updates_allowed&&!b.updates_allowed(x))return m.Breach();n.info("update: check for script updates @",c);
return m.Pledge()}().then(function(){var a=y.determineMetaURL(r.script);if(!a)return m.Pledge();if("none"==a)return n.log("update: ignore non-updatable script",r.script.name),m.Breach();var c=m();ka({method:"GET",retries:p.XMLHTTPREQUEST.RETRIES,timeout:1E3*p.SCRIPT_DOWNLOAD.TIMEOUT,revalidate:!0,headers:{Accept:"text/x-userscript-meta, */*"},url:a},{ondone:function(b){4==b.readyState&&200==b.status?H=E.processMetaHeader(b.responseText):n.warn("update: unable to find meta data @ "+a+" req.status = "+
b.status);c.resolve()}});return c.promise()}).then(function(){var a=!!H,c=a&&!!H.version,b=c&&(!r.script.version||E.versionCmp(H.version,r.script.version)==E.versionCmp.eNEWER);return a&&c&&!b?m.Breach():m.Pledge()}).then(function(){var a;if(a=z.parse(x)){if(a.protocol.match(/(https?|file):/))return f.getScriptFromURL(x).fail(function(){n.warn("update: failed",r.script.name,x)});n.warn("update: can't download URL",r.script.name,x)}else n.warn("update: can't parse URL",r.script.name,x)}).then(function(a){var c;
c=r.script.uuid;var d=E.createScriptFromSrc(a);if(!d.name||""==d.name||void 0===d.version||d.options.compat_uW_gmonkey)c=E.versionCmp.eERROR;else{var k;c=(k=A.getMetaByUid(c))?k.system?null:d.version==k.version?E.versionCmp.eEQUAL:E.versionCmp(d.version,k.version):E.versionCmp.eNEWER}return c==E.versionCmp.eNEWER?(b++,h=r.script.name,g=x,q=a,m.Pledge()):m.Breach()}).then(function(){if(e.values.notification_silentScriptUpdate)return m.Pledge();var a=d.getMessage("There_is_an_update_for_0name0_avaiable_",
h)+"\n"+d.getMessage("Click_here_to_install_it_"),c=d.getMessage("Just_another_service_provided_by_your_friendly_script_updater_")+":",b=m();R.show(c,a,rea.extension.getURL("images/icon128.png"),e.values.scriptUpdateHideNotificationAfter,b.resolve);return b.promise()}).then(function(b){var h=c||r.script.uuid;return void 0===b||b.clicked?y.doSave({url:g,uuid:h,replace:!h,src:q,ask:!e.values.notification_silentScriptUpdate}).done(function(c){c&&c.installed&&a++}):m.Breach()})});return m.sidebyside(c).then(function(){0==
b&&(n.debug("No update found"),g&&R.show("Narf!",d.getMessage("No_update_found__sry_"),rea.extension.getURL("images/icon128.png"),1E4),O.all("status",{key:"script_update",class:"information",text:d.getMessage("No_update_found__sry_"),timeout:1E4}));return{found:b,installed:a}})},q=null,f={check:function(f,l,b){if(!f&&0>=e.values.scriptUpdateCheckPeriod)return m.Breach();var a=Y.getConfig();if(!f&&Date.now()-a.scripts<Math.max(e.values.scriptUpdateCheckPeriod,36E5))return m.Breach();var c=m();f=function(){h&&
(window.clearTimeout(h),h=null);k&&k.cancel();B(l,b).done(function(a){c.resolve(a.installed)}).fail(function(){c.resolve(null)});a=Y.getConfig();a.scripts=Date.now();Y.setConfig(a)};var h,k,v=function(){k=null;var a=d.getMessage("Script_Update"),c=d.getMessage("Waiting_for_sync_to_finish")+"...";k=R.show(a,c,rea.extension.getURL("images/icon128.png"),6E4)};L.enabled?(L.addSyncDoneCallback(f),L.sync(50,!1),l&&(h=window.setTimeout(v,500))):f();return c.promise()},getScriptFromURL:function(d){var f=
m();-1!=["file:",p.REQUESTS.INTERNAL_PAGE_PROTOCOL].indexOf(z.parse(d).protocol)?rea.file.get(d,function(b){f.resolve(J.arrbuf2str(b))},function(b){f.reject({error:!0,responseText:b})}):pa({method:"GET",retries:p.XMLHTTPREQUEST.RETRIES,timeout:1E3*p.SCRIPT_DOWNLOAD.TIMEOUT,revalidate:!0,headers:{Accept:"text/x-userscript, */*"},url:d},{onload:function(b){4!=b.readyState||200!=b.status&&0!=b.status||b.error?f.reject({error:!0,responseText:b.responseText}):f.resolve(b.responseText)},onerror:function(b){f.reject({error:!0,
responseText:b.responseText})},ontimeout:function(){f.reject({timeout:!0,responseText:""})}});return f.promise()},init:function(){var d=function(){q&&(window.clearTimeout(q),q=null);0<e.values.scriptUpdateCheckPeriod&&(q=window.setTimeout(function(){q=null;f.check();d()},36E5))};d();e.addChangeListener("scriptUpdateCheckPeriod",d)}};return f}();trup=Z;var y=function(){var B=function(b){b.sort(function(a,c){return a.position-c.position});return b},q=function(b){void 0===b.ask&&(b.ask=!0);if(void 0===
b.url||null==b.url)b.url="";""===b.force_url&&(b.force_url=null);var a=E.createScriptFromSrc(b.src),c=null,h={heading:null,errors:[],info:[],warnings:[],flags:{}},k=m(),f=Date.now(),g=b.save&&!b.ask&&e.values.editor_easySave,q=b.uuid,r,p;a.name&&void 0!=a.version?p=m.Pledge():(h.errors.push(d.getMessage("Invalid_UserScript__Sry_")+"\n\n"),b.name&&h.errors.push(d.getMessage("Script_name_0name0",b.name)+"\n\n"),b.url&&h.errors.push(d.getMessage("Downloaded_from_0url0",b.url)),n.warn("scriptman: invalid userscript",
h,a),p=m.Breach());p.then(function(){b.replace&&!q&&(q=A.getUidsByName(a.name,a.namespace)[0]);if(q)c=A.getMetaByUid(q);else if(a.uuid)q=a.uuid;else if(b.replace)q=w.createUUID();else return n.warn("scriptman: neither UUID, @uuid nor replace option set"),m.Breach();if(""!==q.replace(/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/,""))return n.warn("scriptman: invalid UUID",q),m.Breach();if(!b.clean&&!b.defaultscript&&c&&c.system)return m.Breach()}).then(function(){if(b.clean&&
b.name&&b.name!=a.name||-1!=a.name.search("\n"))return h.errors.push(d.getMessage("Invalid_UserScript_name__Sry_")),m.Breach()}).then(function(){if(a.options.compat_uW_gmonkey)return h.errors.push(d.getMessage("This_script_uses_uW_gm_api_")),m.Breach()}).then(function(){if(c){c.name!=a.name&&(h.flags.renamed=!0);if(c.lastModified&&void 0!==b.lastModTime&&c.lastModified!==b.lastModTime){var k=d.getMessage("some_secs");try{var e=Math.max(1,Math.floor((f-c.lastModified)/1E3));isNaN(e)||(k=e)}catch(l){}h.warnings.push(d.getMessage("CONFLICT__This_script_was_modified_0t0_seconds_ago_",
k));h.flags.forceAsk=!0}a.version==c.version&&(b.save?h.flags.modification=!0:h.flags.reset=!0);b.clean&&(h.flags.factory=!0);r=!b.internal}else h.flags.first_install=!0,r=!b.internal||b.save;a.includes.length||a.matches.length||g||b.internal||h.warnings.push(d.getMessage("This_script_does_not_provide_any__include_information_"));h.flags.sync=!!b.sync;h.flags.internal=b.internal;h.flags.ask=b.ask;h.flags.save=b.save}).then(function(){a.uuid=q;a.system=b.defaultscript;a.evilness=y.getEvilness(a);a.position=
y.determineLastPosition()+1;a.lastModified=f;if(b.force_meta){var d;if(d=b.force_meta.fileURL)a.fileURL=d;if(d=b.force_meta.lastModified)a.lastModified=d}h.flags.factory||h.flags.reset?c&&(a.lastModified=c.lastModified):(b.force_url&&(a.updateURL=null,a.downloadURL=b.force_url),c&&(a.options.override=c.options.override,a.options.comment=c.options.comment,a.options.check_for_updates=c.options.check_for_updates));["includes","excludes","matches","connects"].forEach(function(c){a.options.override["orig_"+
c]=a[c]});a.options.override.orig_noframes=a.options.noframes;a.options.override.orig_run_at=a.options.run_at||"document-idle";a.options.noframes=null;a.options.run_at=null}).then(function(){if(c&&(a.fileURL=c.fileURL,a.position=c.position,c.sync&&(a.sync=c.sync),!h.flags.factory&&!h.flags.reset)){a.enabled=c.enabled;a.options.noframes=c.options.noframes;a.options.run_at=c.options.run_at;a.options.awareOfChrome||(a.options.compat_forvarin=c.options.compat_forvarin);b.save&&!b.force_url&&(a.downloadURL=
c.downloadURL||a.downloadURL);var k=l.determineMetaURL(c),f=l.determineMetaURL(a),k=k?z.woHash(k):k,f=f?z.woHash(f):f;k==f||g||b.internal||h.warnings.push(d.getMessage("The_update_url_has_changed_from_0oldurl0_to__0newurl0",[k,f]));b.save||(w.adiff(c.includes,a.includes,"notinfirst").length+w.adiff(c.matches,a.matches,"notinfirst").length+w.adiff(a.excludes,c.excludes,"notinfirst").length&&h.warnings.push(d.getMessage("At_least_one_of_the_include_match_or_exclude_statements_was_changed_")),w.adiff(c.connects||
[],a.connects||[],"notinfirst").length&&h.warnings.push(d.getMessage("At_least_one_new_connect_statement_was_added_")))}}).then(function(){if(c&&!h.flags.factory&&a.version==c.version&&(b.defaultscript||b.noreinstall))return m.Breach()}).then(function(){c?(h.flags.factory||h.flags.reset?(h.flags.reset?(h.heading=d.getMessage("You_are_about_to_reinstall_a_UserScript_"),h.flags.reinstall=!0):(h.heading=d.getMessage("You_are_about_to_install_a_UserScript_"),h.flags.install=!0),b.internal||h.warnings.splice(0,
0,d.getMessage("All_script_settings_will_be_reset_"))):h.flags.modification?h.heading=d.getMessage("You_are_about_to_modify_a_UserScript_"):E.versionCmp(a.version,c.version)==E.versionCmp.eOLDER?(h.heading=d.getMessage("You_are_about_to_downgrade_a_UserScript"),h.flags.downgrade=!0,g||b.internal||h.warnings.splice(0,0,d.getMessage("The_downgraded_script_might_have_problems_to_read_its_stored_data_"))):(h.heading=d.getMessage("You_are_about_to_update_a_UserScript_"),h.flags.update=!0),h.info.push({label:d.getMessage("Installed_Version_"),
value:"v"+c.version})):(h.heading=d.getMessage("You_are_about_to_install_a_UserScript_"),g||b.internal||(h.info.splice(0,0,d.getMessage("Malicious_scripts_can_violate_your_privacy_")),S.getWarningsFor(l.determineSourceURL(a)).forEach(function(a){h.warnings.splice(0,0,a)})),h.flags.install=!0);h.flags.install?h.action=d.getMessage("Install"):h.flags.reinstall?h.action=d.getMessage("Reinstall"):h.flags.modification?h.action=d.getMessage("Modify"):h.flags.downgrade?h.action=d.getMessage("Downgrade"):
h.flags.update&&(h.action=d.getMessage("Update"))}).then(function(){b.url&&(a.fileURL=b.url);b.sync&&(a.sync=b.sync);b.force_options&&w.copy(b.force_options,a.options,(new E.Script).options,!0);b.force_settings&&w.copy(b.force_settings,a,["enabled","position"]);a=y.mergeCludes(a)}).then(function(){var c=!1,k;for(k in a.options)if(-1!=k.search("compat_")&&!0===a.options[k]){c=!0;break}c&&h.info.push({label:d.getMessage("Note"),value:d.getMessage("A_recheck_of_the_GreaseMonkey_FF_compatibility_options_may_be_required_in_order_to_run_this_script_")});
var f,e;(f=l.determineOrigin(a))&&(e=f.convert)&&(c=e(a),c.warning&&(b.internal?h.info.push(c.warning):h.warnings.push(c.warning)),a=c.script)}).then(function(){["requires","resources"].forEach(function(c){a[c]=w.map(a[c],function(c){c.unsafe_url=c.url;c.abs_url=a.fileURL?a.fileURL.split("/").slice(0,-1).join("/"):null;c.url=null;return c})})}).done(function(){k.resolve({script:a,oldscript:c,messages:h,trigger_sync:!!r,short_info:[{label:d.getMessage("Author"),prop:"author"},{label:d.getMessage("Description"),
prop:"description"},{label:d.getMessage("Source"),prop:"fileURL"}]})}).fail(function(){k.reject({messages:h})});return k.promise()},f=function(b){var a=m(),c=b.messages,h=b.script,d=b.trigger_sync,f=function(){c.flags.modification||N.dropAll(h.uuid);a.notify();var b=l.doModify(h.uuid,h,d)||{};!c.flags.install&&!c.flags.update||c.flags.factory||c.flags.reset||M.tS(h.name,h.fileURL,c.flags.install?"i":"u");(c.flags.first_install||c.flags.factory)&&A.setStorageByUid(h.uuid,{ts:Date.now()});return b},
e={lastModified:void 0,installed:!0,renamed:c.flags.renamed};c.warnings.length||c.flags.ask?W.install(b).done(function(c){c.ok&&f();e.installed=c.ok;e.aborted=c.aborted;a.resolve(e)}).fail(function(c){a.reject(c)}):window.setTimeout(function(){f();a.resolve(e)},1);return a.promise()},g=w.getDebouncer(1E3),l={determineSourceURL:function(b){return b?w.select([b.downloadURL,b.fileURL],function(a){if(!a||"file:"!==z.parse(a).protocol)return a})[0]:null},determineMetaURL:function(b){if(!b)return null;
var a,c=y.determineOrigin(b);c&&c.meta_header?a=b.fileURL:!b.fileURL||c&&!c.meta_url||(a=b.fileURL.replace(".user.js",".meta.js"),b.fileURL==a&&(a=b.fileURL.replace(".tamper.js",".meta.js")),b.fileURL==a&&(a=null));return w.select([b.updateURL,b.downloadURL,a],function(a){if(!a||"file:"!==z.parse(a).protocol)return a})[0]},mergeCludes:function(b){var a,c,d=b.options.override;["includes","excludes","matches"].forEach(function(a){b[a]=d["merge_"+a]&&d["orig_"+a]?d["orig_"+a].slice():[]});if(d.use_includes)for(a=
0;a<d.use_includes.length;a++)c=b.excludes.indexOf(d.use_includes[a]),0<=c&&b.excludes.splice(c,1),b.includes.push(d.use_includes[a]);if(d.use_matches)for(a=0;a<d.use_matches.length;a++)c=b.excludes.indexOf(d.use_matches[a]),0<=c&&b.excludes.splice(c,1),b.matches.push(d.use_matches[a]);if(d.use_excludes)for(a=0;a<d.use_excludes.length;a++)b.excludes.push(d.use_excludes[a]);return b},doSave:function(b){return q(b).then(f)},doRemove:function(b,a){A.removeByUid(b,a);A.setStorageByUid(b,null);N.dropAll(b);
return m.Pledge()},doModify:function(b,a,c){void 0===c&&(c=!0);A.setByUid(b,a,c);return c?N.loadResources(b,a.resources).then(function(){return N.loadRequires(b,a.requires)}).then(function(){var c=[].concat(a.resources).concat(a.requires).map(function(a){return z.sanitize(a.unsafe_url,a.abs_url)});return N.dropAllBut(b,c)}):m.Pledge()},exportToJson:function(b,a){var c=m(),d=y.determineScriptsToRun(null);b&&(d=w.select(d,function(a){return b[a.uuid]}));d=ra(d,{options_page:!0,externals:a.externals});
a&&!a.storage||d.forEach(function(a){a.storage=A.getStorageByUid(a.uuid)});d={scripts:d};if(!a||a.global_settings)d.global_settings=t.getValue(p.CONSTANTS.STORAGE.CONFIG,{});c.resolve(d);return c.promise()},importFromJson:function(b){if(!b||!b.scripts||!b.scripts.length)return m.Breach();for(var a={},c=[],d={},k={requires:{},resources:{}},e=0,g;g=b.scripts[e];e++)try{var l=m();"new-user-script"!=g.uuid&&(g.storage&&(d[g.uuid]=g.storage),["resources","requires"].forEach(function(a){var c;if(c=g[a])k[a][g.uuid]=
c}),q({uuid:g.uuid,name:g.name,src:g.source,force_settings:{enabled:g.enabled,position:g.position},force_options:g.options,force_meta:{lastModified:g.lastModified},replace:!0,url:g.file_url||g.update_url,ask:!1}).done(function(c){a[w.createUUID()]=c;l.resolve()}).fail(function(a){n.warn("import: Error @ script",g.name,a);l.resolve()}),c.push(l.promise()))}catch(H){n.warn("import: Error while importing script",g.name,H)}var r=function(){var a=m();m.when(c).always(function(){a.resolve()});return a.promise()}().then(function(){return W.import(a,
b.global_settings)}).then(function(c){var b=m(),e=[],g=[];if(c.ok)for(var v=0,r;r=c.import_ids[v];v++)(function(){var c=r;if(a[c]){a[c].messages.warnings=[];var b=a[c].script.uuid,c=f(a[c]).progress(function(){["resources","requires"].forEach(function(a){var c;(c=k[a][b])&&c.length&&c.forEach(function(a){N.setElement(b,a.url,{content:a.content||"",meta:a.mimetype||"text/javascript"},a.modified)})})}).done(function(){var a;d[b]&&(a=A.setStorageByUid(b,{data:d[b].data||{},ts:Date.now()}),g.push(a))});
e.push(c)}})();m.when(e).always(function(){y.reorderScripts();m.when(g).always(function(){b.resolve(c)})});return b.promise()}).then(function(a){return b.global_settings&&a.global_settings?(a=t.setValue(p.CONSTANTS.STORAGE.CONFIG,b.global_settings).then(function(){r.done(function(){window.setTimeout(V.reset,1)});return m.Pledge({global_settings:!0})}),t.setTemporary(!0),a):m.Pledge({})});return r},installFromUrl:function(b,a,c){var h=m(),k,f={messages:{errors:[d.getMessage("Unable_to_load_script_from_url_0url0",
b)],warnings:[]}};a=a||{};c=c||{};var e=["url",b,JSON.stringify(a)].join("_");if(g.is(e))return n.debug("scriptman: de-bounced installFromUrl",b),m.Breach();g.add(e);if((k=z.parse(b))&&k.protocol.match(/(https?|file):/))"file:"!=k.protocol||p.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS||n.warn("scriptman: Access to local files is forbidden! Loading the following script for installation may fail:",b,"-> more info:","https://tampermonkey.net/faq.php#Q204");else return n.warn("scriptman: can't install from ",
b),m.Breach(f);Z.getScriptFromURL(b).then(function(d){var k={url:b,src:d,ask:!0,replace:!0};a&&w.each(a,function(c,b){k[b]=a[b]});h.consume(l.installFromSource(d,k,c))}).fail(function(a){a?("file:"!=k.protocol||p.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS||f.messages.warnings.unshift(d.getMessage("Tampermonkey_has_no_file_access_permission_")),f.heading=d.getMessage("You_are_about_to_install_a_UserScript_"),c.silent_fail?h.reject(f):W.installError(f).always(function(a){h.reject(a)})):h.reject()});return h.promise()},
installFromSource:function(b,a,c){var h=m(),k={src:b,ask:!0,replace:!0};a&&w.each(a,function(c,b){k[b]=a[b]});l.doSave(k).done(function(a){h.resolve(a.installed)}).fail(function(a){a?(a.heading=d.getMessage("You_are_about_to_install_a_UserScript_"),c.silent_fail?h.reject(a):W.installError(a).always(function(a){h.reject(a)})):h.reject()});return h.promise()},determineLastPosition:function(){var b=0;A.getUidList().forEach(function(a){var d=A.getByUid(a);d.script&&d.cond?d.script.position&&d.script.position>
b&&(b=d.script.position):n.warn("scriptman: inconsistent script entry",a)});var a=new E.Script;a.position>b&&(b=a.position);return b},convertToRegExp:function(b,a){var c,d;try{a||"/"!=b.substr(0,1)?a?(d=z.getRegExpFromMatch(b),c=new RegExp(d)):(d=z.getRegExpFromInclude(b),c=new RegExp(d,"i")):c=new RegExp(("^"==b.substr(1,1)?"":".*")+b.replace(/^\//g,"").replace(/\/$/g,"")+("$"==b.substr(-2,1)?"":".*"),"i")}catch(k){return n.warn("scriptman: invalid regexp ",b),!1}return c},matchUrl:function(b,a){return""===
b.replace(a,"")},regexify:function(b,a){var c={},d={inc:"rinc",match:"rinc",exc:"rexc"};Object.keys(d).forEach(function(k){var f=b[k]&&b[k].length?b[k].map(function(a){return l.convertToRegExp(a,"match"===k)}).filter(function(a){return!1!==a}):null;if(f||a)c[d[k]]=(c[d[k]]||[]).concat(f||[])});return c},validUrl:function(b,a,c){var d=!1;if(a.rinc){if(a.rinc.every(function(a){return l.matchUrl(b,a)?(n.debug('scriptman: @include "'+a+'" matched'+(c?" ("+c+")":'"')),d=!0,!1):!0}),!d)return d}else d=
!0;a.rexc&&a.rexc.every(function(a){return l.matchUrl(b,a)?(n.debug('scriptman: @exclude "'+a+'" matched'+(c?" ("+c+")":'"')),d=!1):!0});return d},getEvilness:function(b){var a=0;return b.fileURL&&(a=S.getEvilnessOf(b.fileURL))||b.downloadURL&&(a=S.getEvilnessOf(b.downloadURL))||b.updateURL&&(a=S.getEvilnessOf(b.updateURL))?(n.debug("scriptman: found blacklisted script",b),a):0},blackCheckAll:function(){A.getUidList().forEach(function(b){var a=A.getByUid(b);if(a.script&&a.cond){var c=y.getEvilness(a.script);
if(c!==a.script.evilness){if(c||void 0!==a.script.evilness)n.debug("scriptman: write blacklist state of ",a.script.name,c),c&&M.tS(a.script.name,c,"b");a.script.evilness=c;l.doModify(b,a.script,!1)}}})},reorderScripts:function(b,a){var c=l.determineScriptsToRun();if(b)for(var d=0;d<c.length;d++){var k=c[d];k.uuid==b&&(k.position=Number(a)+(k.position<a?.5:-.5))}c=B(c);d=1;for(k=0;k<c.length;k++){var f=c[k];f.position=d++;l.doModify(f.uuid,f,!1)}},getScriptHistoryForTab:function(b){if(C.get.empty(b.id))n.debug("bg: WARN: Tabs.get.urls["+
b.id+"] is empty!");else return C.get.history(b.id);return{}},getUniqueScriptsForTab:function(b){var a={};C.get.empty(b.id)?n.debug("bg: WARN: Tabs.get.urls["+b.id+"] is empty!"):w.each(C.get.urls(b.id),function(c,b){if(U.isAllowed(b)){var d=X.get(c.frameId,b);[d.runners,d.disabled,d.evilness].forEach(function(c){c.forEach(function(c){a[c.uuid]={script:c}})})}});return a},scriptWillRun:function(b,a){if(a&&b){var c=K.items.regexp.get(b);if(!c){if(!(c=t.getValue(p.CONSTANTS.PREFIX.COND+b,null)))return;
c=l.regexify(c,!0);K.items.regexp.set(b,c)}return!!l.validUrl(a,c,b)}},determineScriptsToRun:function(b,a){var c=[];n.debug("scriptman: determineScriptsToRun @"+b);A.getUidList().forEach(function(h){var k=!0,f=0;b&&(f=Date.now(),k=l.scriptWillRun(h,b),f=Date.now()-f);var e=A.getByUid(h);e.script&&e.cond?(a&&1E3<f&&(n.warn("scriptman: checking "+e.script.name+"'s ("+h+") includes and excludes took "+f+"ms!"),O.all("status",{key:"slowdown",class:"warning",text:d.getMessage("Script_0name0_is_slowing_down_some_page_loads_",
e.script.name),timeout:3E5})),k&&c.push(e.script)):n.warn("scriptman: inconsistent script entry",h,e)});return B(c)},isContexter:function(b){return b.options&&("context-menu"===b.options.run_at||null===b.options.run_at&&"context-menu"===b.options.override.orig_run_at)},determineOrigin:function(b){return l.determineOriginOfUrl(b.fileURL||b.downloadURL||b.updateURL)},determineOriginOfUrl:function(b){if(b){var a=b.match(/https?:\/\/userscripts\.org\/scripts\/(source|version)\/([0-9]{1,9})\.user\.js/)||
b.match(/https?:\/\/userscripts-mirror\.org\/scripts\/(source|version)\/([0-9]{1,9})\.user\.js/);if(a&&3==a.length)return{id:a[2],token:"uso",meta_url:!0,url:"http://userscripts-mirror.org/scripts/show/"+a[2],issue_url:"http://contactbyweb.com/userscripts-mirror"};if((a=b.match(/https?:\/\/greasyfork\.org\/scripts\/([^/]+)\/code\/.*\.user\.js/))&&2==a.length)return b=a[1],{id:b,token:"gf",meta_url:!0,url:"https://greasyfork.org/scripts/"+b,issue_url:"https://greasyfork.org/scripts/"+b+"/feedback",
updates_allowed:function(a){return!a.match(/https?:\/\/greasyfork\.org\/scripts\/([^/]+)\/code\/.*\.user\.js.*version=[0-9]+.*/)}};if((a=b.match(/https?:\/\/openuserjs\.org\/install\/([^/]+)+\/(.*)\.user\.js/))&&3==a.length)return a.shift(),{id:a.join("/"),token:"ouj",meta_header:!0,url:"https://openuserjs.org/scripts/"+a[0]+"/"+a[1],issue_url:"https://openuserjs.org/scripts/"+a[0]+"/"+a[1]+"/issues"};if((a=b.match(/https?:\/\/monkeyguts\.com\/(codepages\/)?([0-9]{1,9})\.user\.js/))&&3==a.length)return b=
a[2],{id:b,token:"mog",meta_url:!0,url:"https://monkeyguts.com/code.php?id="+b,issue_url:"https://monkeyguts.com/code.php?nav=rev&id="+b};if((a=b.match(/https?:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/.*\.user\.js/)||b.match(/https?:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/.*\.user\.js/)||b.match(/https?:\/\/github\.com\/([^/]+)\/([^/]+)\/releases\/download\/.*\.user\.js/))&&3==a.length)return a.shift(),b=a.join("/"),{id:b,token:"gh",url:"https://github.com/"+b,issue_url:"https://github.com/"+
b+"/issues"};if((a=b.match(/https?:\/\/gitlab\.com\/([^/]+\/?[^/]*)\/([^/]+)\/raw\/.*\.user\.js/))&&3==a.length)return a.shift(),b=a.join("/"),{id:b,token:"gl",url:"https://gitlab.com/"+b,issue_url:"https://gitlab.com/"+b+"/issues"};if((a=b.match(/https?:\/\/bitbucket\.org\/([^/]+)\/([^/]+)\/(?:raw|downloads)\/.*\.user\.js/))&&3==a.length)return a.shift(),b=a.join("/"),{id:b,token:"bb",url:"https://bitbucket.org/"+b,issue_url:"https://bitbucket.org/"+b+"/issues"};if((b=b.match(/https?:\/\/userstyles\.org\/styles\/userjs\/([^/]+)\/.*\.user\.js/))&&
2==b.length)return b.shift(),{id:b[0],token:"usty",url:"https://userstyles.org/styles/"+b[0],issue_url:"https://forum.userstyles.org/post/discussion?Discussion/StyleID="+b[0],convert:function(a){var b,k,f,e,g,r=[{tag:"includes",re:/(?: \|\| \(new RegExp\("\^)([^$]+)(?:\$"\)\)\.test\(document\.location\.href\))/g,idx:1,value:function(a){return"/^"+a.replace(/\\\\(.)/g,"\\$1")+"$/"}},{tag:"matches",re:/(?: \|\| \(document\.domain == ")([^\"]+)"(?: \|\| document\.domain\.substring\(document\.domain\.indexOf\("[^\"]+"\) \+ 1\) == "[^\"]+"\))/g,
idx:1,value:function(a){return"*."+a}}],l=new RegExp("(?:if \\(false)("+r.map(function(a){return"(?:"+a.re.source+")"}).join("|")+")+","g");0===a.includes.length&&0===a.matches.length&&0===a.excludes.length&&a.options&&a.options.override&&a.options.override.orig_includes&&0===a.options.override.orig_includes.length&&a.options.override.orig_matches&&0===a.options.override.orig_matches.length&&(f=a.textContent.match(l))&&1===f.length&&(k=f[0])&&(r.forEach(function(b){for(;e=b.re.exec(k);)if(e.length>
b.idx){var d=b.value(e[b.idx]);a.options.override["orig_"+b.tag].push(d);a[b.tag].push(d);g=!0}}),g&&(b=d.getMessage("Automatically_added_user_includes_for_compatibility_reasons_")));return{script:a,warning:b}}}}}};return l}(),A=function(){var d=[],q={init:function(){t.addDifferentOriginChangeListener(p.CONSTANTS.PREFIX.STORE,function(d,e){if(e&&e.hasOwnProperty("value")&&e.origin){var l=d.replace(p.CONSTANTS.PREFIX.STORE,""),b;for(b in e.value.data)e.value.data.hasOwnProperty(b)&&function(){var a=
b,c=e.value.data[b];q.notifyStorageListeners({uuid:l},null,function(b){var d={data:{},ts:0};d.data[a]=c;d.ts=e.value.data.ts;var f={storage:d};void 0===d.data[a]&&(f.removed=a);b(f)})}()}})},getUidList:function(){var d=new RegExp("^"+p.CONSTANTS.PREFIX.SCRIPT_UID),e=[];t.listValues().forEach(function(l){-1!=l.search(d)&&e.push(l.replace(d,""))});return e},getUidsByName:function(d,e){var l=[];q.getUidList().forEach(function(b){var a=q.getMetaByUid(b);!a||a.name!=d||e&&e!=a.namespace||l.push(b)});return l},
getUidByName:function(d){return q.getUidsByName(d)[0]},getStorageByUid:function(d){d=t.getValue(p.CONSTANTS.PREFIX.STORE+d,{ts:0,data:{}});"undefined"===typeof d.ts&&(d.ts=0);"undefined"===typeof d.data&&(d.data={});return d},setStorageByUid:function(d,e){return e?t.setValue(p.CONSTANTS.PREFIX.STORE+d,e):t.deleteValue(p.CONSTANTS.PREFIX.STORE+d)},getMetaByUid:function(d){return t.getValue(p.CONSTANTS.PREFIX.META+d,null)},getByUid:function(d,e){if(!d)return n.error("sb: no UUID set"),{};var l,b=t.getValue(p.CONSTANTS.PREFIX.META+
d,null);if(b){var a=function(a){if(a)for(var b=0,d=null;d=a[b];b++)delete d.loaded,delete d.textContent,delete d.resURL,delete d.resText};a(b.requires);a(b.resources);b.uuid=d;b.grant=b.grant||[];b.options.override.use_connects||(b.connects=b.connects||[],b.options.override.merge_connects=!0,b.options.override.use_connects=[]);void 0===b.options.check_for_updates&&(b.options.check_for_updates=!0);e&&(b=w.copy(b,{}));b.textContent=t.getValue(p.CONSTANTS.PREFIX.SCRIPT+d,b.textContent);b.textContent&&
(l=b)}return{script:l,cond:t.getValue(p.CONSTANTS.PREFIX.COND+d,null)}},setByUid:function(d,e,l){var b={};if(!d)return n.error("sb: no UUID set",e),b;if(null===e.textContent||void 0===e.textContent)throw Error("No script code set!");var a=t.getValue(p.CONSTANTS.PREFIX.META+d),c=!a;t.setValue(p.CONSTANTS.PREFIX.SCRIPT_UID+d,e.name);t.setValue(p.CONSTANTS.PREFIX.COND+d,{inc:e.includes,match:e.matches,exc:e.excludes});t.setValue(p.CONSTANTS.PREFIX.SCRIPT+d,e.textContent);var h=w.copy(e,{});h.textContent=
null;t.setValue(p.CONSTANTS.PREFIX.META+d,h);l&&(ha.onScriptsChanged(),c?L.scriptAddedCb(e.name,e):L.scriptChangedCb(e.name,e,a));K.items.rundata.removeAll();K.items.regexp.remove(d);return b},removeByUid:function(d,g){void 0===g&&(g=!0);var l=q.getByUid(d);t.deleteValue(p.CONSTANTS.PREFIX.SCRIPT_UID+d);t.deleteValue(p.CONSTANTS.PREFIX.COND+d);t.deleteValue(p.CONSTANTS.PREFIX.SCRIPT+d);t.deleteValue(p.CONSTANTS.PREFIX.META+d);t.deleteValue(p.CONSTANTS.PREFIX.STORE+d);g&&(ha.onScriptsChanged(),l.script&&
l.cond&&(L.scriptRemovedCb(l.script.name,l.script),e.values&&M.tS(l.script.name,null,"r")));K.items.rundata.removeAll();K.items.regexp.remove(d);return{}},addStorageListener:function(e,g,l,b,a){d.push({tabid:e,id:g,uuid:l,time:b,response:a})},removeStorageListeners:function(e,g){void 0===g&&(g=!0);var l=d;d=[];l.forEach(function(b){try{void 0!==e.tabid&&e.tabid!==b.tabid||void 0!==e.uuid&&e.uuid!==b.uuid||void 0!==e.id&&e.id!==b.id?d.push(b):g&&b.response({})}catch(a){n.debug("sb: listener clear for script",
e,"failed! Page reload?!")}})},notifyStorageListeners:function(e,g,l){e=e||{};g=g||{};d.forEach(function(b){try{void 0!==g.uuid&&b.uuid===g.uuid||void 0!==g.tabid&&b.tabid===g.tabid||void 0!==g.id&&b.id===g.id||void 0!==e.tabid&&e.tabid!==b.tabid||void 0!==e.uuid&&e.uuid!==b.uuid||void 0!==e.id&&e.id!==b.id||l&&l(b.response)}catch(a){n.warn("sb: listener notification for script",e,"failed! Page reload?!")}})}};return q}();scbr=A;var xa=function(){var B={ping:{allow:{insecure:!0},exec:function(a,c,
b){b({pong:!0,instanceID:va,config:{layout:e.values.layout}})}},newTab:{allow:{extpage:!0},exec:function(a,c,b){("options"==c.extpage||"options"==a.origin?m.Pledge(c.tab):la()).then(function(c){rea.tabs.create({url:a.url,parent:c},function(a){b({tabId:a.id})})})}},getTab:{allow:{script:!0},exec:function(a,c,b){c.tab&&a.uuid?b({data:ia.get(c.tab.id,a.uuid)}):(n.warn("bg: unable to process request",c,a),b({data:null}))}},getTabs:{allow:{script:!0},exec:function(a,c,b){a.uuid?b({data:ia.getAll(a.uuid)}):
(n.warn("bg: unable to process request",c,a),b({data:null}))}},setTab:{allow:{script:!0},exec:function(a,c,b){c.tab&&a.uuid?ia.set(c.tab.id,a.uuid,a.tab):n.warn("bg: unable to process request",c,a);b({})}},focusTab:{allow:{script:!0},exec:function(a,c,b){(a=c&&c.tab?c.tab.id:null)?rea.tabs.update(a,{active:!0},function(){b({error:rea.runtime.lastError})}):b({error:"internal error"})}},closeTab:{allow:{script:!0},exec:function(a,c,b){var d=c&&c.tab?c.tab.id:null;d?rea.tabs.query({windowType:"normal"},
function(a){1>=a.length?(n.warn("bg:","refused to close last tab!"),b({error:"refused to close last tab!"})):rea.tabs.remove(d,function(){b({})})}):b({error:"internal error"})}},setOption:{allow:{extpage:!0},exec:function(a,c,b){var d="options"==c.extpage||"options"==a.origin;e.setValue(a.name,a.value).always(function(){d?T.create("options.settings").done(function(a){b({items:a,options:e.snapshot})}).fail(function(a){b({error:a,options:e.snapshot})}):b({})})}},reportAnIssue:{allow:{extpage:!0},exec:function(a,
c,b){("options"==c.extpage||"options"==a.origin?m.Pledge(c.tab):la()).then(function(c){var d,e,f,g;if(a.uuid&&(d=A.getByUid(a.uuid))&&d.script&&d.cond){e=y.determineOrigin(d.script);var l;if("hoster"==a.to&&e)f=e,g=[f.token,f.id].join(":");else if(l=d.script.supportURL||e.issue_url||e.url)f={issue_url:l},g=e?[a.to,e.token,e.id].join(":"):[a.to,f.url].join(":");f&&(M.tS(d.script.name,g,"m"),rea.tabs.create({url:f.abuse_url||f.issue_url,active:!0,parent:c},function(){}))}b({})})}},begEvent:{allow:{extpage:!0},
exec:function(a,c,b){if("dialog"==a.action)aa.dialog.shown(a.extra);else if("clicked"==a.action){var d,e;a.extra&&(d=a.extra.amount,e=a.extra.currency);aa.clicked(a.type,d,e)}else if(aa.button[a.action])aa.button[a.action](a.type,a.extra);else n.warn("bg: Warning: unknown request ",a);b({})}},buttonPress:{allow:{extpage:!0},exec:function(a,c,b){c=function(){b({})};if("reset_simple"==a.name)V.reset(c);else if("reset_factory"==a.name)V.factoryReset(c);else if("reset_sync"==a.name)L.reset().always(c);
else if("install_tests"==a.name)(c=sa.framework.prepare(y.doSave,p.RUNTIME.BROWSER,p.RUNTIME.BROWSER_VERSION,c))&&n.error(c);else if("enabled"==a.name)e.setValue(a.name,!e.values[a.name]).always(function(){b({})});else if("installFromUrl"==a.name)y.installFromUrl(a.data).always(function(){b({})});else if("externals_delete"==a.name)N.cleanElement(a.scriptuid,a.safe_url),T.create("options.scripts").done(function(a){b({items:a,options:e.snapshot})}).fail(function(a){b({error:a,options:e.snapshot})});
else if("focus_tab"==a.name)B.focusTab.exec({},{tab:{id:a.tabid}},b);else if("run_script_updates"==a.name)if(a.scriptuid){var d;Z.check(!0,!1,a.scriptuid).done(function(a){d=a}).always(function(){b({scriptuid:a.scriptuid,updatable:d})})}else Z.check(!0,!0),b({});else n.warn("bg: Warning: unknown button "+a.name),b({})}},loadTree:{allow:{extpage:!0},exec:function(a,c,b){T.create(a.referrer,{complete:a.complete,url:a.url,uuid:a.uuid,filter:a.filter,tabId:a.tabId}).done(function(c){c={items:c,i18n:e.values.i18n,
options:e.snapshot,begging:aa.needed()};a.layout&&(c.layout=ga.getLayoutByValue(e.values.layout));b(c)}).fail(function(a){b({error:a,options:e.snapshot})})}},modifyScriptOptions:{allow:{extpage:!0},exec:function(a,c,b){if(a.uuid){var d="options"==c.extpage||"options"==a.origin,f=void 0==a.reload||1==a.reload,g=!1,l=A.getByUid(a.uuid,!0);if(l.script&&l.cond){var r=!1,q=new E.Script;Object.keys(q.options).forEach(function(c){void 0!==a[c]&&(l.script.options[c]=a[c],g|=!0===L.SYNCED[c])});Object.keys(q.options.override).forEach(function(c){-1!=
c.search("merge_")&&void 0!==a[c]&&(l.script.options.override[c]=a[c],r=!0)});["includes","excludes","matches"].forEach(function(c){void 0!==a[c]&&(r=!0,l.script.options.override["use_"+c]=a[c])});["connects","blockers"].forEach(function(c){void 0!==a[c]&&(l.script.options.override["use_"+c]=a[c])});a.add_excludes&&(l.script.options.override.use_excludes=l.script.options.override.use_excludes.concat(a.add_excludes),r=!0);r&&(l.script=y.mergeCludes(l.script));a.temp_connects&&ea.setSessionConnects(l.script.uuid,
a.temp_connects);void 0!==a.enabled&&(l.script.enabled=a.enabled);g&&(l.script.lastModified=Date.now());void 0!==a.file_url&&(l.script.downloadURL=a.file_url);y.doModify(l.script.uuid,l.script,g).done(function(){f?(void 0!==a.position&&y.reorderScripts(a.uuid,a.position),d?B.loadTree.exec({referrer:"options.scripts"},c,b):rea.tabs.getSelected(null,function(c){T.create("actions").done(function(a){b({items:a,i18n:e.values.i18n,options:{enabled:e.values.enabled,layout:e.values.layout}})}).fail(function(){b({i18n:e.values.i18n,
options:{enabled:e.values.enabled,layout:e.values.layout}})});a.uuid&&e.values.autoReload&&rea.tabs.sendMessage(c.id,{method:"reload",frameId:0},function(){})})):b({})}).fail(function(){b({})})}else b({})}else b({})}},modifyNativeScript:{allow:{extpage:!0},exec:function(a,c,b){if(a.nid){var k=void 0==a.reload||1==a.reload;P.getUserscriptById(a.nid).then(function(b){if(b)if("installed"==a.actionid){if("false"==a.value)return P.uninstall(b)}else{if("enabled"==a.actionid)return P.setEnabled(b,a.value);
if("imported"==a.actionid&&"true"==a.value){var h=P.getUserscriptSource(b);if(h)return y.doSave({src:h,ask:!0,replace:!0}).then(function(a){if(a.installed){if("disable"==e.values.native_import_post_action)return P.setEnabled(b,!1);if("uninstall"==e.values.native_import_post_action)return P.uninstall(b)}});rea.tabs.sendMessage(c.tab.id,{method:"showMsg",msg:d.getMessage("Please_double_check_the_native_script_import_settings__")},function(){})}}else k=!1;return m.Pledge()}).always(function(){k?B.loadTree.exec({referrer:"options.scripts"},
c,b):b({})})}else b({})}},saveScript:{allow:{extpage:!0},exec:function(a,c,b){var k=void 0===a.reload||!!a.reload,f=function(a){k?T.create("options.scripts").done(function(c){a.items=c;a.options=e.snapshot;b(a)}).fail(function(a){b({error:a,options:e.snapshot})}):b({})};if(a.clean){n.debug("bg: clean userscript "+a.uuid);c=A.getByUid(a.uuid);var g=function(c){T.create("options.scripts").done(function(d){b({cleaned:c.installed,items:d,options:e.snapshot});c.installed&&A.notifyStorageListeners({uuid:a.uuid},
null,function(c){c({storage:A.getStorageByUid(a.uuid)})})}).fail(function(a){b({error:a,options:e.snapshot})})};c.script&&c.cond?y.doSave({name:a.name,uuid:a.uuid,src:c.script.textContent,clean:!0,ask:!1,internal:!0,save:!0}).always(function(a){g(a||{installed:!1})}):(n.error(d.getMessage("fatal_error")+" ("+a.uuid+")!!!"),g({installed:!1}))}else if(a.code){var l=b;k&&(l=function(a){y.reorderScripts();f(a)});a.new_script&&(a.uuid=w.createUUID());y.doSave({name:a.name,uuid:a.uuid,force_url:a.force_url,
src:a.code,ask:!e.values.editor_easySave,lastModTime:a.lastModTime,save:!0}).always(function(a){l(a||{installed:!1})})}else a.auto_save||(y.doRemove(a.uuid),y.reorderScripts()),f({})}},saveExternal:{allow:{extpage:!0},exec:function(a,c,b){N.setElement(a.uuid,a.url,{content:a.code||"",meta:a.mimetype||"text/javascript"},!0);T.create("options.scripts").done(function(a){b({success:!0,items:a,options:e.snapshot})}).fail(function(a){b({error:a,options:e.snapshot})})}},saveStorageKey:{allow:{extpage:!0},
exec:function(a,c,b){g.saveStorageKey.exec(null,a,c,b)}},exportToJson:{allow:{extpage:!0},exec:function(a,c,b){y.exportToJson(a.ids,a.options).done(function(a){b({json:a})}).fail(function(){b({})})}},importFromJson:{allow:{extpage:!0},exec:function(a,c,b){var k=void 0===a.reload||!!a.reload;y.importFromJson(a.json).fail(function(a){b({error:a||d.getMessage("An_error_occured_during_import_")})}).done(function(a){var c={reload:a.global_settings};k&&!c.reload?T.create("options.scripts").done(function(a){c.items=
a;c.options=e.snapshot;b(c)}).fail(function(a){b({error:a,options:e.snapshot})}):b(c)})}},download:{allow:{extpage:!0},exec:function(a,c,b){g.download.exec(null,a,c,function(a){(a.error||a.load)&&b(a)})}},askCom:{allow:{extpage:!0},exec:function(a,c,b){W.onMessage(a.data).always(function(c){c.i18n=e.values.i18n;c.options=e.snapshot;c.ext={version:rea.extension.manifest.version};a.data.layout&&(c.layout=ga.getLayoutByValue(e.values.layout));b(c)})}},installScript:{allow:{extpage:!0},exec:function(a,
c,b){if(c.tab){var e={};y.installFromUrl(a.url,{},{silent_fail:!0}).done(function(a){e={data:null,found:!0,installed:a}}).fail(function(a){e.err=a&&a.messages&&a.messages.errors?a.messages.errors[0]:d.getMessage("Unable_to_parse_this_")}).always(function(){b(e)})}else n.warn("bg: Error: unable to install script due to empty tabID!")}},execMenuCmd:{allow:{extpage:!0},exec:function(a,c,b){(a=ba.getById(a.id))?a.response({run:!0,menuId:a.id}):n.warn("bg: Error: unable to find MC id "+a.id);b({})}},unLoad:{allow:{script:!0},
exec:function(a,c){a.topframe||a.id&&c.frameId&&C.events.unload(c.tab.id,c.frameId,a.id);return!1}},prepare:{allow:{script:!0},exec:function(a,c,b){if(c.tab){var d=void 0!==c.frameId?c.frameId:a.topframe?0:null,e=z.woHash(a.url);a.cleanup?(C.events.clean(c.tab.id,d,e),Q.setIcon(c.tab.id),Q.setBadge(c.tab.id),b({})):C.events.run(c.tab.id,d,a.id,e,function(d){d=d?X.answer(d,a.url):{fast:!0};b(d);Q.setIcon(c.tab.id);Q.setBadge(c.tab.id)})}else b({})}},notification:{allow:{script:!0,extpage:!0},exec:function(a,
c,b){var d=a.image?a.image:rea.extension.getURL("images/icon128.png");(function(){var b=m();a.highlight&&c.tab?R.highlight(c.tab.id,b.resolve):b.resolve();return b.promise()})().then(function(){var c=m();a.text?R.show(a.title,a.text,d,a.timeout,c.resolve):c.resolve();return c.promise()}).always(function(a){b({clicked:a&&a.clicked})})}},determineScriptsToRun:{allow:{extpage:!0},exec:function(a,c,b){b({scripts:y.determineScriptsToRun(a.url).map(function(a){return a.uuid})})}},syntaxCheck:{allow:{script:!0,
extpage:!0},exec:function(a,c,b){(function(){var a=m();Registry.require("hinter",function(){a.resolve(Registry.get("hinter"))});return a.promise()})().then(function(c){return c.hint(a.code,e.values.editor_linter_config||void 0)}).always(function(a){b({errors:a})})}},externalMessage:{allow:{insecure:!0},exec:function(a,c,d){a=a.request;var k;if("off"!=e.values.external_connect&&(k=c.url)&&U.isAllowed(k)){for(var f,g,l,r=Object.keys(b.externally_connectable),q=0;q<r.length;q++)if(f=r[q],c=b.externally_connectable[f],
(g=y.regexify({match:[f]}))&&y.validUrl(k,g)&&(-1!=c.indexOf("*")||-1!=c.indexOf(a.method))){l=!0;break}if(l)if("getVersion"==a.method)d({version:rea.extension.manifest.version,id:rea.runtime.short_id});else if("all"!=e.values.external_connect)n.warn("mh: calling external method "+a.method+" is not permitted to "+k+" by the user");else if("isInstalled"==a.method){var x,m,p,B;k=!1;g=a.script.name;(m=A.getUidsByName(g,a.script.namespace)[0])&&(x=A.getByUid(m))&&x.script&&(k=!0,B=x.script.enabled,p=
x.script.version);d({name:g,installed:k,enabled:B,version:p})}else n.warn("mh: unknown external method "+a.method);else n.warn("mh: calling external method "+a.method+" is not permitted to "+k)}}},api:{allow:{script:!0},exec:function(a,c,b){M.tA(a.name,a.type);b()}}},q=function(a){var c=rea.runtime.id,c=!p.REQUESTS.HAS_SENDER_ID&&a.tab||a.id===c,b=null,d=p.REQUESTS.INTERNAL_PAGE_PROTOCOL+"//",e=p.REQUESTS.GET_INTERNAL_PAGE_REGEXP();a=a.url?a.url:a.tab?a.tab.url:null;if(d=c&&(a?0==a.search(d):!0))a?
(e=a.match(e))&&2==e.length&&(b=e[1]):b="*";return{id_valid:c,url:a,page:b,extpage:d}},f=function(a,c,b){if(!F.late)return F.registerLateCallback(function(){f(a,c,b)}),!0;var d=B[a.method];if(!d)return n.warn("mh: unknown method "+a.method),!1;if(!d.allow||!d.exec)return n.warn("mh: invalid implementation of "+a.method),!1;var e=q(c),g=e.extpage,l=e.page,e=e.id_valid;g?c.extpage=l:delete a.origin;var r="options"==l,m=!0;if("background"==l||d.allow.insecure||d.allow.extpage&&g||d.allow.options&&r||
d.allow.script&&e&&!g){if(d=d.exec(a,c,function(a){m=!1;b(a)}),!1!==m&&!1!==d)return!0}else return!1===a.topframe&&(g||r)||n.warn("mh: this context doesn't have the permission to call \""+a.method+'"'),!1},g={xhr:{allow:{script:!0},exec:function(a,c,b,d){var f=!1,g=function(){a.disconnect()};c.details.convertBinary=!0;c.details.partialSize=c.details.partialSize||p.XMLHTTPREQUEST.PARTIAL_SIZE;var l={};Object.keys(c.callbacks).forEach(function(a){var b="ondone"===a;if(c.callbacks[a]||b||"onload"===
a)l[a]=function(c){c={data:c.response,exception:c.exception};c[a]=!0;d(c);b&&g()}});l.ondone||(l.ondone=g);var r=function(a){var c=m(),b=[];rea.cookies.getAll({url:a},function(a){b=b.concat(a);c.resolve(b)});return c.promise()},q;c.details.url=z.sanitize(c.details.url,c.url||b.url||null)||c.details.url;p.RUNTIME.WEBREQUEST_XHR_SUPPORT&&"no"!=e.values.webrequest_modHeaders&&(c.details.headers=c.details.headers||{},c.details.headers.internal=c.uuid,p.REQUESTS.SENDS_ORIGIN&&-1==Object.keys(c.details.headers).map(function(a){return a.toLowerCase()}).indexOf("origin")&&
(c.details.headers.origin=null));(function(){return c.details.cookie&&c.details.url?r(c.details.url).then(function(a){a=a.map(function(a){return a.name+"="+encodeURIComponent(a.value)}).concat([c.details.cookie]).join(";");delete c.details.cookie;c.details.headers=c.details.headers||{};c.details.headers.cookie=a}):m.Pledge()})().then(function(){if(!f){var a;if(c.details.url&&(a=z.parse(c.details.url).protocol)&&-1!=["file:",p.REQUESTS.INTERNAL_PAGE_PROTOCOL].indexOf(a)){var d=function(a){var b='Refused to connect to "'+
c.details.url+'": '+a,d=ma.makeErrorResponse(b);["onerror","ondone"].forEach(function(a){if(l[a])l[a]({response:d,exception:b})})};if("file:"==a){var k,g;p.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS&&("all"==e.values.script_file_access?k=!0:"externals"==e.values.script_file_access&&(g=A.getByUid(c.uuid))&&g.script&&g.cond&&-1!=[].concat(g.script.resources).concat(g.script.requires).map(function(a){return z.sanitize(a.unsafe_url,a.abs_url)}).indexOf(c.details.url)&&(k=!0));if(!k)return d("Access to this local file is forbidden!")}rea.file.get(c.details.url,
function(a){var c={response_data:J.arrbuf2str(a),readyState:4,responseHeaders:"",status:0,statusText:""};["onload","ondone"].forEach(function(a){if(l[a])l[a]({response:c})})},d)}else q=ea.exec(c.details,c.uuid,b||{},l)}});return function(){f=!0;q&&q.abort()}}},download:{allow:{script:!0},exec:function(a,c,b,d){c=c.details;c.internal=null===a;var e=G.start(c,{onload:function(a){d&&d({load:!0,data:a})},onprogress:function(a){d&&d({progress:!0,data:a})},onerror:function(a){d&&d({error:!0,data:a})},ontimeout:function(a){d&&
d({timeout:!0,data:a})},ondone:function(){a&&a.disconnect();a=null}});a&&void 0!==e&&a.onMessage.addListener(function(a){a.cancel&&null!==e&&(G.cancel(e),e=null)});return function(){d=a=null}}},webRequest:{allow:{script:!0},exec:function(a,c,b,d){a=b.tab.id;b=b.frameId;(void 0!==a&&void 0!==b||!c.uuid)&&da.scripts.set(a,b,c.uuid,c.rules,function(a){d(a)})}},addStorageListener:{allow:{script:!0},exec:function(a,c,b,d){if(b.tab)return A.addStorageListener(b.tab.id,c.id,c.uuid,Date.now(),d),function(){A.removeStorageListeners({uuid:c.uuid,
id:c.id},!1)};d({error:!0})}},saveStorageKey:{allow:{script:!0},exec:function(a,c,b,d){b.tab?c.uuid&&(a=A.getStorageByUid(c.uuid),a.data[c.key]=c.value,a.ts=c.ts,A.setStorageByUid(c.uuid,a),A.notifyStorageListeners({uuid:c.uuid},{id:c.id},function(a){var b={data:{},ts:0};b.data[c.key]=c.value;b.ts=c.ts;var d={storage:b};void 0===b.data[c.key]&&(d.removed=c.key);a(d)})):n.warn("storage: unable to save storage due to empty tabID!");d({})}},openInTab:{allow:{script:!0},exec:function(a,c,d,e){var f,g=
["active"],l={url:c.details.url},r=null;if(f=c.details.options){for(var q=0;q<g.length;q++)void 0!==f[g[q]]&&(l[g[q]]=f[g[q]]);f.insert&&(l.index=d.tab.index+1);f.setParent&&(l.parent=d.tab)}rea.tabs.create(l,function(c){r=c.id;a&&(ca[r]={onClose:function(){a&&e({closed:!0})}},e({success:!0,tabId:r}))});a.onMessage.addListener(function(a){if(null!==r)if(a.close)rea.tabs.remove(r),r=null;else if(void 0!==a.name){var d=3,h=function(){C.listeners.once.whenReady(b.tabId,function(){rea.tabs.sendMessage(b.tabId,
{method:"setForeignAttr",attr:"name",value:c.name},function(a){a?e({name:c.name}):0<d--?h():n.warn("foreignAttr: error setting attr")})})};h()}});return function(){null!==r&&delete ca[r];a=null}}},registerMenuCommand:{allow:{script:!0},exec:function(a,c,b,d){if(b.tab)return ba.add(b.tab.id,c.name,c.uuid,c.accessKey,c.menuId,d),O.actionPage("update"),function(){ba.clearById(c.menuId);O.actionPage("update")};n.warn("Unable to register menu cmd due to empty tabID!");a.disconnect()}},tabWatch:{allow:{extpage:!0},
exec:function(a,c,b,d){var e=ta.openAndWatch({url:c.url,index:(b.tab.index||0)+1,parent:b.tab},function(c){c?d({tab:c}):(f(),a.disconnect())}),f=function(){e.cancel()};return f}}},l=function(){var a=function(a,b){var d=a.sender,e=g[b.method];if(!e)return n.warn("mh: unknown method "+b.method),!1;if(!e.allow||!e.exec)return n.warn("mh: invalid implementation of "+b.method),!1;var f=q(d),l=f.extpage,r=f.page,m="options"==r,f=f.id_valid&&!l;if("background"==r||e.allow.insecure||e.allow.extpage&&l||e.allow.options&&
m||e.allow.script&&f)(d=e.exec(a,b,d,function(b){try{a.postMessage(b)}catch(d){n.debug("bg: Error sending port ("+a.name+") message",b)}}))&&a.onDisconnect.addListener(d);else return!1===b.topframe&&(l||m)||n.warn("mh: this context doesn't have the permission to call \""+b.method+'"'),!1};return function(c){F.late?c.onMessage.addListener(function(b){void 0!==b.method&&a(c,b)}):F.registerLateCallback(function(){l(c)})}}(),b={init:function(){b.externally_connectable_reg=y.regexify({match:Object.keys(b.externally_connectable)});
rea.extension.onMessage.addListener(f);rea.extension.onConnect.addListener(l);rea.extension.onConnectExternal.addListener(function(a){a.disconnect()})},externally_connectable:{"*://tampermonkey.net/*":["getVersion"],"https://greasyfork.org/*":["*"],"https://userstyles.org/*":["*"]}};return b}(),ba=function(){var d=[];return{add:function(e,f,g,l,b,a){d.push({tabId:e,name:f,uuid:g,accessKey:l,id:b,response:a})},list:function(){return d},listByTabId:function(e){var f={};return d.filter(function(d){var l=
d.uuid+d.name;return d.tabId==e&&!f[l]&&(f[l]=!0)})},clearByTabId:function(e){d=d.filter(function(d){return d.tabId!=e})},getByTabId:function(e){return d.filter(function(d){return d.tabId==e})[0]},clearById:function(e){d=d.filter(function(d){return d.id!=e})},getById:function(e){return d.filter(function(d){return d.id==e})[0]}}}(),Ha=function(){return{create:function(){var m,q,f,g,l,b,a,c,h,k,v,u,t,r;k=null;m={name:d.getMessage("General"),sub_menu_item:!0,items:[]};m.items.push({name:d.getMessage("Config_Mode"),
id:"configMode",level:0,option:!0,select:[{name:d.getMessage("Novice"),value:0},{name:d.getMessage("Beginner"),value:50},{name:d.getMessage("Advanced"),value:100}],value:e.values.configMode,desc:d.getMessage("Changes_the_number_of_visible_config_options")});m.items.push({name:d.getMessage("Language"),id:"i18n",level:0,option:!0,reload:!0,warning:d.getMessage("A_reload_is_required"),select:[{name:"Browser Default",value:null}].concat(d.supported),value:e.values.i18n,validation:{image:"info",opacity:.9,
msg:d.getMessage("Your_language_is_not_supported__Click_here_to_get_intructions_how_to_translate_TM_"),url:"https://tampermonkey.net/faq.php#Q500"}});m.items.push({name:d.getMessage("Auto_reload_on_script_enabled"),level:20,id:"autoReload",option:!0,checkbox:!0,enabled:e.values.autoReload,desc:d.getMessage("Auto_reload_on_script_enabled_desc")});m.items.push({name:d.getMessage("Anonymous_statistics"),level:0,id:"statistics_enabled",option:!0,checkbox:!0,enabled:!!e.values.statistics_enabled,validation:{image:"info",
opacity:.9,msg:d.getMessage("Allow_Tampermonkey_to_collect_anonymous_statistics_via_Google_Analytics"),url:"https://tampermonkey.net/privacy.php#extension"}});m.items.push({name:d.getMessage("Debug_scripts"),level:100,id:"debug",option:!0,checkbox:!0,enabled:e.values.debug,desc:""});m.items.push({name:d.getMessage("Show_fixed_source"),level:100,id:"showFixedSrc",option:!0,checkbox:!0,enabled:e.values.showFixedSrc,desc:""});m.items.push({name:d.getMessage("LogLevel"),id:"logLevel",level:0,option:!0,
select:[{name:d.getMessage("Debug"),value:60},{name:d.getMessage("Warning"),value:30},{name:d.getMessage("Error"),value:0}],value:e.values.logLevel,desc:""});p.OPTIONS.NATIVE_SCRIPT_IMPORT&&(q={name:d.getMessage("Native_Script_Import"),sub_menu_item:!0,need_save:!0,items:[]},k={},e.values.native_import&&(k=!0===p.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS?{image:"button_ok",msg:d.getMessage("TM_has_access_to_file_URIs")}:{image:"critical",msg:d.getMessage("Tampermonkey_needs_access_to_file_URIs__Visit_the_FAQ_"),
url:"https://tampermonkey.net/faq.php#Q204"}),q.items.push({name:d.getMessage("Enable_Native_Script_Import"),id:"native_import",level:0,option:!0,checkbox:!0,enabled:e.values.native_import,validation:k}),q.items.push({name:d.getMessage("Post_Import_Action"),id:"native_import_post_action",level:0,option:!0,select:[{name:d.getMessage("None"),value:"none"},{name:d.getMessage("Disable_Extension"),value:"disable"},{name:d.getMessage("Uninstall_Extension"),value:"uninstall"}],value:e.values.native_import_post_action,
desc:d.getMessage("What_action_should_be_done_after_a_native_userscript_was_imported_sucessfully_")}),k={},e.values.native_import&&(k=P.isPathValid()?{image:"button_ok",msg:d.getMessage("Everything_is_setup_correctly_")}:{image:"critical",msg:d.getMessage("Tampermonkey_needs_to_know_the_absolute_path_to_your_browser_profile_folder_Visit_the_FAQ_"),url:"https://tampermonkey.net/faq.php#Q205"}),q.items.push({name:d.getMessage("Browser_Profile_Path"),id:"native_import_path",level:0,option:!0,text:!0,
width:2,value:e.values.native_import_path,validation:k}));u={name:d.getMessage("Script_Sync"),sub_menu_item:!0,level:50,need_save:!0,items:[]};u.items.push({name:d.getMessage("Enable_Script_Sync"),id:"sync_enabled",level:50,option:!0,checkbox:!0,enabled:e.values.sync_enabled,desc:d.getMessage("Synchronize_your_scripts_across_browsers_and_operation_systems")});f=function(){var a=[],b={reset_sync:!0,cloud_url:!1,cloud_user:!1,cloud_pass:!1};rea.storage.sync.supported&&a.push({name:d.getMessage("Browser_Sync"),
value:D.types.eCHROMESYNC,enable:b});a.push({name:"Google Drive",value:D.types.eGDRIVE,enable:b});p.RUNTIME.CHROME&&37>p.RUNTIME.BROWSER_VERSION||p.RUNTIME.SAFARI&&8>p.RUNTIME.BROWSER_VERSION||p.RUNTIME.DOLPHIN?n.info("Script Sync: no Dropbox support due to missing SHA-256 capabilities"):a.push({name:"Dropbox",value:D.types.eDROPBOX,enable:b});a.push({name:"WebDAV",value:D.types.eWEBDAV,enable:{reset_sync:!0,cloud_url:!0,cloud_user:!0,cloud_pass:!0}});return a}();u.items.push({name:d.getMessage("Sync_Type"),
id:"sync_type",enabler:!0,level:50,option:!0,select:f,value:e.values.sync_type});u.items.push({name:d.getMessage("URL"),id:"cloud_url",enabledBy:"sync_type",level:50,option:!0,text:!0,width:2,value:e.values.cloud_url});u.items.push({name:d.getMessage("Login"),id:"cloud_user",enabledBy:"sync_type",level:50,option:!0,text:!0,width:2,value:e.values.cloud_user});u.items.push({name:d.getMessage("Password"),id:"cloud_pass",enabledBy:"sync_type",level:50,option:!0,text:!0,password:!0,width:2,value:e.values.cloud_pass});
u.items.push({name:d.getMessage("Sync_Reset"),id:"reset_sync",enabledBy:"sync_type",level:80,button:!0,reload:!0,value:0,warning:d.getMessage("This_will_remove_all_remote_data_from_sync_Ok_")});b={name:d.getMessage("Appearance"),sub_menu_item:!0,need_save:!0,items:[],warning:d.getMessage("A_reload_is_required"),reload:!0};b.items.push({name:d.getMessage("Layout"),id:"layout",level:0,option:!0,select:ga.getLayouts(),value:e.values.layout,desc:""});b.items.push({name:d.getMessage("Custom_CSS"),id:"layout_user_css",
level:100,option:!0,input:!0,value:e.values.layout_user_css,desc:d.getMessage("You_can_add_your_custom_CSS_rules_here_")});k={};"off"==e.values.notification_showUpdate&&(k={image:"critical",msg:d.getMessage("Are_you_sure_that_you_don_t_want_to_be_notified_of_updates_")});b.items.push({name:d.getMessage("Update_Notification"),id:"notification_showUpdate",level:50,option:!0,select:[{name:d.getMessage("Disabled"),value:"off"},{name:d.getMessage("Show_notification"),value:"notification"},{name:d.getMessage("Open_changelog"),
value:"changelog"}],value:e.values.notification_showUpdate,validation:k});b.items.push({name:d.getMessage("Favicon_Service"),id:"favicon_service",level:50,option:!0,select:[{name:d.getMessage("Google"),value:"google"},{name:d.getMessage("DuckDuckGo"),value:"duckduckgo"},{name:d.getMessage("Native"),value:"native",warning:d.getMessage("Warning_unsafe_site_warnings_might_appear_")}],value:e.values.favicon_service});a={name:d.getMessage("Action_Menu"),sub_menu_item:!0,items:[],level:50};a.items.push({name:d.getMessage("Hide_disabled_scripts"),
id:"action_menu_scripts_hide_disabled",level:100,option:!0,checkbox:!0,enabled:e.values.action_menu_scripts_hide_disabled,desc:""});a.items.push({name:d.getMessage("Columns"),id:"action_menu_columns",level:50,option:!0,select:[{name:d.getMessage("1"),value:"1"},{name:d.getMessage("2"),value:"2"},{name:d.getMessage("3"),value:"3"}],value:e.values.action_menu_columns});a.items.push({name:d.getMessage("Script_order"),id:"action_menu_scripts_sort",level:50,option:!0,select:[{name:d.getMessage("Auto"),
value:"auto"},{name:d.getMessage("Position_"),value:"position"},{name:d.getMessage("Name"),value:"name"},{name:d.getMessage("Enabled"),value:"enabled"}],value:e.values.action_menu_scripts_sort});a.items.push({name:d.getMessage("Icon_badge_info"),id:"appearance_badges",level:50,option:!0,select:[{name:d.getMessage("Disabled"),value:"off"},{name:d.getMessage("Running_scripts"),value:"running"},{name:d.getMessage("Unique_running_scripts"),value:"running_unique"},{name:d.getMessage("Disabled_scripts"),
value:"disabled"}],value:e.values.appearance_badges});(p.RUNTIME.CHROME||p.RUNTIME.FIREFOX)&&a.items.push({name:d.getMessage("Icon_badge_color"),id:"appearance_badge_color",level:100,color:!0,value:e.values.appearance_badge_color});f={name:d.getMessage("Editor"),sub_menu_item:!0,level:20,need_save:!0,items:[],warning:d.getMessage("A_reload_is_required"),reload:!0};f.items.push({name:d.getMessage("Enable_Editor"),id:"editor_enabled",level:100,option:!0,checkbox:!0,enabled:e.values.editor_enabled,desc:""});
f.items.push({name:d.getMessage("Theme"),id:"editor_theme",level:50,option:!0,select:ga.getEditorThemes(),value:e.values.editor_theme});f.items.push({name:d.getMessage("Font_Size"),id:"editor_fontSize",level:50,option:!0,select:[{name:"50%",value:50},{name:"70%",value:70},{name:"80%",value:80},{name:"90%",value:90},{name:"100%",value:100},{name:"110%",value:110},{name:"120%",value:120},{name:"150%",value:150}],value:e.values.editor_fontSize});f.items.push({name:d.getMessage("Key_Mapping"),id:"editor_keyMap",
level:50,option:!0,select:[{name:d.getMessage("Windows"),value:"windows"},{name:d.getMessage("Sublime"),value:"sublime"},{name:d.getMessage("Emacs"),value:"emacs"},{name:d.getMessage("Vim"),value:"vim"}],value:e.values.editor_keyMap});f.items.push({name:d.getMessage("Indentation_Width"),id:"editor_indentUnit",level:50,option:!0,select:[{name:d.getMessage("1"),value:1},{name:d.getMessage("2"),value:2},{name:d.getMessage("3"),value:3},{name:d.getMessage("4"),value:4},{name:d.getMessage("5"),value:5},
{name:d.getMessage("6"),value:6},{name:d.getMessage("7"),value:7},{name:d.getMessage("8"),value:8},{name:d.getMessage("9"),value:9},{name:d.getMessage("10"),value:10},{name:d.getMessage("11"),value:11}],value:e.values.editor_indentUnit,desc:""});f.items.push({name:d.getMessage("Indent_with"),id:"editor_indentWithTabs",level:50,option:!0,select:[{name:d.getMessage("Tabs"),value:"tabs"},{name:d.getMessage("Spaces"),value:"spaces"}],value:e.values.editor_indentWithTabs,desc:""});f.items.push({name:d.getMessage("TabMode"),
id:"editor_tabMode",level:50,option:!0,select:[{name:d.getMessage("Classic"),value:"classic"},{name:d.getMessage("Smart"),value:"smart"},{name:d.getMessage("Indent"),value:"indent"}],value:e.values.editor_tabMode,desc:""});f.items.push({name:d.getMessage("Line_break"),id:"editor_lineWrapping",level:50,option:!0,checkbox:!0,enabled:e.values.editor_lineWrapping,desc:""});f.items.push({name:d.getMessage("Reindent_on_typing"),id:"editor_electricChars",level:50,option:!0,checkbox:!0,enabled:e.values.editor_electricChars,
desc:""});f.items.push({name:d.getMessage("Enable_autoSave"),id:"editor_autoSave",level:20,option:!0,checkbox:!0,enabled:e.values.editor_autoSave,desc:""});f.items.push({name:d.getMessage("Enable_easySave"),id:"editor_easySave",level:20,option:!0,checkbox:!0,enabled:e.values.editor_easySave,desc:""});f.items.push({name:d.getMessage("Highlight_trailing_whitespace"),id:"editor_highlightTrailingWhitespace",level:50,option:!0,checkbox:!0,enabled:e.values.editor_highlightTrailingWhitespace,desc:""});f.items.push({name:d.getMessage("Trim_trailing_whitespace_from_modified_lines"),
id:"editor_trimTrailingSpacesFromModifiedLines",level:50,option:!0,checkbox:!0,enabled:e.values.editor_trimTrailingSpacesFromModifiedLines,desc:""});f.items.push({name:d.getMessage("Auto_syntax_check_on_typing"),id:"editor_autoLint",level:50,option:!0,checkbox:!0,enabled:e.values.editor_autoLint,desc:d.getMessage("Enable_this_option_to_automatically_check_the_code_on_typing_")});f.items.push({name:d.getMessage("Auto_syntax_check_max_length"),id:"editor_autoLintMaxLen",level:50,option:!0,text:!0,value:e.values.editor_autoLintMaxLen,
desc:d.getMessage("Check_only_scripts_up_to_this_size_automatically_")});f.items.push({name:d.getMessage("Custom_Linter_Config"),id:"editor_linter_config",level:100,option:!0,input:!0,json:!0,value:e.values.editor_linter_config,validation:{image:"info",opacity:.9,msg:d.getMessage("You_can_add_your_custom_linter_config_here_"),url:"https://eslint.org/docs/user-guide/configuring"}});l={name:d.getMessage("Script_Update"),sub_menu_item:!0,level:0,items:[]};l.items.push({name:d.getMessage("Check_disabled_scripts"),
id:"scriptUpdateCheckDisabled",level:0,option:!0,checkbox:!0,enabled:e.values.scriptUpdateCheckDisabled,desc:""});l.items.push({name:d.getMessage("Dont_ask_me_for_simple_script_updates"),id:"notification_silentScriptUpdate",level:80,option:!0,checkbox:!0,enabled:e.values.notification_silentScriptUpdate,desc:""});l.items.push({name:d.getMessage("Check_interval"),id:"scriptUpdateCheckPeriod",level:0,option:!0,select:[{name:d.getMessage("Never"),value:0},{name:d.getMessage("Every_6_Hours"),value:216E5},
{name:d.getMessage("Every_12_Hour"),value:432E5},{name:d.getMessage("Every_Day"),value:864E5},{name:d.getMessage("Every_Week"),value:6048E5}],value:e.values.scriptUpdateCheckPeriod,desc:""});l.items.push({name:d.getMessage("Hide_notification_after"),id:"scriptUpdateHideNotificationAfter",level:50,option:!0,select:[{name:d.getMessage("Never"),value:0},{name:d.getMessage("15_Seconds"),value:15E3},{name:d.getMessage("30_Seconds"),value:3E4},{name:d.getMessage("1_Minute"),value:6E4},{name:d.getMessage("5_Minutes"),
value:3E5},{name:d.getMessage("1_Hour"),value:36E5}],value:e.values.scriptUpdateHideNotificationAfter,desc:""});g={name:d.getMessage("Externals"),sub_menu_item:!0,level:0,items:[]};g.items.push({name:d.getMessage("Update_interval"),id:"external_update_interval",level:0,option:!0,select:[{name:d.getMessage("Always"),value:1},{name:d.getMessage("Every_Day"),value:864E5},{name:d.getMessage("Every_Week"),value:6048E5},{name:d.getMessage("Every_Month"),value:2592E6},{name:d.getMessage("Never"),value:0}],
value:e.values.external_update_interval,desc:""});c={name:d.getMessage("Security"),sub_menu_item:!0,level:50,items:[]};p.OPTIONS.HAS_CSP&&(c.items.push({name:d.getMessage("Add_TM_to_CSP"),id:"webrequest_fixCSP",level:80,option:!0,select:[{name:d.getMessage("Yes"),value:"yes"},{name:d.getMessage("No"),value:"no"}],value:e.values.webrequest_fixCSP,desc:d.getMessage("Tampermonkey_might_not_be_able_to_provide_access_to_the_unsafe_context_when_this_is_disabled")}),c.items.push({name:d.getMessage("Allow_headers_to_be_modified_by_scripts"),
id:"webrequest_modHeaders",level:80,option:!0,reload:!0,select:[{name:d.getMessage("Yes"),value:"yes"},{name:d.getMessage("Auto"),value:"auto"},{name:d.getMessage("No"),value:"no"}],value:e.values.webrequest_modHeaders,warning:d.getMessage("Tampermonkey_needs_to_be_restarted_to_make_this_change_apply_Do_you_want_to_continue_"),desc:""}));p.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS&&c.items.push({name:d.getMessage("Script_local_files_access"),id:"script_file_access",level:80,option:!0,select:[{name:d.getMessage("All_local_files"),
value:"all"},{name:d.getMessage("require_and_resource"),value:"externals"},{name:d.getMessage("Disabled"),value:"off"}],value:e.values.script_file_access});c.items.push({name:d.getMessage("Allow_communication_with_cooperate_pages"),id:"external_connect",level:80,option:!0,reload:!0,select:[{name:d.getMessage("Tampermonkey_and_script_version"),value:"all"},{name:d.getMessage("Tampermonkey_version"),value:"version"},{name:d.getMessage("Disabled"),value:"off"}],value:e.values.external_connect,desc:d.getMessage("This_option_allows_the_Tampermonkey_homepage_and_some_script_hosting_pages_to_determine_the_Tampermonkey_version_and_whether_a_script_is_installed_")});
c.items.push({name:d.getMessage("Subresource_Integrity"),id:"require_sri_mode",level:80,option:!0,select:[{name:d.getMessage("Disabled"),value:"ignore"},{name:d.getMessage("Validate_if_supported"),value:"supported"},{name:d.getMessage("Validate_if_given"),value:"given"},{name:d.getMessage("Enforce"),value:"enforce"}],value:e.values.require_sri_mode,desc:d.getMessage("Script_authors_can_secure_external_resources_by_adding_a_SRI_hash_to_the_URL_")});c.items.push({name:d.getMessage("connect_mode"),id:"connect_mode",
level:50,option:!0,select:(80<=e.values.configMode||-1!=["off","casual"].indexOf(e.values.connect_mode)?[{name:d.getMessage("Disabled"),value:"off"},{name:d.getMessage("Casual"),value:"casual"}]:[]).concat([{name:d.getMessage("Ask_if_unknown"),value:"ask"},{name:d.getMessage("Strict"),value:"strict"},{name:d.getMessage("Always_ask"),value:"paranoid"}]),value:e.values.connect_mode,desc:""});p.RUNTIME.INCOGNITO_MODE&&!rea.extension.inIncognitoContext&&(k="temporary"==e.values.incognito_mode?{}:{image:"critical",
msg:"Permanent mode is still a BETA feature!"},c.items.push({name:d.getMessage("Store_data_in_incognito_mode"),id:"incognito_mode",level:50,option:!0,select:[{name:d.getMessage("Temporary"),value:"temporary"},{name:d.getMessage("Permanent"),value:"permanent"}],value:e.values.incognito_mode,validation:k}));c.items.push({name:d.getMessage("Page_Filter_Mode"),id:"page_filter_mode",level:50,option:!0,select:[{name:d.getMessage("Disabled"),value:"off"},{name:d.getMessage("Blacklist"),value:"black"},{name:d.getMessage("Whitelist"),
value:"white"},{name:d.getMessage("Both"),value:"black+white"}],value:e.values.page_filter_mode,desc:""});c.items.push({name:d.getMessage("Whitelisted_Pages"),id:"page_whitelist",level:50,option:!0,input:!0,array:!0,value:e.values.page_whitelist,desc:""});c.items.push({name:d.getMessage("Blacklisted_Pages"),id:"forbiddenPages",level:50,option:!0,input:!0,array:!0,value:e.values.forbiddenPages,desc:""});h={name:d.getMessage("BlackCheck"),sub_menu_item:!0,level:50,items:[]};h.items.push({name:d.getMessage("Script_Blacklist_Source"),
id:"script_blacklist_type",level:50,option:!0,select:[{name:d.getMessage("Disabled"),value:"off"},{name:d.getMessage("Server_And_Manual"),value:"server"},{name:d.getMessage("Only_Manual"),value:"only_manual"}],value:e.values.script_blacklist_type});h.items.push({name:d.getMessage("Blacklist_Severity"),id:"script_blacklist_severity",level:50,option:!0,select:[{name:d.getMessage("severity_1"),value:1},{name:d.getMessage("severity_2"),value:2},{name:d.getMessage("severity_3"),value:3},{name:d.getMessage("severity_4"),
value:4},{name:d.getMessage("severity_5"),value:5},{name:d.getMessage("severity_6"),value:6},{name:d.getMessage("severity_7"),value:7},{name:d.getMessage("severity_8"),value:8},{name:d.getMessage("severity_9"),value:9},{name:d.getMessage("severity_10"),value:10}],value:e.values.script_blacklist_severity});h.items.push({name:d.getMessage("Manual_Script_Blacklist"),id:"require_blacklist",level:50,option:!0,input:!0,array:!0,value:e.values.require_blacklist,desc:""});if(p.OPTIONS.CAN_DOWNLOAD){var H=
!1;k={};w.map("exe sh crx com bat scr".split(" "),function(a){return"name."+a}).forEach(function(a){H|=G.is_whitelisted(a)});H&&(k={image:"critical",msg:d.getMessage("Your_whitelist_seems_to_include_executable_files_This_means_your_userscripts_may_download_malware_or_spyware_to_your_harddisk_")});r={name:d.getMessage("Downloads")+" BETA",sub_menu_item:!0,level:50,items:[]};r.items.push({name:d.getMessage("Download_Mode"),id:"downloads_mode",level:50,option:!0,select:w.select([{name:d.getMessage("Default"),
value:G.staticVars.DEFAULT},{name:d.getMessage("Disabled"),value:G.staticVars.OFF},{name:d.getMessage("Native"),value:G.staticVars.NATIVE},{name:d.getMessage("Browser_API"),value:rea.downloads.supported?G.staticVars.CHROME:null}],function(a){return a.value}),value:e.values.downloads_mode,desc:d.getMessage("The_Browser_API_mode_requires_a_special_permission_")});r.items.push({name:d.getMessage("Whitelisted_File_Extensions"),id:"downloads_extension_whitelist",level:50,option:!0,input:!0,array:!0,value:e.values.downloads_extension_whitelist,
desc:d.getMessage("Only_files_with_these_extensions_can_be_saved_to_the_harddisk_Be_careful_to_not_allow_file_extensions_that_represent_executables_at_your_operating_system_"),validation:k})}v={name:d.getMessage("Experimental"),sub_menu_item:!0,level:80,items:[]};p.RUNTIME.FAST_EXEC_SUPPORT&&(k="fast"==e.values.runtime_inject_mode?{image:"critical",msg:"This might cause higher CPU usage!"}:{},v.items.push({name:d.getMessage("Inject_Mode"),id:"runtime_inject_mode",level:80,option:!0,select:[{name:d.getMessage("Default"),
value:"default"},{name:d.getMessage("Instant"),value:"instant"},{name:d.getMessage("Normal"),value:"normal"}],value:e.values.runtime_inject_mode,validation:k}));v.items.push({name:d.getMessage("strict_mode"),id:"runtime_strict_mode",level:80,option:!0,select:[{name:d.getMessage("Default"),value:"byscript"},{name:d.getMessage("Always"),value:"on"},{name:d.getMessage("Disabled"),value:"off"}],value:e.values.runtime_strict_mode});rea.webRequest.filterResponseData&&p.OPTIONS.HAS_CSP&&v.items.push({name:"Add Tampermonkey to the sites content CSP",
id:"webrequest_fixContentCSP",level:80,option:!0,select:[{name:d.getMessage("Yes"),value:"yes"},{name:d.getMessage("No"),value:"no"}],value:e.values.webrequest_fixContentCSP,warning:"Warning: enabling this option is may break pages!"});k={name:d.getMessage("Userscripts"),sub_menu_item:!0,level:80,items:[]};k.items.push({name:d.getMessage("Script_URL_detection"),id:"scriptUrlDetection",level:80,option:!0,select:[{name:d.getMessage("Auto"),value:"auto"},{name:d.getMessage("Disabled"),value:"manual"}],
value:e.values.scriptUrlDetection});k.items.push({name:d.getMessage("New_script_template_"),id:"script_templates",level:80,option:!0,input:!0,array:!0,named:!0,value:e.values.script_templates});t={name:d.getMessage("Reset_Section"),sub_menu_item:!0,level:50,items:[]};t.items.push({name:d.getMessage("Restart_Tampermonkey"),id:"reset_simple",level:50,button:!0,reload:!0,value:0,warning:d.getMessage("This_will_restart_Tampermonkey_Ok_")});t.items.push({name:d.getMessage("Factory_Reset"),id:"reset_factory",
level:80,button:!0,reload:!0,value:0,warning:d.getMessage("This_will_remove_all_scripts_and_reset_all_settings_Ok_")});sa&&t.items.push({name:"Install Tests",id:"install_tests",level:80,button:!0,reload:!1,ignore:!0,value:0,warning:"This will install a lot of test scripts!"});return[m,b,a,l,g,void 0,u,q,void 0,f,c,h,r,k,v,t].filter(function(a){return!!a})}}}(),T=function(){return{create:function(B,q){B=B||"";q=q||{};var f=function(b){return m.onebyone(b).fail(function(){n.warn("tree: wait failed!")}).then(function(a){return a.filter(function(a){return a})})},
g=function(b,a){for(var c=b.replace(/\.$/,"").split("."),d=l;c.length;){var e=c.shift();if(d[e]){if("function"===typeof d[e])return function(){return d[e](q,!a)};d=d[e];c.length||c.unshift("root")}else return n.warn("tree: unable to find",b,q),function(){return m.Pledge([])}}n.warn("tree: unable to find",b,q);return function(){return m.Pledge([])}},l={actions:{root:function(b){var a=m();rea.tabs.getSelected(null,function(c){c&&0<=c.id?q.tab=c:b.tabId&&(q.tab={id:b.tabId,url:null});c=f([g("actions.general"),
g("actions.scripts"),g("actions.commands")]);a.consume(c)});return a.promise()},general:function(){var b=q.tab,a=b?b.url:null,c=a&&4<a.length&&""==a.substr(0,4).replace(/file|http/,"")?a:"",h=[],b={name:"enabled",sub_menu_item:!0,pos:"top",items:[],tabId:b?b.id:null};b.items.push({name:d.getMessage("Enabled"),display:e.values.enabled?null:"greyed",id:"enabled",button:!0,reload:!0,enabler:!0});b.items=b.items.concat(O.actionStatus().map(function(a){return{options:a,globalhint:!0}}));h.push(b);var f;
!ja.isScriptUrl(a,!0)||(f=ja.isScriptUrl(a))&&"manual"!=e.values.scriptUrlDetection||b.items.push({name:f?d.getMessage("Install_this_script"):d.getMessage("Try_to_install_as_script"),image:"script_download",id:"installFromUrl",data:a,button:!0,reload:!0});a={name:"about",sub_menu_item:!0,pos:"bottom",items:[]};a.items.push({name:d.getMessage("Dashboard"),image:"utilities",url:rea.extension.getURL("options.html")+"#"+["url="+J.Base64.encode(c),"nav=dashboard"].join("&"),newtab:!0});c="version="+rea.extension.manifest.version+
"&ext="+rea.runtime.short_id;a.items.push({image:"about",id:"about",urls:[{name:" "+d.getMessage("Help"),url:"https://tampermonkey.net/faq.php?"+c,newtab:!0},{name:" "+d.getMessage("Changelog"),url:"https://tampermonkey.net/changelog.php?"+c,newtab:!0}]});h.push(a);return m.Pledge(h)},scripts:{root:function(b){var a=q.tab,c=a?a.url:null,h=[],f=c?z.parse(c):null,f=f&&-1!=["http:","https:","file:"].indexOf(f.protocol)?z.woHash(f):"",g,l={name:"scripts",sub_menu_item:!0,pos:"center",items:[]},n=X.getContexters(!0,
null),r={},p={},x={},B={};a&&[y.getUniqueScriptsForTab(a),y.getScriptHistoryForTab(a)].forEach(function(a,b){var c;Object.keys(a).forEach(function(e){var h=a[e];b?(r[e]=h.urls,p[e]=h.count,(c=x[e])||(h=A.getByUid(e),x[e]=h.script&&h.cond?c=h.script:c={uuid:e,name:d.getMessage("This_script_was_deleted"),enabled:!0,deleted:!0}),B[e]="a"+c.name.toLowerCase()+c.position):(x[e]=c=h.script,B[e]="z"+c.name.toLowerCase()+c.position)})});a="position"==e.values.action_menu_scripts_sort?function(a,b){return a.position-
b.position}:"name"==e.values.action_menu_scripts_sort?function(a,b){return a.name.toLowerCase()<b.name.toLowerCase()?-1:a.name.toLowerCase()>b.name.toLowerCase()?1:0}:"enabled"==e.values.action_menu_scripts_sort?function(a,b){return 1E4*(a.enabled?0:1)+a.position-(1E4*(b.enabled?0:1)+b.position)}:function(a,b){return B[a.uuid].localeCompare(B[b.uuid])};x=w.values(x).sort(a);a=ra([].concat(x).concat(n),{active_urls:r,active_counts:p});e.values.action_menu_scripts_hide_disabled&&(a=a.filter(function(a){return a.enabled||
p[a.uuid]}));!e.values.action_menu_scripts_hide_disabled&&2<Math.min(e.values.action_menu_columns,(b?b.available_columns:null)||99)?(g={name:"scripts_right",sub_menu_item:!0,pos:"right",items:[]},a.forEach(function(a){(a.enabled||p[a.uuid]?l:g).items.push(a)}),h.push(l),g.items.length&&h.push(g)):(g=l,l.items=l.items.concat(a),h.push(l));e.values.enabled&&!a.length&&c&&(U.isAllowed(c)?l.items.push({name:d.getMessage("No_script_is_running"),image:"no_script"}):l.items.push({name:d.getMessage("This_page_is_blacklisted_at_the_security_settings"),
image:"critical"}));b=d.getLocale();e.values.enabled&&("3"==e.values.action_menu_columns||100>e.values.configMode||!a.length)&&(a.length?(c={name:"scripts_new",sub_menu_item:!0,pos:"center",items:[]},h.push(c)):c=l,c.items.push({name:d.getMessage("Get_new_scripts___"),image:"script_search",url:"https://tampermonkey.net/scripts.php"+(b?"?locale="+b:""),newtab:!0}),c.items.push({name:d.getMessage("Add_new_script___"),image:"script_add",url:rea.extension.getURL("options.html")+"#url="+J.Base64.encode(f)+
"&nav=new-user-script",newtab:!0}));return m.Pledge(h)}},commands:function(){var b=q.tab,a=[],c=d.getLocale(),h={name:"commands",id:"commands",sub_menu_item:!0,pos:"left",items:[]},f;if(b){var g=b.id,b=[],g=null==g||void 0==g?ba.list():ba.listByTabId(g);for(f in g)if(g.hasOwnProperty(f)){var l=g[f];b.push({name:l.name,id:l.id,accessKey:l.accessKey,image:"menu_cmd",menucmd:!0})}f=b}else f=[];f.length&&(h.items=f);h.items.push({name:d.getMessage("Check_for_userscripts_updates"),id:"run_script_updates",
button:!0,image:"update"});80<=e.values.configMode&&h.items.push({name:d.getMessage("Report_a_bug"),image:"bug",url:"https://tampermonkey.net/bug",newtab:!0});h.items.push({name:d.getMessage("Please_consider_a_contribution"),image:"contrib",url:"https://tampermonkey.net/contrib.php?src=a"+(c?"&locale="+c:""),newtab:!0});a.push(h);return m.Pledge(a)}},options:{root:function(){return f([g("options.general"),g("options.verification"),g("options.scripts"),g("options.settings")])},general:function(){var b,
a=[];a.push({name:"Version",id:null,version:!0,value:rea.extension.manifest.version});rea.extension.inIncognitoContext&&"temporary"==e.values.incognito_mode?a.push({globalhint:!0,options:{image:"critical",text:d.getMessage("All_modifications_are_only_kept_until_this_incognito_session_is_closed_")}}):(b=O.optionsStatus().map(function(a){return{options:a,globalhint:!0}}))&&b.length?a=a.concat(b):(b=wa.updateAvailable())&&a.push({globalhint:!0,options:{image:"info",class:"information",text:d.getMessage("0name0_0version0_is_available__Please_re_start_your_browser_to_update_",
rea.extension.manifest.name,b)}});return m.Pledge(a)},verification:function(){var b=[];fa.getWarnings().forEach(function(a){b.push({globalhint:!0,options:{image:"critical",class:"warning",text:a.text,title:a.description,info_url:a.url}})});return m.Pledge(b)},scripts:{root:function(b,a){var c=m(),e={name:d.getMessage("Installed_userscripts"),main_menu_item:!0,scriptTab:!0,id:"dashboard"};(function(){if(b.complete||!a)return f(w.map(["options.scripts.natives","options.scripts.userscripts","options.scripts.new"],
function(a){return g(a)}));e.referrer="options.scripts";e.partial=!0;return f([g("options.scripts.new")])})().done(function(a){e.items=a;c.resolve([e])}).fail(c.reject);return c.promise()},"new":function(){var b=[];b.push({name:d.getMessage("New_userscript"),id:null,image:"script_add",icon:rea.extension.getURL("images/txt.png"),nnew:!0,uuid:"new-user-script",position:-1,positionof:p.RUNTIME.MAX_SCRIPTS,enabled:!0,userscript:!0});return m.Pledge(b)},natives:function(){var b=[],a=m();P.getAllUserscripts().always(function(c){c=
c||[];c.forEach(function(a){b.push({name:a.name,uuid:a.id,icon:a.icon,code:null,position:0,positionof:p.RUNTIME.MAX_SCRIPTS,enabled:a.enabled,version:a.version,description:a.description,nativeScript:!0})});a.resolve(b)});return a.promise()},userscripts:{root:function(b,a){var c=b.complete||!a?null:"options.scripts.userscripts",c=ra(y.determineScriptsToRun(null),{options_page:!0,referrer:c}),e=c.length,f=d.getLocale();c.push({name:d.getMessage("No_script_is_installed"),image:"info",visible:!e});c.push({name:d.getMessage("Get_some_scripts___"),
image:"edit_add",url:"https://tampermonkey.net/scripts.php"+(f?"?locale="+f:""),newtab:!0,visible:!e});return m.Pledge(c)},matches:function(b){if(!b.uuid)return m.Pledge([]);var a=A.getByUid(b.uuid),c;return a.script&&a.cond&&(c=b.filter)?(b=/\/(.*)\/(.*)/.exec(c.code),m.Pledge([-1!=a.script.textContent.search(new RegExp(b[1],b[2]))])):m.Pledge([])},source:function(b){if(!b.uuid)return m.Pledge([]);b=A.getByUid(b.uuid);if(b.script&&b.cond)return b=e.values.showFixedSrc?na.mkCompat(b.script.textContent,
b.script,"off"!=e.values.runtime_strict_mode):b.script.textContent,m.Pledge([b]);n.warn("tree: unable to process ",b);return m.Breach()},storage:function(b){return b.uuid?m.Pledge([A.getStorageByUid(b.uuid).data]):m.Pledge([])},external:function(b){if(!b.uuid)return m.Pledge([]);var a=A.getByUid(b.uuid);if(a.script&&a.cond){var c;[].concat(a.script.requires).concat(a.script.resources).some(function(a){a=a.url||z.sanitize(a.unsafe_url,a.abs_url);if(a==b.url&&(a=N.getElement(b.uuid,a))&&a.data&&a.data.content)return c=
a.data.content,!0});return m.Pledge([c])}n.warn("tree: unable to process ",a);return m.Breach()}}},settings:function(b,a){var c=m(),e={name:d.getMessage("Settings"),main_menu_item:!0,id:"settings",selected_default:!0},f;b.complete||!a?f=m.Pledge(Ha.create()):(e.referrer="options.settings",f=m.Pledge());f.done(function(a){e.items=a;c.resolve([e])}).fail(c.reject);return c.promise()}}};n.debug("tree: loading",B,q);return g(B,!0)()}}}(),ra=function(d,q){var f=[];q=q||{};var g=new E.Script;["author",
"copyright"].forEach(function(d){g[d]=!1});Object.keys(d).forEach(function(l){var b=d[l],a;if(q.options_page){a={};var c=["textContent","requires","resources"];Object.keys(g).forEach(function(d){-1==c.indexOf(d)&&(w.toType(g[d]),a[d]=b[d])});q.referrer?(a.referrer=q.referrer,a.length=b.textContent.length):a.code=b.textContent;["requires","resources"].forEach(function(c){a[c]=w.map(b[c],function(a){var d=a.url||z.sanitize(a.unsafe_url,a.abs_url),e=N.getElement(b.uuid,d),f=0,g=null,l=null,m,n,p,B;e&&
e.data&&(e.data.content&&(B=e.data.content,f=B.length),l=e.data.sri,g=e.ts,m=e.modified,p=e.data.meta||"text/plain",n="requires"==c||/text\/.*|application\/(?:x-)?(?:java|ecma)script/.test(p));return{display_url:a.url||a.unsafe_url,abs_url:a.abs_url,unsafe_url:a.unsafe_url,url:d,data:{length:f,content:q.externals?B:void 0},sri:l,ts:g,mimetype:p,editable:n,modified:m}})});a.origin=y.determineOrigin(b);a.contexter=y.isContexter(b);a.temp_connects=ea.getSessionConnects(b.uuid);l=A.getStorageByUid(b.uuid);
a.storage_key_count=Object.keys(l.data).length;a.remote_url=L.getSyncRemoteUrl(b);a.lastUpdated=b.lastUpdated}else l=y.determineOrigin(b),a={name:b.name,name_i18n:b.name_i18n,uuid:b.uuid,system:b.system,support:!!b.supportURL||l&&!!l.issue_url,abuse:l&&!!l.abuse_url,active_urls:(q.active_urls||{})[b.uuid],active_count:(q.active_counts||{})[b.uuid],referrer:q.referrer,contexter:y.isContexter(b),enabled:b.enabled,position:b.position,deleted:b.deleted};a.blacklisted=b.evilness>=e.values.script_blacklist_severity;
b.evilness&&(a.warnings=S.getWarningsFor(y.determineSourceURL(b)));a.file_url=b.downloadURL||b.fileURL;a.positionof=d.length;a.userscript=!0;b.icon64||b.icon||(a.icon64=rea.extension.getURL("images/txt.png"));b.options&&Object.keys(g.options).forEach(function(c){a[c]=b.options[c]});f.push(a)});return f},V={run:function(d,e){var f=1,g=function(){0==--f&&(e&&e(),rea.page.reload())};if("config"==d){var l=t.listValues();Object.keys(l).forEach(function(b){b=l[b];-1==b.search(p.CONSTANTS.PREFIX.SCRIPT)&&
-1==b.search(p.CONSTANTS.PREFIX.COND)&&-1==b.search(p.CONSTANTS.PREFIX.STORE)&&-1==b.search(p.CONSTANTS.PREFIX.META)&&(f++,t.deleteValue(b).always(g))})}else"factory"==d&&(f++,G.remove_permission().done(g),f++,t.factoryReset().always(g));g()},reset:function(d){V.run(null,d)},factoryReset:function(d){V.run("factory",d)},configReset:function(d){V.run("config",d)}},Q=function(){var m=function(){rea.runtime.lastError&&void 0},q={init:function(){q.setIcon();var d=e.values.appearance_badge_color||"#ee3131";
"#"!==d[0]&&(d="#"+d);rea.browserAction.setBadgeBackgroundColor({color:d})},setIcon:function(f){var g,l;l=null;var b=g=!1;void 0===f||C.get.empty(f)||(g=C.get.blocker(f),b=C.get.forbidden(f));b?(g="_forbidden",l=d.getMessage("At_least_one_part_of_this_page_is_listed_at_the_forbidden_pages_setting_")):g?(g="_blocker",l=d.getMessage("Some_scripts_might_be_blocked_by_the_javascript_settings_for_this_page_or_a_script_blocker_")):g=e.values.enabled&&void 0!==f?"":"_grey";n.debug("badge: set icon "+g);
g={path:rea.extension.getURL("images/icon"+g+".png")};l={title:l?l:rea.extension.manifest.name};null!=f&&(g.tabId=f,l.tabId=f);try{rea.browserAction.setIcon(g,m),rea.browserAction.setTitle(l)}catch(a){n.warn("bg: ERROR while setIcon! "+a.message)}},setBadge:function(d){var g=0;"off"==e.values.appearance_badges?g=0:"running"==e.values.appearance_badges?d&&!C.get.empty(d)&&(g=C.get.stats(d).running):"running_unique"==e.values.appearance_badges?d&&!C.get.empty(d)&&(g=C.get.stats(d,!0).unique):"disabled"==
e.values.appearance_badges&&d&&!C.get.empty(d)&&(g=C.get.stats(d).disabled);n.debug("badge: set "+g);g?rea.browserAction.setBadgeText({text:g.toString(),tabId:d}):rea.browserAction.setBadgeText({text:"",tabId:d})}};return q}(),aa=function(){var d=null,e={init:function(){d=t.getValue(p.CONSTANTS.STORAGE.BEGGING,null);var f,g=Date.now();d?(f=t.getValue(p.CONSTANTS.STORAGE.LAST_START,0))&&12096E5<g-f&&(d.later={type:"after_pause",ts:g},e.save()):(d={first_run:{type:"from_init",ts:g}},e.save())},save:function(){t.setValue(p.CONSTANTS.STORAGE.BEGGING,
d)},needed:function(){var e=Date.now(),g=d.first_run?d.first_run.ts+12096E5<e:!0,l=!d.hide,b=!d.contributed,e=d.later?d.later.ts+12096E5<e:!0;if(!p.RUNTIME.DOLPHIN&&g&&l&&b&&e)return d.later?"l":"i"},clicked:function(d,e,l){M.tG("clicked",d,e+l)},dialog:{shown:function(f){var g=Date.now();d.dialog={ts:g,extra:f};e.save();M.tG("dialog")}},button:function(){var f={};["contributed","later","hide"].forEach(function(g){f[g]=function(f,b){var a=Date.now();d[g]={ts:a,type:f,extra:b};e.save();M.tG("button",
g)}});return f}()};return e}(),ha=function(){var d=function(a,b){n.debug(a,b);if(b&&a.menuItemId){var c=A.getByUid(a.menuItemId);c&&c.script?Aa.bundle({url:a.frameUrl||a.pageUrl||"<unknown>"},c.script,!0).then(function(c){var d=m();c.method="executeScript";a.frameUrl?c.url=z.woHash(a.frameUrl):c.topframe=!0;rea.tabs.sendMessage(b.id,c,d.resolve);return d.promise()}):n.debug("ctxm: unable to find script "+a.menuItemId,a,b)}},e=[],f=null,g=!1,l=function(a){var b=[];w.each(a,function(a){var c=m();rea.contextMenus.create({id:a.uuid,
contexts:["all"],parentId:f,title:a.name,type:"normal",documentUrlPatterns:["http://*/*","https://*/*","file://*/*"]},function(){c.resolve()});e.push(a.uuid);b.push(c.promise())});return m.when(b)},b=function(){var a=m();rea.contextMenus.removeAll(function(){f=null;a.resolve()});return a.promise()},a=function(){var a=m();b().then(function(){f=rea.contextMenus.create({contexts:["all"],title:"Tampermonkey",type:"normal",documentUrlPatterns:["http://*/*","https://*/*","file://*/*"]},function(){a.resolve()})});
return a.promise()},c=function(){var c=X.getContexters(!0,null);if(c.length){var d;d=f?m.Pledge():a();return d.then(function(){return l(c)})}return b().then(h.clean)},h={init:function(){rea.contextMenus.supported&&(h.clean().then(c).then(function(){g=!0}),rea.contextMenus.onClicked.addListener(d))},clean:function(){var a=m();e.forEach(function(a){rea.contextMenus.remove(a)});e=[];a.resolve();return a.promise()},onScriptsChanged:function(){if(rea.contextMenus.supported&&g)return h.clean().then(c)},
getContexterCount:function(){return e.length}};return h}(),da=function(){var d={},m={},f=("TM_"+w.createUUID().substr(0,5)).toLowerCase(),g=["x-webkit-csp","x-content-security-policy","content-security-policy"],l=function(a,c){var b,d,e,f,h,g=a.split(";");g.forEach(function(a,b){0===a.search(/^\s*script-src /)?d=b:0===a.search(/^\s*default-src /)?e=b:0===a.search(/^\s*img-src /)&&(f=b)});var k,l;void 0!==e&&void 0===d&&(b=!0,g.push(g[e].replace(/default-src /,"script-src ")),d=g.length-1);void 0!==
e&&void 0===f&&(b=!0,g.push(g[e].replace(/default-src /,"img-src ")),f=g.length-1);void 0!==f&&(l=!1,k=g[f],-1==k.search(/'data:'/)&&(l=!0,k=k.replace(/img-src /,"img-src data: ")),-1!=k.search(/'none'/)&&(l=!0,k=k.replace(/ 'none'/,"")),l&&(g[f]=k,b=!0));void 0!==d&&(l=!1,k=g[d],-1==k.search(/'unsafe-eval'/)&&(l=!0,k=k.replace(/script-src /,"script-src 'unsafe-eval' ")),-1!=k.search(/'none'/)&&(l=!0,k=k.replace(/ 'none'/,"")),p.RUNTIME.FIREFOX&&(-1==k.search(/'unsafe-inline'/)&&(l=h=!0,k=k.replace(/script-src /,
"script-src 'unsafe-inline' ")),-1==k.search(/'strict-dynamic'/)&&-1!=k.search(/ '(nonce|sha[0-9]+)-[^\']+'/)&&(l=!0,k=k.replace(/ '(nonce|sha[0-9]+)-[^\']+'/g," *"))),l&&(g[d]=k,b=!0));void 0!==e&&(l=!1,k=g[e],h&&-1!=k.search(/ 'self'/)&&(l=!0,g[e]=k.replace(/default-src /,"default-src blob: data: ")),l&&(b=!0));return b?g.join(";"):null},b=function(a,b){var c,d,e=a.split(";");e.forEach(function(a,b){0===a.search(/^\s*sync-xhr /)&&(d=b)});var f,h;void 0!==d&&(h=!1,f=e[d],-1!=f.search(/'none'/)&&
(h=!0,f=f.replace(/ 'none'/," *")),h&&(e[d]=f,c=!0));return c?e.join(";"):null},a=function(a,b){var c,d=a.url;Object.keys(b).forEach(function(a){var e=b[a];w.each(e.rules,function(a,b){var f,h;if((f=a.selector)&&(h=a.action)){var g,k=e.id+"/"+b;(g=K.items.regexp.get(k))||(g=y.regexify({inc:f.include,match:f.match,exc:f.exclude}),K.items.regexp.set(k,g));if(y.validUrl(d,g)){h.cancel&&(n.debug("webRequest: request was canceled by script "+e.uuid,d,a,e),e.callback&&e.callback({type:"cancel",details:{rule:a,
url:d}}),c={cancel:!0});if(h.redirect){var l,r,m,q;h.redirect.url?l=h.redirect.url:h.redirect.regex&&(r=h.redirect.regex.from)&&(m=h.redirect.to)&&(q=d.match(r,m))&&(q.shift(),l=d,q.concat(["","",""]).forEach(function(a,b){l=l.replace("$"+b,a||"")}));f=function(b){n.warn("webRequest: error while request redirect by script "+e.uuid,d,a,e);e.callback&&e.callback({type:"redirect",message:"error",details:{description:b,rule:a,url:d,redirect_url:l}})};if(!l){f("unable to determine the redirect URL");return}l=
z.woHash(l);U.isAllowed(l)?y.scriptWillRun(e.uuid,l)?(n.debug("webRequest: request was redirected by script "+e.uuid,d,l,a,e),e.callback&&e.callback({type:"redirect",details:{rule:a,url:d,redirect_url:l}}),c={redirectUrl:l}):f("the redirect URL needs to be included by the scripts @include or @match tag"):f("the redirect URL is filtered by the security settings")}if(c)return!1}}})});return c},c=function(a){var b=[],c=a.requestHeaders||[],d,e,h={},g=new RegExp("^"+f),c=c.filter(function(c){if(c.name&&
0==c.name.search(g))e=c.name.replace(g,""),h[e.toLowerCase()]=!0,"internal"==e?m[a.requestId]=c.value:c.value&&b.push({name:e,value:J.decodeS(c.value)}),d=!0;else return!0});if(d)return{requestHeaders:c.filter(function(a){return!a.name||!h[a.name.toLowerCase()]}).concat(b)}},h=function(b){if(F.late)if("main_frame"==b.type){if(C.events.reset(b.tabId,!0),0<b.tabId&&"POST"!=b.method&&"auto"==e.values.scriptUrlDetection&&ja.isScriptUrl(b.url))return y.installFromUrl(b.url,{},{silent_fail:!0}).fail(function(a){n.info("webRequest: user script detected @ "+
b.url+" was invalid",a?a.messages:"");rea.tabs.update(b.tabId,{url:b.url+"#bypass=true"},function(){})}).done(function(){p.RUNTIME.EDGE&&rea.tabs.query({windowType:"normal"},function(a){a.forEach(function(a){a.id===b.tabId&&rea.tabs.update(a.id,{url:a.url},function(){})})})}),p.RUNTIME.EDGE?{cancel:!0}:{redirectUrl:"javascript:history.back()"}}else{var c,d;if((c=C.get.requests(b.tabId,b.frameId))&&(d=a(b,c)))return d}else F.registerLateCallback(function(){h(b)})},k=function(a,c){if(F.late){var f=
a.responseHeaders||[];if("xmlhttprequest"==a.type){var h,n,t;(h=m[a.requestId])&&delete m[a.requestId];(n=d[a.requestId])&&delete d[a.requestId];if(h&&(p.XMLHTTPREQUEST.COOKIE_PASSTHROUGH||f.forEach(function(a){a.name&&a.value&&-1!=a.name.toLowerCase().indexOf("set-cookie")&&(f.push({name:"tm-setcookie"+rea.runtime.short_id.toLowerCase(),value:a.value}),t=!0)}),n&&(f.push({name:"tm-finalurl"+rea.runtime.short_id.toLowerCase(),value:n}),t=!0),t))return{responseHeaders:f}}else{var u,v,w,y,A=p.OPTIONS.HAS_CSP&&
"yes"==e.values.webrequest_fixCSP,E=A&&p.RUNTIME.CHROME&&60<=p.RUNTIME.BROWSER_VERSION;f.some(function(a){if(a.name)return a=a.name.toLowerCase(),v|="location"==a,A&&(w|=-1!=g.indexOf(a)),E&&(y|="feature-policy"==a),v});if(!v){(h=C.events.response(a.tabId,a.frameId,a.url))&&(w||y)&&f.forEach(function(c,d){if(c.name&&c.value){var e=c.name.toLowerCase();if(-1!=g.indexOf(e)){var h;if(h=l(c.value,a))u=!0,f[d]={name:c.name,value:h}}"feature-policy"==e&&(e=b(c.value,a))&&(u=!0,f[d]={name:c.name,value:e})}});
var D;p.RUNTIME.FAST_EXEC_SUPPORT&&-1!=["instant"].indexOf(e.values.runtime_inject_mode)&&(D=C.events.run(a.tabId,a.frameId,null,a.url))&&(n=z.parse(a.url),n=n.pathname+n.search,n="TM_"+rea.runtime.short_id+J.Base64.encode(n.length+n).substr(0,255).replace(/[#=\/]/g,"_")+Date.now(),D=X.answer(D,a.url),D=JSON.stringify(D),D=new Blob([D],{type:"binary/octet-stream"}),D=URL.createObjectURL(D),C.set.objurl(a.tabId,a.frameId,D),f.push({name:"set-cookie",value:n+"="+window.encodeURIComponent(D)+"; max-age=15;"}),
u=!0);if(h&&!c&&rea.webRequest.filterResponseData&&p.OPTIONS.HAS_CSP&&"yes"==e.values.webrequest_fixCSP&&"yes"==e.values.webrequest_fixContentCSP&&-1!=["main_frame","sub_frame"].indexOf(a.type)){var I;f.some(function(a){if(a.name&&a.value&&"content-type"==a.name.toLowerCase()&&"text/html"==a.value.split(";")[0].toLowerCase().trim())return I=!0});if(I){var G=rea.webRequest.filterResponseData(a.requestId);G.ondata=function(b){var c=(new TextDecoder("x-user-defined")).decode(b.data,{stream:!0}),d=new RegExp('(<head>[\\s\\S]*)(<meta[^>]+http-equiv="(?:'+
g.join("|")+')"[^>]*>)([\\s\\S]*?<\\/head>)',"i"),e,c=c.replace(d,function(b,c,d,f){return c+d.replace(/(content=")([^">]+)(")/,function(b,c,d,f){if(b=l(d||"",a))e=!0;return c+(b||d)+f})+f});e?G.write(J.str2arrbuf(c)):G.write(b.data);G.disconnect();G=null};G.onstop=function(){G&&G.disconnect()}}}if(u)return p.RUNTIME.FIREFOX&&(f=f.filter(function(a){return"cache-control"!=a.name.toLowerCase()}),f.push({name:"cache-control",value:"no-cache, no-store, must-revalidate"})),{responseHeaders:f}}}}else F.registerLateCallback(function(){k(a,
!0)})},t=function(a){d[a.requestId]=a.redirectUrl},u=function(a){F.late?a.fromCache&&C.events.response(a.tabId,a.frameId,a.url):F.registerLateCallback(function(){u(a)})},A=function(a){C.events.reset(a.tabId,!0)};return{getPrefix:function(){return f},init:function(a){try{var b;b=p.RUNTIME.EDGE?["http://*/*","https://*/*"]:["http://*/*","https://*/*","ftp://*/*","file:///*"].concat(p.RUNTIME.WEBREQUEST_WEBSOCKET?["ws://*/*","wss://*/*"]:[]);a?(rea.webRequest.onBeforeRequest.addListener(h,{urls:b,types:["main_frame",
"sub_frame","script","xmlhttprequest"].concat(p.RUNTIME.WEBREQUEST_WEBSOCKET?["websocket"]:[])},["blocking"]),rea.webRequest.onHeadersReceived.addListener(k,{urls:b,types:["main_frame","sub_frame","xmlhttprequest"]},["blocking","responseHeaders"]),p.RUNTIME.WEBREQUEST_XHR_SUPPORT&&rea.webRequest.onBeforeRedirect.addListener(t,{urls:b,types:["xmlhttprequest"]},[]),rea.webRequest.onResponseStarted.addListener(u,{urls:b,types:["main_frame","sub_frame"]},[]),rea.webRequest.onErrorOccurred.addListener(A,
{urls:b,types:["main_frame"]})):p.RUNTIME.WEBREQUEST_XHR_SUPPORT&&"no"!=e.values.webrequest_modHeaders&&rea.webRequest.onBeforeSendHeaders.addListener(c,{urls:b,types:["xmlhttprequest"]},["blocking","requestHeaders"]);rea.webRequest.handlerBehaviorChanged()}catch(d){n.warn("webRequest: error initializings",d.message)}},scripts:{set:function(a,b,c,d,e){var f=[];d.forEach(function(a){var b="string"===typeof a.selector?{include:[a.selector]}:a.selector;["include","match","exclude"].forEach(function(b){"string"===
typeof a.selector[b]&&(a.selector[b]=[a.selector[b]])});var c=a.action;if("string"===typeof c){var d=c,c={};c[d]=!0}"string"===typeof a.action.redirect&&(a.action.redirect={url:a.action.redirect});f.push({selector:b,action:c})});C.set.requests(a,b,c,{id:c+"@"+a+":"+b+"#"+Date.now(),rules:f,uuid:c,callback:e})}}}}(),F={late:!1,callbacks:[],init:function(){},registerLateCallback:function(d){n.debug("toea: register callback");F.callbacks.push(d)},setReady:function(){n.debug("toea: run "+F.callbacks.length+
" callbacks");F.late=!0;for(var d=0;d<F.callbacks.length;d++)F.callbacks[d]();F.callbacks=[]}},Ia=function(){var d=!1,e=null,f=function(){d||(n.debug("Unloader.onbeforeunload()"),e&&e(),d=!0)};return{init:function(d){e=d;window.addEventListener("beforeunload",f,!1)}}}(),wa=function(){var w=null,q=rea.extension.manifest.version,f=null,g=!1,l=!1,b=function(){if(F.late){var a="version="+q+"&ext="+rea.runtime.short_id+"&updated=true",c;g?(c="https://tampermonkey.net/installed.php?"+a,l=!0):(a+="&old="+
f,c="https://tampermonkey.net/changelog.php?"+a);"off"!=e.values.notification_showUpdate&&("notification"==e.values.notification_showUpdate?R.showUpdate(d.getMessage("Updated_to__0version0",q),d.getMessage("Click_here_to_see_the_recent_changes"),rea.extension.getURL("images/icon128.png"),function(a){a.clicked&&rea.tabs.create({url:c},function(){})}):"changelog"==e.values.notification_showUpdate&&(l||(c+="&intr=true"),l=!0,rea.tabs.create({url:c,active:l},function(){})))}else F.registerLateCallback(b)},
a=function(){var a=null,b,c=m(),d=function(){b&&(b=null,c.resolve(!!a))};b=window.setTimeout(d,300);rea.idle.queryState(p.MISC.IDLE_TIMEOUT,function(b){a="active"==b;d()});return c.promise()},c=function(a){F.late?(n.debug("upd: onInstalled",a),a||(a={reason:"mandatory_argument_is_not_set"}),"chrome_update"==a.reason?M.tB({updated:!0}):"install"!=a.reason&&"update"!=a.reason||y.scheduleNotification(a.previousVersion,"install"==a.reason)):F.registerLateCallback(function(){c(a)})},h=function(){var a=
m(),b=function(){var b=Date.now(),c=t.getValue(p.CONSTANTS.STORAGE.LAST_START,0),b=Math.round((b-c)/1E3),c=b<=p.MISC.DISTURBANCE_ALLOWED;n.debug("upd: restart?",c,"(",b,"seconds ago)");a.resolve(c)};F.late?b():F.registerLateCallback(b);return a.promise()}(),k=function(){var c=!1,d=!1;a().then(function(a){d=a;return h}).then(function(a){c=a}).always(function(){l=!d||c;b();u=!0})},v=null,u=!1,y={scheduleNotification:function(a,b){u||(f=a,g|=b,v&&window.clearTimeout(v),v=window.setTimeout(k,1E3))},updateAvailable:function(){return w}};
rea.runtime.onInstalled.addListener(c);rea.runtime.onUpdateAvailable.addListener(function(a){n.info("An update to version",a.version,"is available");w=a.version;window.setTimeout(function(){R.show(d.getMessage("Update"),d.getMessage("0name0_0version0_is_available__Please_re_start_your_browser_to_update_",rea.extension.manifest.name,a.version),rea.extension.getURL("images/icon128.png"),6E4)},864E5)});(function(){F.registerLateCallback(function(){t.setValue(p.CONSTANTS.STORAGE.LAST_START,Date.now())})})();
return y}(),Ja=function(d){(function(){var n=m();"toggle-enable"==d?(e.values.enabled=!e.values.enabled,n.resolve()):rea.tabs.getSelected(null,function(e){var g;"open-dashboard"==d?g=rea.extension.getURL("options.html")+"#nav=dashboard":"open-dashboard-with-running-scripts"==d?g=rea.extension.getURL("options.html")+"#nav=dashboard&filter="+encodeURIComponent(e.url):"open-new-script"==d&&(g=rea.extension.getURL("options.html")+"#url="+J.Base64.encode(e.url)+"&nav=new-user-script");n.resolve(g?{url:g,
active:!0,parent:e}:null)});return n.promise()})().then(function(d){d&&rea.tabs.create(d)})},ta=function(){var d=[],m=function(a,b,f){F.late?("auto"==e.values.scriptUrlDetection&&ja.isScriptUrl(f.url)&&y.installFromUrl(f.url,{},{silent_fail:!0}),f.url?"loading"==b.status?C.events.loading(f.id,0,f.url):"complete"==b.status&&C.events.complete(f.id,0,f.url):n.warn("tabUpdates: no tab url set! ",f),d.forEach(function(a){a({reason:"updated",status:b.status},f)})):window.setTimeout(function(){m(a,b,f)},
100)},f=function(a,b){ca[a]&&(ca[a].onClose(),delete ca[a]);C.events.remove(a);d.forEach(function(b){b({reason:"removed"},{id:a})})},g=function(a,b){f(b,{});Q.setIcon(a);Q.setBadge(a);d.forEach(function(b){b({reason:"replaced"},a)})},l=function(a){F.late?(C.events.commited(a.tabId,a.frameId,a.url),0===a.frameId&&d.forEach(function(b){b({reason:"commited"},{url:a.url,id:a.tabId})})):window.setTimeout(function(){l(a)},100)},b={init:function(){rea.tabs.onUpdated.addListener(m);rea.tabs.onRemoved.addListener(f);
rea.tabs.onReplaced.addListener(g);rea.webNavigation.supported&&rea.webNavigation.onCommitted.addListener(l)},openAndWatch:function(a,c){var d=null,e=function(a,f){null!==d&&f.id===d&&(-1!=["updated","commited"].indexOf(a.reason)?c(f):"removed"==a.reason&&(b.removeListener(e),c()))};rea.tabs.create(a,function(a){d=a.id;c(a)});b.addListener(e);return{cancel:function(){b.removeListener(e);null!==d&&(rea.tabs.remove(d,function(){}),d=null)}}},addListener:function(a){d.push(a)},removeListener:function(a){var b;
d&&-1<(b=d.indexOf(a))&&d.splice(b,1)}};return b}(),Ba=function(){var d="temporary"==e.values.incognito_mode&&rea.extension.inIncognitoContext;t.setTemporary(d);d&&(e.values.native_import=!1,e.values.sync_enabled=!1,e.values.scriptUpdateCheckPeriod=0,e.values.sync_type=0,e.values.statistics_enabled=!1)},Ka=function(){n.set(e.values.logLevel);d.setLocale(e.values.i18n);P.setPath(e.values.native_import_path);ma=Registry.get("xmlhttprequest",p.RUNTIME.WEBREQUEST_XHR_SUPPORT&&"no"!=e.values.webrequest_modHeaders?
da.getPrefix():null,p.RUNTIME.FIREFOX);ka=ma.run;M.init("bg",rea.extension.manifest.version);M.setEnabled(e.values.statistics_enabled);C.listeners.add.onReset(function(d,e){ba.clearByTabId(d);A.removeStorageListeners({tabid:d},!1);e||Q.setIcon(d)});var m=function(d){rea.tabs.get(d,function(e){!rea.runtime.lastError&&e&&(Q.setIcon(d),Q.setBadge(d))})};C.listeners.add.onCommited(m);C.listeners.add.onCompleted(m);C.listeners.add.onCompleted(ea.purgeAppeals);C.listeners.add.onRemoved(ea.purgeAppeals);
C.listeners.add.onRemoved(ia.cleanTab);L.init().done(function(d){d&&L.sync()});U.init();S.init();A.init();m=function(){G.set_mode(e.values.downloads_mode);G.set_whitelist(e.values.downloads_extension_whitelist)};m();G.config_changed_listener=m;qa.init();da.init();ha.init();aa.init();Z.init()},ka,ma,na,E,D,sa;init=function(){F.init();da.init(!0);ta.init();xa.init();rea.commands.supported&&rea.commands.onCommand.addListener(Ja);Ia.init(function(){L.finalize()});na=Registry.get("compat",p);E=Registry.get("parser");
D=Registry.get("syncinfo",ta);sa=Registry.get("test");rea.browserAction.setIcon({path:rea.extension.getURL("images/icon_grey.png")});rea.browserAction.setPopup({popup:"action.html"});rea.browserAction.setTitle({title:"Tampermonkey"});t.init().then(function(){return Da()}).then(function(){return e.init()}).then(function(){cfgo=e;Ba();Ka();Ga();Q.init();window.setTimeout(Z.check,1E4);n.debug("Listeners registered!");window.setTimeout(F.setReady,1)})};init()}});
