'use strict';var trup,init,sycl,cfgo,uris,dast,perm,blak,scbr,scma,exts,down;
Registry.require("promise statistics convert xmlhttprequest downloads tools storage uri compat parser layout helper syncinfo notify asker i18n".split(" "),function(){var p=Registry.log,n=rea.FEATURES,ka=function(){var w=[],d=!0,e=function(d,w,b){var a={title:d.join("\n\n")};w.path=rea.extension.getURL("images/icon"+(w.frag?"_"+w.frag:"")+".png");p.warn(d.join("\n"));rea.browserAction.setIcon({path:w.path});rea.browserAction.setTitle(a);w=function(a,g,b){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]});b({items:[a],options:{enabled:!1}})};b||rea.extension.onMessage.addListener(w)};return{run:function(){try{Registry.verify("6095").length&&(d=!1,e(["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(w){d=!1,p.error(w.message)}if("chromeStorage"==n.DB.USE&&!n.DB.NO_WARNING){var f=
function(){if(!r)return window.setTimeout(f,2E3);r.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://www.tampermonkey.net/faq#Q206"},function(){});e(["Tampermonkey detected that the extension storage is unreliable!"],{frag:"paused"},!0)})};
window.setTimeout(f,1E3)}return d},pause:e,setWarning:function(d,e,b){w.push({text:d,description:e,url:b})},getWarnings:function(){return w}}}();if(ka.run()){var m=Registry.get("promise"),y=Registry.get("helper"),wa=Registry.get("tools"),M=Registry.get("statistics"),r=Registry.get("storage"),S=Registry.get("notify"),X=Registry.get("asker"),ea=Registry.get("permission"),P=Registry.get("layout"),B=Registry.get("uri"),d=Registry.get("i18n"),J=Registry.get("downloads"),K=wa.cache,H=Registry.get("convert");
uris=B;down=J;perm=ea;dast=r;var xa=y.createUUID(),fa={};p.debug("Starting background fred @"+xa);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 Fa=function(){var d=m(),h,e,f=rea.extension.manifest.version,q=r.getSchemaVersion(),b=q;r.getVersion("0.0.0.0").then(function(a){e=a;h=C.versionCmp(f,e)==C.versionCmp.eNEWER;return r.isWiped()}).then(function(a){!h&&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://www.tampermonkey.net/faq.php#Q207"],p.warn(a.join("\n")),ka.setWarning.apply(this,a))}).always(function(){var a=[],c=0,g=function(){if(c<a.length){var l=a[c].schema;a[c].cond(l)?a[c].fn().done(function(){l&&(p.log("Converted database from",b,"to",l),b=l);c++;
g()}).fail(function(){d.reject()}):(c++,g())}},l=function(){p.warn("Incognito mode detected. Database conversion can only be done in non-incognito mode! Stopping now...");ka.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 h&&!n.RUNTIME.FIREFOX&&!n.RUNTIME.EDGE&&"chromeStorage"==n.DB.USE&&!r.getValue(n.CONSTANTS.STORAGE.LEGACY_VERSION)&&
C.versionCmp("3.5.3603",e)==C.versionCmp.eNEWER},fn:function(){var a=m();rea.extension.inIncognitoContext?(l(),a.reject()):(p.log("Update database..."),b="3.5.3603",r.migrate("sql","chromeStorage").done(function(){p.log("Copied config for default usage of chrome storage");a.resolve()}).fail(function(){a.resolve()}));return a.promise()}},{cond:function(){return h&&C.versionCmp("3.6.3650",b)==C.versionCmp.eNEWER&&C.versionCmp("3.5.3650",e)==C.versionCmp.eNEWER},fn:function(){var a=m();if(rea.extension.inIncognitoContext)l(),
a.reject();else{b="3.6.3650";var c=[];[{o:"TM_config",n:n.CONSTANTS.STORAGE.CONFIG},{o:"TM_update_check",n:n.CONSTANTS.STORAGE.UPDATE},{o:"TM_version"},{o:"TM_unload_ts"}].forEach(function(a){if(a.n){var g=r.getValue(a.o);void 0!==g&&c.push(r.setValue(a.n,g))}c.push(r.deleteValue(a.o))});var g=/@re$/,d=[];r.listValues().forEach(function(a){-1!=a.search(g)&&(a=a.replace(g,""),d.push(a))});d.forEach(function(a){var g=r.getValue(a+"@st"),b=r.getValue(a),l=r.getValue(a+"@re"),x=r.getValue(a+"@source"),
d=A.getUidByName(a)||y.createUUID();c.push(r.deleteValue(a+"@st"));c.push(r.deleteValue(a));c.push(r.deleteValue(a+"@re"));c.push(r.deleteValue(a+"@source"));b&&l&&x?(c.push(r.setValue(n.CONSTANTS.PREFIX.SCRIPT_UID+d,a)),c.push(r.setValue(n.CONSTANTS.PREFIX.COND+d,l)),c.push(r.setValue(n.CONSTANTS.PREFIX.STORE+d,g)),c.push(r.setValue(n.CONSTANTS.PREFIX.SCRIPT+d,x)),c.push(r.setValue(n.CONSTANTS.PREFIX.META+d,b))):p.warn("invalid script entry",{source:x,meta:b,cond:l})});g=/@st$/;r.listValues().forEach(function(a){-1!=
a.search(g)&&c.push(r.deleteValue(a))});m.when(c).done(function(){p.log("Converted database from",e,"to",b);a.resolve()})}return a.promise()}},{schema:"3.7.0",cond:function(a){return C.versionCmp(a,b)==C.versionCmp.eNEWER},fn:function(){var a=m();if(rea.extension.inIncognitoContext)l(),a.reject();else{var c=[],g=new RegExp("^"+n.CONSTANTS.PREFIX.META);r.listValues().forEach(function(a){if(-1!=a.search(g)){var b=r.getValue(a);b.options&&b.options.override&&!b.options.override.orig_run_at&&(b.options.override.orig_run_at=
b.options.run_at||"document-idle",b.options.run_at=null,c.push(r.setValue(a,b)))}});m.when(c).done(function(){a.resolve()})}return a.promise()}},{schema:"4526",cond:function(a){return h&&n.RUNTIME.SAFARI&&"chromeStorage"==n.DB.USE&&C.versionCmp(a,b)==C.versionCmp.eNEWER},fn:function(){var a=m();if(rea.extension.inIncognitoContext)l(),a.reject();else{p.log("Update database...");var c=r.migrate("localStorage","chromeStorage").done(function(){p.log("Copied config for default usage of setting storage")}).fail(function(){a.resolve()});
a.consume(c)}return a.promise()}},{schema:"4871",cond:function(a){return h&&C.versionCmp(a,b)==C.versionCmp.eNEWER},fn:function(){var a=m(),c,g,b=r.getValue(n.CONSTANTS.STORAGE.CONFIG);b&&b.scriptTemplate&&(g=k.getDefaults())&&(c=g.script_templates)&&c[0]&&c[0].value&&(c[0].value=b.scriptTemplate,delete b.scriptTemplate,r.setValue(n.CONSTANTS.STORAGE.CONFIG,b));a.resolve();return a.promise()}},{schema:"5465",cond:function(a){return C.versionCmp(a,b)==C.versionCmp.eNEWER},fn:function(){var a=m();if(rea.extension.inIncognitoContext)l(),
a.reject();else{var c=r.getValue(n.CONSTANTS.STORAGE.CONFIG);c&&1==c.sync_version&&(c.sync_enabled=!1,r.setValue(n.CONSTANTS.STORAGE.CONFIG,c));a.resolve()}return a.promise()}},{cond:function(){return h||C.versionCmp(b,q)==C.versionCmp.eNEWER},fn:function(){var a=m();r.setVersion(f,b).done(function(){a.resolve()});return a.promise()}},{cond:function(){return h},fn:function(){p.log("First run of version "+f+"!");ga.scheduleNotification(e,"0.0.0.0"==e);return m.Pledge()}},{cond:function(){return!0},
fn:function(){var a=m();d.resolve();window.setTimeout(a.resolve,n.MISC.TIMEOUT);return a.promise()}}];g()});return d.promise()},Y=function(){return{get:function(d,h){var e=(0==d)+"#"+h,f=K.items.rundata.getj(e);if(f)f=f.oldret;else{var f=[],q=[],b=[],a={};if(h)for(var c=u.determineScriptsToRun(h,!0),g=0;g<c.length;g++){var l=c[g];u.isContexter(l)||0!=d&&(!0===l.options.noframes||null===l.options.noframes&&!0===l.options.override.orig_noframes)||(l.evilness&&l.evilness>=Math.min(I.SEVERITY_MAX,k.values.script_blacklist_severity)?
b.push(l):l.enabled?(a[l.uuid]=h,f.push(l)):q.push(l))}f={runners:f,disabled:q,evilness:b,script_map:a};h&&K.items.rundata.setj(e,{frameId:d,oldret:f})}return f},answer:function(d,h){var e=y.select(d,function(a){return a}),f=[{m:"native",t:[J.staticVars.DEFAULT,J.staticVars.NATIVE]},{m:"disabled",t:[J.staticVars.OFF]},{m:"browser",t:[J.staticVars.CHROME]}].filter(function(a){if(-1!=a.t.indexOf(k.values.downloads_mode))return!0}).map(function(a){return a.m})[0]||"disabled",q=rea.extension.inIncognitoContext,
b=!q&&"off"!=k.values.external_connect&&u.validUrl(h,za.externally_connectable_reg);return{scripts:e,contexters:ma.getContexterCount(),raw:{},external_connect:b,inIncognitoContext:q,downloadMode:f,enforce_strict_mode:"on"==k.values.runtime_strict_mode,statistics:M.isActive("api"),measure_scripts:k.values.debug,logLevel:k.values.logLevel,version:rea.extension.manifest.version}},getContexters:function(d,h){for(var e=[],f=u.determineScriptsToRun(h),k=0;k<f.length;k++){var b=f[k];b.enabled&&(0==d||!0!==
b.options.noframes&&(null!==b.options.noframes||!0!==b.options.override.orig_noframes))&&u.isContexter(b)&&e.push(b)}return e}}}(),D=function(){var d={},h=1,e=h++,f=h++,q=h++,b=h++,a=h++,c=h++,g=h++,l=function(){var a={frames:{0:{state:e}},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},x={updateStats:function(a,c,b,g){d[a].stats.running+=
b;d[a].stats.disabled+=g;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-=g});d[a].tabs.ts=Date.now()},updateMaps:function(a,c,b){var g=1,l=function(c,b){var l=1===g;void 0===d[a].maps[b]&&l&&(d[a].maps[b]={count:0,all_time:0,urls:[]});l&&(d[a].maps[b].urls.push(c),d[a].maps[b].all_time++);d[a].maps[b].count+=g};y.each(b,l);d[a].contexts.onUnload[c]=d[a].contexts.onUnload[c]||[];d[a].contexts.onUnload[c].push(function(){d[a]&&
(g=-1,y.each(b,l))})},updateUrls:function(a,c,b){var g=function(g){1===g&&(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+=g;d[a].urls.length=-1};g(1);d[a].contexts.onUnload[c]=d[a].contexts.onUnload[c]||[];d[a].contexts.onUnload[c].push(function(){d[a]&&g(-1)})},determine:function(a,c,b){var g;T.isAllowed(b)?g=Y.get(c,b):(p.debug("This URL is filtered by the security settings:",b,"-> Do nothing!"),D.set.forbidden(a,c),g={runners:[],disabled:[],
evilness:[],script_map:{}});d[a].scripts[b]=g;g.runners.forEach(function(b){b.webRequest&&ha.scripts.set(a,c,b.uuid,b.webRequest)});return g.runners.length},run:function(a,c,b,g,l){a=[];for(c=0;c<g.length;c++)a.push(Da.bundle({url:b},g[c]));var d;m.when(a).always(function(a){l?l(a):d=a});return d}},t={},z={},E={},Q={},v={listeners:{once:{whenReady:function(a,c){if(!d[a]||d[a].frames[0].state<q)v.listeners.once.onReady(a,c);else c()},onReady:function(a,c){var b=function(a){v.listeners.remove.onCommited(g);
v.listeners.remove.onCompleted(l);a&&c()},g=v.listeners.add.onCommited(function(c){c===a&&b(!0)}),l=v.listeners.add.onCompleted(function(c){c===a&&b(!0)})}},add:{onReset:function(a){var c=y.createUUID();t[c]=a;return c},onCommited:function(a){var c=y.createUUID();z[c]=a;return c},onCompleted:function(a){var c=y.createUUID();E[c]=a;return c},onRemoved:function(a){var c=y.createUUID();Q[c]=a;return c}},remove:function(){return{onReset:function(a){delete t[a]},onCommited:function(a){delete z[a]},onCompleted:function(a){delete E[a]},
onRemoved:function(a){delete Q[a]}}}()},events:{reset:function(a,c){var b;n.RUNTIME.FAST_EXEC_SUPPORT&&(b=d[a])&&Object.keys(b.frames).forEach(function(c){v.events.clean(a,c)});b=d[a]=l();b.frames[0].state=e;y.each(t,function(b){b&&b(a,c)})},response:function(a,c,b){if(k.values.enabled){var g=d[a]=d[a]||l(),t=g.frames[c]=g.frames[c]||{},z=t.state||e;0===c&&(g.tabs.response_ts=Date.now());b=B.woHash(b);z<f&&(x.determine(a,c,b),t.state=f);return(a=g.scripts[b])?a.runners.length:0}},commited:function(a,
c,b){if(k.values.enabled){var g=B.parse(b);if("http:"===g.protocol||"https:"===g.protocol||"file:"===g.protocol){var g=d[a]=d[a]||l(),g=g.frames[c]=g.frames[c]||{},t=g.state||e;t>=q||(g.state=q,t<f&&(b=B.woHash(b),x.determine(a,c,b)),y.each(z,function(c){c&&c(a)}))}}},loading:function(a,c,g){if(k.values.enabled){var t=B.parse(g);if(("http:"===t.protocol||"https:"===t.protocol||"file:"===t.protocol)&&0===c&&"file:"===t.protocol){t=d[a]=d[a]||l();t.frames[c]=t.frames[c]||{};var z=t.frames[c].state||
e;z>=b||(t.frames[c].state=b,z<f&&(g=B.woHash(g),x.determine(a,c,g)))}}},run:function(c,b,g,t,e){if(k.values.enabled){var z=0===b||n.RUNTIME.FAST_EXEC_SUPPORT?b:g,f=d[c]=d[c]||l();f.frames[z]=f.frames[z]||{};var Q=B.woHash(t),h=f.scripts[Q];if(!h&&(p.debug("tv: lazy init @ events.run("+c+", "+b+", "+g+", "+t+")"),x.determine(c,b,Q),h=f.scripts[Q],!h)){p.warn("tv: no script run info for tab "+c+" @ "+Q,p.D?f.scripts:"");return}g=f.frames[z].state;f.frames[z].state=a;g!=a&&(x.updateMaps(c,z,h.script_map),
x.updateUrls(c,z,Q),x.updateStats(c,z,h.runners.length,h.disabled.length));return x.run(c,b,Q,h.runners,e?function(a){v.events.clean(c,z,t);e(a)}:null)}},clean:function(a,c,b){if(k.values.enabled){var g,l;if(g=d[a])b&&(b=B.woHash(b),delete g.scripts[b]),(l=D.get.objurl(a,c))&&URL.revokeObjectURL(l)}},complete:function(b,g,t){t=B.parse(t);if(k.values.enabled&&("http:"===t.protocol||"https:"===t.protocol||"file:"===t.protocol)){if(0===g){var z=d[b]=d[b]||l();z.frames[g]=z.frames[g]||{};var x=z.frames[g].state||
e;z.frames[g].state=c;if(!D.get.empty(b)&&D.get.stats(b).running){if(x<a){p.warn("tv: no script run info!");return}"file:"===t.protocol?window.setTimeout(function(){rea.tabs.sendMessage(b,{method:"onLoad",frameId:g},function(){})},500):rea.tabs.sendMessage(b,{method:"onLoad",frameId:g},function(){})}}y.each(E,function(a){a&&a(b)})}},unload:function(a,c,b){b=0===c||n.RUNTIME.FAST_EXEC_SUPPORT?c:b;n.RUNTIME.FAST_EXEC_SUPPORT&&v.events.clean(a,c);a=d[a]=d[a]||l();a.frames[b]=a.frames[b]||{};a.frames[b].state=
g;if(a.contexts.onUnload[b]){for(c=0;c<a.contexts.onUnload[b].length;c++)a.contexts.onUnload[b][c]();a.contexts.onUnload[b]=[]}delete a.frames[b]},remove:function(a){var c;n.RUNTIME.FAST_EXEC_SUPPORT&&(c=d[a])&&Object.keys(c.frames).forEach(function(c){v.events.clean(a,c)});delete d[a];y.each(Q,function(c){c&&c(a)})}},set:{extra:function(a,c,b,g){a=d[a]=d[a]||l();null===c?a.extra[b]=g:(a.extra[b]=a.extra[b]||{},a.extra[b][c]=g)},objurl:function(a,c,b){v.set.extra(a,c,"objurl",b)},blocker:function(a){v.set.extra(a,
null,"blocker",!0)},forbidden:function(a,c){0===c&&v.set.extra(a,null,"forbidden",!0)},requests:function(a,c,b,g){a=d[a]=d[a]||l();c=a.frames[c]=a.frames[c]||{};(c.requests=c.requests||{})[b]=g}},get:{extra:function(a,c,b,g,l){void 0===g&&(g=null);a=(d[a]?d[a].extra:{})[b];null!==c&&a&&l&&delete a[c];return a||g},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,y.each(d[a].urls,function(c,b){"length"!==b&&0<c.count&&d[a].urls.length++}),v.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={};y.each(d,function(c,b){a[b]={ts:c.response_ts}});return a},objurl:function(a,c){return v.get.extra(a,c,"objurl",null,!0)},blocker:function(a){return v.get.extra(a,
null,"blocker")},forbidden:function(a){return v.get.extra(a,null,"forbidden")},requests:function(a,c){return d[a]&&d[a].frames[c]?d[a].frames[c].requests:null}}};return v}(),na=function(){var d={};return{get:function(h,e){d[h]||(d[h]={});d[h][e]||(d[h][e]={});return d[h][e]},getAll:function(h){var e={};Object.keys(d).forEach(function(f){e[f]={};e[f]=d[f][h]});return e},set:function(h,e,f){d[h]||(d[h]={});var k={};f&&Object.keys(f).forEach(function(b){k[b]=f[b]});d[h][e]=k},cleanTab:function(h){delete d[h]}}}(),
oa=function(){return{isScriptUrl:function(d,h){if(!d||-1!=d.search(/\#bypass=true/)||-1!=d.search(n.REQUESTS.GET_INTERNAL_PAGE_REGEXP())||"data:"===d.substr(0,5))return!1;var e=h?d:d.split(/[\?#$]/)[0],f=-1!=e.search(/.+\.user\.(js\#|js\?|js$)/)||-1!=e.search(/.+\.tamper\.(js\#|js\?|js$)/);return f?!(-1!=e.search(/^htt[ps]{1,2}:\/\/code\.google\.com/)||-1!=e.search(/^htt[ps]{1,2}:\/\/(github|gitlab)\.com/)&&!u.determineOriginOfUrl(e)||-1!=e.search(/^htt[ps]{1,2}:\/\/bitbucket\.org/)&&!u.determineOriginOfUrl(e)):
f}}}(),T=function(){return{init:function(){var d=function(){K.items.regexp.remove("PageFilter")};k.addChangeListener("forbiddenPages",d);k.addChangeListener("page_whitelist",d);k.addChangeListener("page_filter_mode",d)},isAllowed:function(d){var h=!1,e=!1,f=L.getSyncRemoteDomains().map(function(a){return"*://"+a+"/*"}),f=k.values.forbiddenPages.concat(f),q=0<f.length,b=0<k.values.page_whitelist.length;switch(k.values.page_filter_mode){case "black":e=q;break;case "off":break;case "white":h=b;break;
default:h=b,e=q}(q=K.items.regexp.get("PageFilter"))||(q=u.regexify({inc:h?k.values.page_whitelist:void 0,exc:e?f:void 0}),K.items.regexp.set("PageFilter",q));return!e&&!h||u.validUrl(d,q)}}}(),I=function(){var w=function(d,f){var h=!1;if(f.length)return(h="/"==f.substr(0,1)?u.matchUrl(d,u.convertToRegExp(f)):-1!=d.search(f))&&p.debug('black: entry "'+f+'" matched'),h},h={SEVERITY_MAX:10,SEVERITY_MANUALLY_DEFINED:11,SEVERITY_FOISTED_SCRIPT:12,init:function(){var d=m(),f=function(){"server"===k.values.script_blacklist_type&&
window.setTimeout(h.checkUpdate,2E4)};f();k.addChangeListener("script_blacklist_type",f);d.resolve();return d.promise()},getWarningsFor:function(e){var f=[];e&&y.each(k.values.script_blacklist_server,function(h){if(h){var b;y.each(h.rules,function(a){b|=w(e,a);return 1!=b});if(b)if(h.reasons){var a=Object.keys(h.reasons),c,g;void 0!==(c=d.getBestLocale(a))&&(g=a[c]);f.push(h.reasons[g||"en"])}else h.reason&&f.push(h.reason)}});return f},getEvilnessOf:function(d){if("off"===k.values.script_blacklist_type)return!1;
if(!d)return 0;var f=!1,q=0;y.each(k.values.require_blacklist,function(b){f|=w(d,b);return 1!=f});f?q=h.SEVERITY_MANUALLY_DEFINED:"server"===k.values.script_blacklist_type&&y.each(k.values.script_blacklist_server,function(b){if(b&&(y.each(b.rules,function(a){f|=w(d,a);return 1!=f}),f))return q=b.severity,!1});return Number(q)},checkUpdate:function(d){var f=m(),h=Z.getConfig(),b;if(d||6048E5<Date.now()-h.black.last){var a=function(a,b){var d=m();aa.internal({method:"GET",url:a,nocache:b,retries:n.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(g){p.warn("black: unable to parse version response! "+c.responseText)}p.info("black: local version: "+h.black.version+" remote: "+b);if(b>h.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&&(k.values.script_blacklist_server=b.blacklist);p.info("black: updated blacklist to ",b)}catch(d){p.warn("black: blacklist update failed! ",a.responseText)}}).always(function(){h=Z.getConfig();h.black.last=Date.now();h.black.version=b||h.black.version;Z.setConfig(h);f.resolve()})}else f.resolve();return f.promise()}};return h}();blak=I;var Ia=function(d){d([])},L=function(){var w=0,h=[],e={to:null,force:null,
t:0},f={},q=wa.createQueue(1),b={},a=function(a){return q.add(function(){p.debug("sync: import",a.uuid,a.name,a.url);var c={imported:k.values.sync_type},b={},g;for(g in E.SYNCED)!0===E.SYNCED[g]&&(b[g]=a.options[g]);var d={uuid:a.uuid,ask:!1,internal:!0,sync:c,force_meta:{lastModified:a.lastModified,fileURL:a.url},force_options:b},l={silent_fail:!0};return F.caps.syncsSource?F.getSource(a.uuid).then(function(a){return u.installFromSource(a,d,l)}):u.installFromUrl(a.url,d,l)})},c=function(a,c){return q.add(function(){if(!F.caps.syncsSource){var b;
if(!a.url||!(b=B.parse(a.url))||!b.protocol.match(/https?:/))return p.debug("sync: skip export due to missing URL",a.name,a.url),m.Pledge(!1)}p.debug("sync: export",a.name,a.url);return F.setMeta(a,{lastModified:a.lastModified}).then(function(){if(F.setSource&&c)return F.setSource(a.uuid,c)}).then(function(){return!0})})},g=function(a){var c=a.downloadURL?a.downloadURL.split("#")[0]:null,b=a.fileURL?a.fileURL.split("#")[0]:null,g=y.select([b,c],function(a){if(!a||"file:"!==B.parse(a).protocol)return a})[0],
c={uuid:a.uuid,name:a.name,options:{},durl:c,furl:b,url:g,lastModified:a.lastModified||a.lastUpdated},d;for(d in E.SYNCED)!0===E.SYNCED[d]&&null!==a.options[d]&&(c.options[d]=a.options[d]);return c},l=function(){var a=[];A.getUidList().forEach(function(c){c=A.getByUid(c);if(c.script&&c.cond){var b=g(c.script);b.lastModified||Registry.isDevVersion("test")?c.script.evilness&&c.script.evilness>=Math.min(I.SEVERITY_MAX,k.values.script_blacklist_severity)?p.warn("sync: ignore evil script",c.script):a.push(b):
p.warn("sync: script without updated/modified timestamps found",c.script)}});return a},x=function(g){if(E.enabled)if(0<w)g&&E.addSyncDoneCallback(function(a){a&&E.sync(50,g)});else{w++;var t=null,z=null,x=0,e=0,q=!0,n=function(a){if(a)for(var c=0;c<z.length;c++)if(z[c].uuid==a)return z[c];return null},r=function(a){if(!a)return null;for(var c=0;c<t.length;c++)if(t[c].uuid==a)return t[c]},Ga=function(a,c,b){return b?Math.floor(a/b)*b>Math.floor(c/b)*b:a>c},Ba=function(a,c,b){return b?Math.floor(a/
b)*b<Math.floor(c/b)*b:a<c},Ha=function(a,c,b){return b?Math.floor(a/b)*b!=Math.floor(c/b)*b:a!=c};N.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(){t=l();return F.list().done(function(a){z=a}).fail(function(){p.warn("sync: unable to get remotelist!")})}).then(function(){var c=z.map(function(c){var g,l=r(c.uuid),t,z;if(l){if(!c.lastModified&&k.values.sync_type==F.types.eCHROMESYNC)for(var e in E.SYNCED)if(!0===
E.SYNCED[e]&&l.options[e]!=c.options[e]){p.debug("sync: importable change detected!",c.name,"key:",e,c);t=!0;break}c.lastModified&&Ba(l.lastModified,c.lastModified,c.precision)&&(z=c.lastModified,t=!0,p.debug("sync: importable change detected!",c.name,"local ts:",new Date(l.lastModified),"remote ts:",new Date(c.lastModified),c))}else(g=b[c.uuid])&&c.lastModified&&Ba(g.lastModified,c.lastModified,c.precision)&&(z=c.lastModified,t=!0,p.debug("sync: changed cache entry detected!",c.name,"local ts:",
new Date(g.lastModified),"remote ts:",new Date(c.lastModified),c));if(!l&&!g||t)return function(){return m.Pledge().then(function(){return F.caps.specialMeta?F.getMeta(c.uuid):m.Pledge(c)}).then(function(c){if(c){var e;if(l)if(c.options.removed)x++,p.debug("sync: remove local script",c.uuid,c.name,c.url),u.doRemove(l.uuid,!1);else{if(t){Ha(z,c.lastModified,c.precision)&&(c.lastModified&&p.warn("sync: list and meta data lastModified differ, this will cause extra traffic!","file ts:",new Date(z),"meta ts:",
new Date(c.lastModified),c),c.lastModified=z);x++;p.debug("sync: update local script",c.uuid,c.name,c.url);var v=A.getByUid(l.uuid);if(v.script&&v.cond){for(e in E.SYNCED)!0===E.SYNCED[e]&&(v.script.options[e]=c.options[e]);v.script.lastModified=c.lastModified;return m.Pledge().then(function(){if(F.caps.syncsSource){var a=m();F.getSource(c.uuid,v.script.textContent).done(function(a){v.script.textContent=a}).fail(function(){p.warn("sync: getting source of",c.uuid,"failed",c)}).always(a.resolve);return a.promise()}}).then(function(){return u.doModify(v.script.uuid,
v.script,!1)})}p.warn(d.getMessage("fatal_error")+"("+l.name+")!!!")}}else if(l||c.options.removed)!g&&c.options.removed&&(b[c.uuid]=c);else if(e=m(),c.url&&f[c.url]||c.uuid&&f[c.uuid])p.warn("sync: skip previously failed import",c);else return a(c).done(function(a){a?x++:(p.warn("sync: unable to import",c),f[c.url]=!0,f[c.uuid]=!0)}).fail(function(){p.warn("sync: unable to load",c);f[c.url]=!0;f[c.uuid]=!0}).always(e.resolve),e.promise()}})}}).filter(function(a){return a});return m.onebyone(c)}).then(function(){x&&
(u.reorderScripts(),N.all("status",{key:"sync",class:"information",title:d.getMessage("Script_Sync"),text:d.getMessage("0count0_changes_imported",x),timeout:1E4}));t=l();return m.Pledge()}).then(function(){for(var a=[],b=0;b<t.length;b++)a.push(function(){var a=t[b],g,d;if(!F.caps.syncsSource&&!a.url)return m.Pledge();var l=n(a.uuid);if(l){if(!l.lastModified||Ga(a.lastModified,l.lastModified,l.precision))g=!0,p.debug("sync: exportable change detected!",a.name,"remote ts:",new Date(l.lastModified),
"local ts:",new Date(a.lastModified),a)}else p.debug("sync: export because remotely missing!",a.name,"local ts:",new Date(a.lastModified),a);return!l||g||F.caps.syncsSource&&!l.source?(F.caps.syncsSource&&(g=A.getByUid(a.uuid),g.script&&g.cond&&(d=g.script.textContent)),c(a,d).then(function(a){a&&e++})):m.Pledge()}());return m.when(a)}).fail(function(){q=!1}).done(function(){q=!0}).always(function(){p.debug("sync: finished");if(0==--w){N.all("status",{key:"sync_status",class:"information",title:d.getMessage("Script_Sync"),
text:d.getMessage("Sync_finished"),timeout:15E3});e&&N.all("status",{key:"sync",class:"information",title:d.getMessage("Script_Sync"),text:d.getMessage("0count0_changes_exported",e),timeout:5E3});for(var a=q;h.length;)h.shift()(a)}})}},t=function(){E.enabled&&E.sync(500,!0)},z=null,E={enabled:!1,SYNCED:{comment:!0},configChangeListener:function(){z||(z=window.setTimeout(function(){z=null;E.init().done(function(){E.enabled&&E.sync(3E3)})},3E3))},init:function(){var a=m();E.enabled=!1;(function(){if(k.values.sync_enabled&&
k.values.sync_type){var a;k.values.sync_type==F.types.eWEBDAV&&(a={url:k.values.cloud_url,basic_auth:H.Base64.encode(k.values.cloud_user+":"+k.values.cloud_pass)});return F.init(k.values.sync_type,a).done(function(a){E.enabled=a;E.enabled?F.addChangeListener(t):p.warn("sync: init failed!")}).fail(function(){p.warn("sync: init failed!")})}return m.Pledge()})().always(function(){a.resolve(E.enabled)});return a.promise()},finalize:function(){},reset:function(){return E.enabled?F.reset():m.Breach()},
addSyncDoneCallback:function(a){h.push(a)},sync:function(a,c){var b=Date.now();a=a||500;c=e.force||c;e.to?(window.clearTimeout(e.to),e.ts<b+a&&(a=e.ts-b,1>a&&(a=1))):p.debug("sync: schedule sync for run in "+a+" ms");e.force=c;e.ts=b+a;e.to=window.setTimeout(function(){x(e.force);e.to=null;e.force=null},a)},scriptAddedCb:function(a,b){if(E.enabled){var d=g(b);c(d,b.textContent)}},scriptChangedCb:function(){E.enabled&&E.sync(6E4)},scriptRemovedCb:function(a,c){if(E.enabled){var b=g(c);p.debug("sync: remove",
b.name,b.url);F.remove(b)}},getSyncRemoteUrl:function(a){if(E.enabled)return F.getRemoteUrl(a)},getSyncRemoteDomains:function(){return F.getRemoteDomains()||[]}};return E}();sycl=L;var Ja=function(){k.addChangeListener(["sync_enabled","sync_type","cloud_url","cloud_user","cloud_pass"],L.configChangeListener);k.addChangeListener("logLevel",function(){p.set(k.values.logLevel)});k.addChangeListener("i18n",function(){d.setLocale(k.values.i18n)});k.addChangeListener("incognito_mode",function(){Ea()});
k.addChangeListener("statistics_enabled",function(){M.setEnabled(k.values.statistics_enabled,!0)});k.addChangeListener(["require_blacklist","script_blacklist_server","script_blacklist_type"],u.blackCheckAll);k.addChangeListener(["downloads_extension_whitelist","downloads_mode"],J.config_changed_listener);k.addChangeListener("webrequest_modHeaders",function(d,h,e,f){f.done(window.setTimeout(V.reset,1))})},k=function(){var d={},h={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:n.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:"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",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:!n.RUNTIME.FIREFOX&&!n.RUNTIME.SAFARI||
"firb"==rea.runtime.short_id?!0:null,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(" ")},e={cloud_url:null,cloud_user:null,cloud_pass:null},f=function(a){var c;return void 0!==(c=r.getValue(n.CONSTANTS.STORAGE.CONFIG,
{})[a])?c:"function"==typeof(c=h[a])?c():c},k=function(a,c){var b=r.getValue(n.CONSTANTS.STORAGE.CONFIG,{}),g=f(a);b[a]=c;var l=r.setValue(n.CONSTANTS.STORAGE.CONFIG,b);d[a]&&JSON.stringify(g)!=JSON.stringify(c)&&d[a].forEach(function(b){try{b(a,g,c,l)}catch(d){p.warn("config: changeListener error",d)}});return l},b,a;if(n.HTML5.LOCALSTORAGE&&(a=n.HTML5.LOCALSTORAGE.getItem(n.CONSTANTS.STORAGE.SESSION)))try{b=JSON.parse(H.Base64.decode(a))}catch(x){}b=b||{};var c=function(a){var c;return void 0!==
(c=b[a])?c:e[a]},g=function(a,g){var l=c(a);void 0===g?delete b[a]:b[a]=g;n.HTML5.LOCALSTORAGE&&n.HTML5.LOCALSTORAGE.setItem(n.CONSTANTS.STORAGE.SESSION,H.Base64.encode(JSON.stringify(b)));d[a]&&JSON.stringify(l)!=JSON.stringify(g)&&d[a].forEach(function(c){try{c(a,l,g)}catch(b){p.warn("config: changeListener error",b)}});return m.Pledge()},l={init:function(){var a=m();l.values={};Object.defineProperty(l,"snapshot",{get:function(){return y.assign({},l.values)},enumerable:!0});Object.keys(h).forEach(function(a){Object.defineProperty(l.values,
a,{get:function(){return f(a)},set:function(c){k(a,c)},enumerable:!0})});Object.keys(e).forEach(function(a){Object.defineProperty(l.values,a,{get:function(){return c(a)},set:function(c){g(a,c)},enumerable:!0})});l.initialized=!0;Ia(function(c){Object.keys(c).forEach(function(a){var b=c[a];window.setTimeout(function(){u.doSave({url:null,src:b,ask:!1,replace:!0,internal:!0})},1)});a.resolve()});return a.promise()},getValue:function(a){return e.hasOwnProperty(a)?c(a):f(a)},setValue:function(a,c){return e.hasOwnProperty(a)?
g(a,c):k(a,c)},getDefaults:function(){return h},addChangeListener:function(a,c){Array.isArray(a)||(a=[a]);a.forEach(function(a){d[a]||(d[a]=[]);d[a].push(c)})}};return l}(),aa=function(){var k,h,e=[],f,q,b,a=function(){return m.sleep(1).then(function(){return rea.permissions.supported?ea.has(n.PERMISSIONS.ALL_URLS).then(function(a){return a},function(){return!0}):!0}).always(function(a){(h=a)?N.removeAll("runtime_host_permissions"):N.all("status",{key:"runtime_host_permissions",class:"warning",text:d.getMessage("Limited_runtime_host_permissions_might_break_some_Tampermonkey_features_"),
timeout:31536E6});f=null})},c=function(c,l,x){var t={details:c,callbacks:l,internal:x};e.push(t);m.Pledge().then(function(){if(void 0===h)return b||(ea.addListener(function(c){p.log("pcx: detected permission change",c);h=void 0;f=a()}),b=!0),f||(f=a()),f}).then(function(){return q}).then(function(){var a=e;e=[];if(h)return a;var c=[],b=a.map(function(a){var b=B.woPath(a.details.url)+"/*";return ea.hasOrigin(b).then(function(a){a||c.push(b)})});return q=m.sidebyside(b).then(function(){return c.length?
(p.log("pcx: need to ask for some permissions",c),ea.askOrigin(c,d.getMessage("Cross_Origin_Request_Permission"),d.getMessage("Click_here_to_allow_TM_to_access_the_following_hosts_0host_list0",c.join("\n"))).then(function(){q=null;return a})):a}).always(function(){q=null})}).always(function(a){a.forEach(function(a){a.aborted||(a.xhr=k(a.details,a.callbacks,a.internal?{internal:!0}:void 0))})});return{abort:function(){var a;if(t.xhr)return t.xhr.abort();e&&-1!=(a=e.indexOf(t))?e.splice(a,1):t.aborted=
!0}}};return{init:function(){k=W.run},internal:function(a,b){return c(a,b,!0)},external:function(a,b){return c(a,b)}}}(),pa=function(){var d=m();rea.tabs.getSelected(null,function(h){d.resolve(h)});return d.promise()},ia=function(){var d={},h=function(a){if(B.isIpOrHostname(a))return null;var c=a.split(".");if(3>c.length)return a;a=B.isSecondLevelDomain(c.slice(-2).join("."))?-3:-2;return c.slice(a).join(".")},e=function(a){return a&&-1!=a.indexOf("*")},f=function(a){var c=m();T.isAllowed(a)?c.resolve({allowed:!0}):
c.resolve({allowed:!1});return c.promise()},q=function(a,c){var b=function(a){return a?a.map(function(a){if(a.match(/^'?self'?$/))a=B.parse(c.url).hostname||null;else if("'none'"==a)a="none";else if(-1===["none","localhost","*"].indexOf(a)&&!B.isIpOrHostname(a)&&(0===a.indexOf(".")||1===(a.match(/\./g)||[]).length&&B.isSecondLevelDomain(a)))return null;return a}):[]};return{connects:a.options.override.merge_connects&&"paranoid"!=k.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 g=m(),l=function(){g.resolve({permitted:!0})},f=function(a){g.resolve({permitted:!1,reason:a})},x=function(){g.resolve({unknown:!0})},h,q=function(a,c){var b=null,g=B.isIpOrHostname(a);c.every(function(c){if(c.a)for(var d=0;d<c.a.length;d++)if(c.a[d]&&(g||B.isIpOrHostname(c.a[d])?c.a[d]===a:-1!=a.search(new RegExp("(^|.+\\.)"+y.escapeForRegExp(c.a[d])+"$"))))return b=c.blocker?f:l,!1;return!0});return b};if("off"==k.values.connect_mode)l();
else if((h=B.parse(b))&&h.hostname)if((b=q(h.hostname,[{a:d[a.uuid]}]))||(b=e(d[a.uuid])?l:null))b();else if(0===c.connects.length&&0===c.userconnects.length&&0===c.blockers.length)"casual"==k.values.connect_mode?l():"strict"==k.values.connect_mode?f("No @connects given, but strict mode enabled"):x();else if(-1!=c.connects.indexOf("none"))f("None value found");else{if("casual"!=k.values.connect_mode||e(c.blockers)||!(b=e(c.connects)?l:null))(b=e(c.userconnects)?l:null)||(b=q(h.hostname,[{a:c.blockers,
blocker:!0},{a:c.connects},{a:c.userconnects}])||x);b()}else f("URL can not be parsed");return g.promise()},a=function(){var a=function(a){for(var c=0;c<g.length;c++)if(g[c].tabId===a)return g.splice(c,1)[0];return g.pop()},b;pa().then(function(g){for(;!c&&(b=a(g.id));)b.fn()})},c,g=[],l=function(b,l,f,x,v){var k,q=m(),n=function(){q.resolve({approved:!0})},r=function(){q.resolve({forbidden:!0})};p.debug('cor: "'+b.name+'" is asking for permission to access',x,l);if((k=B.parse(x))&&k.hostname){var Ca=
h(k.hostname),Aa=l.tab?l.tab.id:null;c=!0;pa().then(function(a){return X.askForConnect({src_url:l.url,hostname:k.hostname,domain:Ca,all_domains:e(f.connects),tabid:Aa,active:Aa===a.id,timeout:v,url:x,settings_url:rea.extension.getURL("options.html")+"#nav="+b.uuid+"+settings",connect_url:"https://www.tampermonkey.net/documentation.php#_connect",script:{name:b.name,uuid:b.uuid,icon:b.icon64||b.icon||P.images.origin("unknown")}})}).done(function(a){var c,g=a.whole_domain?Ca:k.hostname;a.allow?a.once?
(p.debug('cor: allowing "'+b.name+'" to access',g,"once"),n()):a.temporary?(p.debug('cor: allowing "'+b.name+'" to access',g,"temporarily"),void 0===d[b.uuid]&&(d[b.uuid]=[]),-1==d[b.uuid].indexOf(g)&&d[b.uuid].push(g),n()):(c=n,a.all_domains?(p.debug('cor: allowing "'+b.name+'" to access all domains always'),b.options.override.use_connects.push("*")):(p.debug('cor: allowing "'+b.name+'" to access',g,"always"),b.options.override.use_connects.push(g),c=n)):a.once||a.aborted?(p.debug('cor: denying "'+
b.name+'" to access',g,"once"),r()):(b.options.override.use_blockers||(b.options.override.use_blockers=[]),c=r,a.all_domains?(p.debug('cor: denying "'+b.name+'" to access any domains (additional) domain'),b.options.override.use_blockers.push("*")):(p.debug('cor: denying "'+b.name+'" to access',g,"always"),b.options.override.use_blockers.push(g)));c&&u.doModify(b.uuid,b,!1).always(c)}).fail(r).always(function(){c=!1;g.length&&window.setTimeout(a,1)})}else r();return q.promise()},x=function(a,d,h,w){var v=
q(a,d),n=arguments;return f(h).then(function(c){if(!0!==c.allowed)return m.Breach("URL is blacklisted");var g,l;return(g=B.parse(h))&&g.origin&&(l=B.parse(d.url))&&l.origin&&g.origin===l.origin?m.Pledge({permitted:!0}):b(a,v,h)}).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===v.connects.length||e(v.connects)){if(-1==["ask","paranoid"].indexOf(k.values.connect_mode))return m.Breach();if(e(v.blockers))return m.Breach("URL was permanently blocked by the user");
if(c){p.debug('cor: queuing access permission check from "'+a.name+'" to',h,d);var f=m();g.push({tabId:d.tab?d.tab.id:null,fn:function(){f.consume(x.apply(this,n))}});return f.promise()}return l(a,d,v,h,w).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){g=g.filter(function(c){return c.tabId!==
a})},exec:function(a,c,b,g){var d,l,e,f,h=a.url,k=[],w=Math.max(Math.min(a.timeout||0,6E4),2E4),q=function(){for(var a;!e&&!f&&(a=k.shift());)a()},m=function(c,b){var d='Refused to connect to "'+(b||a.url)+'": '+(c||"Blocked by @connect CORS check"),l=W.makeErrorResponse(d);["onerror","ondone"].forEach(function(a){if(g[a])g[a]({response:l,exception:d})})};if(!(b&&b.url&&b.tab&&a.url&&c&&(l=A.getByUid(c))&&l.script&&l.cond))return m();x(l.script,b,a.url,w).done(function(){var c={};Object.keys(g).forEach(function(a){c[a]=
function(t){var z=arguments;e||(f?k.push(function(){c[a].apply(this,z)}):function(){return t&&t.finalUrl&&h!==t.finalUrl?(f=!0,x(l.script,b,t.finalUrl,w).fail(function(){e||(d&&d.abort(),e=!0,m("Request was redirected to a not whitelisted URL",t.finalUrl),p.warn("cor: request to",h,"was redirect to a not whitelisted URL",t.finalUrl))}).always(function(){h=t.finalUrl;f=!1;k.length&&window.setTimeout(q,1)})):{always:function(a){a()}}}().always(function(){if(!e)g[a]({response:t})}))}});d=aa.external(a,
c)}).fail(function(a){m(a);p.warn("cor: access to",h,"was denied")});return{abort:function(){e=!0;d&&d.abort()}}}}}(),sa=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("")},h={md5:function(a,c){return m.Pledge(H.MD5(a,c))},sha256:function(a){return m.Pledge(forge_sha256(a))}},e={};["SHA-1","SHA-384","SHA-512"].forEach(function(a){var c=a.toLowerCase().replace("-","");e[c]=function(){var c=
function(c,b){var g=m();window.crypto.subtle.digest(a,H.str2arrbuf(c,b)).then(function(a){g.resolve(d(a))},function(){g.reject()});return g.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 f=function(a){return-1!=Object.keys(h).indexOf(a)},k=function(a){return function(){if(!1!==b){var c=arguments,g=m();b.push(function(){g.consume(a.apply(this,c))});return g.promise()}return a.apply(this,arguments)}},
b=[];return{init:function(){p.D&&Object.keys(h).forEach(function(a){p.debug("sri:",a,"is supported")});return m.sidebyside(Object.keys(e).map(function(a){return e[a]().done(function(c){p.debug("sri:",a,"is supported");h[a]=c}).fail(function(){p.debug("sri:",a,"is unsupported")})})).always(function(){b.forEach(function(a){a()});b=!1})},isSupported:k(function(a){return m.Pledge(f(a))}),getHash:k(function(a,c){var b=m();"string"===typeof a&&(a=B.parse(a));if(a&&a.hash){for(var l,e,t=a.hash.replace(/^#/,
"").split(/,|;/g),h=0;h<t.length;h++)if((e=t[h].match(/([^=|:|-]+)[=|:|-](.+)/))&&3==e.length&&f(e[1])){l=e[2];if(!/^[0-9a-fA-F]+$/.exec(l)){var k;var q=decodeURIComponent(l);try{k=d(H.str2arrbuf(H.Base64.decode(q)))}catch(v){k=null}l=k||l}l={type:e[1],value:l}}b.resolve(l||(c?l:{type:"unsupported",value:""}))}else b.resolve();return b.promise()}),check:k(function(a,c,b){return c&&a&&f(a.type)?h[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()})}}(),O=function(){var d={key:function(a,c){return n.CONSTANTS.PREFIX.EXTERNAL+y.select([a,c?H.MD5(c):null],function(a){return a}).join(":")},list:function(a){var c=new RegExp("^"+a);return y.select(r.listValues(),function(a){return-1!=a.search(c)})},set:function(a,c,b,l){a=d.key(a,c);var e={};y.each(b,function(a,c){"content"==c&&(c="base",a=H.encodeS(a));e[c]=a});r.setValue(a,{ts:Date.now(),url:c,resource:e,modified:l})},get:function(a,c){var b=d.key(a,c),b=r.getValue(b),l;if(b&&b.resource){var e=
{};y.each(b.resource,function(a,c){"base"==c&&(c="content",a=H.decodeS(a));e[c]=a});l={ts:b.ts,url:b.url,data:e,modified:b.modified}}return l},clean:function(a,c){var b=d.key(a,c);r.deleteValue(b)},cleanAll:function(a,c){var b,l=d.list(d.key(a));if(c){var e={};y.each(c,function(c){c=d.key(a,c);e[c]=!0});b=[];y.each(l,function(a){e[a]||b.push(a)})}else b=l;b.forEach(function(a){r.deleteValue(a)})}},h=function(a,c){var b=m(),d=function(d){var l={content:""};if(4!=d.readyState||200!=d.status&&0!=d.status||
d.error)b.reject(l);else{var e,f,t=W.parseHeaders(d.responseHeaders)["content-type"];t&&t.match("(image/|text/)([.-a-zA-Z0-9]+)")&&(e=t);e||(a.match(".*.(ico|jpg|jpeg)+($|\\?|#).*")?e="image/x-icon":(f=a.match(".*.(gif|png)+($|\\?|#).*"))?e="image/"+f[1]:-1!=a.search(".*.(js)+($|\\?|#).*")?e="text/javascript":(f=a.match(".*.(css|html|xml)+($|\\?|#).*"))?e="text/"+f[1]:y.isLocalImage(a)&&(e="image/x-icon"));l.meta=e;l.content=H.arrbuf2str(d.response,c.encoding)||"";b.resolve(l)}},e=function(){b.reject({})},
f=B.parse(a);-1!=["file:"].concat(n.REQUESTS.INTERNAL_PAGE_PROTOCOLS).indexOf(f.protocol)?"file:"!=f.protocol||n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS&&-1!=["externals","all"].indexOf(k.values.script_file_access)?rea.file.get(a,function(a){d({readyState:4,status:0,response:a})},function(a){e({error:!0,responseText:a})}):(p.warn("externals:","Access to this local file is forbidden!","Loading the following @resource failed:",a,"-> more info:","https://www.tampermonkey.net/faq.php#Q204"),e({error:!0,responseText:"Access to this local file is forbidden!"})):
(f={method:"GET",url:a,retries:n.XMLHTTPREQUEST.RETRIES,nocache:!1,responseType:"arraybuffer"},f.timeout=k.values.require_timeout,aa.internal(f,{onload:d,onerror:e,ontimeout:e}));return b.promise()},e=y.getDebouncer(9E3),f=function(a,c,b,l){var e=m(),f={sync:!1};h(c,{encoding:l.encoding}).done(function(h){b&&(h.sri=b);var q=function(b){var g=B.parse(c);g.protocol&&-1==["file:"].concat(n.REQUESTS.INTERNAL_PAGE_PROTOCOLS).indexOf(g.protocol)&&d.set(a,c,b)};b&&-1!=["supported","given"].indexOf(k.values.require_sri_mode)?
sa.check(b,h.content,l.encoding).done(function(){f.resource=h;q(f.resource);e.resolve(f)}).fail(function(a){f.resource={forbidden:!0,sri:{mode:k.values.require_sri_mode,type:b.type,value:"invalid"},determined:a,content:""};q(f.resource);e.reject(f)}):(f.resource=h,q(f.resource),e.resolve(f))}).fail(function(b){p.debug("externals: get.failed",a,c,b);f.resource={failed:!0,content:""};e.reject(f)});return e.promise()},q=function(a,c,b){var l=m(),h=B.parse(c),t={sync:b.sync},z;c?I.getEvilnessOf(c)>=k.values.script_blacklist_severity?
(t.resource={blacklisted:!0,content:""},l.reject(t)):sa.getHash(h,"supported"==k.values.require_sri_mode).done(function(q){if("enforce"!=k.values.require_sri_mode||q)if("file:"!==h.protocol&&(z=d.get(a,c))){var m=d.key(a,c),v=Date.now();0<k.values.external_update_interval&&v-z.ts>k.values.external_update_interval&&!e.is(m)&&(1<k.values.external_update_interval&&e.add(m),z.modified?p.debug("externals: resource is not updated due to user modifications",c,(new Date(z.ts)).toISOString(),(new Date(v)).toISOString()):
(p.debug("externals: resource needs update",c,(new Date(z.ts)).toISOString(),(new Date(v)).toISOString()),window.setTimeout(function(){f(a,c,q,b)},3E3)));t.resource=z.data;t.resource.forbidden||t.resource.blacklisted?l.reject(t):l.resolve(t)}else l.consume(f(a,c,q,b));else t.resource={forbidden:!0,sri:{mode:k.values.require_sri_mode},content:""},l.reject(t)}):(t.resource={forbidden:!0,content:""},l.reject(t));return l.promise()},b={setElement:function(a,c,b,l){return d.set(a,c,b,l)},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 g=m();b.getResources(a,c).always(function(){g.resolve()});return g.promise()},loadRequires:function(a,c){var g=m();b.getRequires(a,c).always(function(){g.resolve()});return g.promise()},getResources:function(a,c){var b={elements:[]},d=m(),e=[],f={sync:!0};c.forEach(function(c){var d=c.url||
B.sanitize(c.unsafe_url,c.abs_url),l={name:c.name,url:d},d=q(a,d,f),h=m();d.done(function(a){a=a.resource;l.content=a.content;l.meta=a.meta||"application"}).fail(function(a){a.resource&&a.resource.forbidden?a.resource.sri?p.warn("externals: can't load @resource",c.name,"from URL",c.unsafe_url,"due to a SRI error"):p.warn("externals: can't load @resource",c.name,"from forbidden URL",c.unsafe_url):a.resource&&a.resource.blacklisted?p.warn("externals: can't load @resource",c.name,"from blacklisted URL",
c.unsafe_url):(p.warn("externals: can't load @resource",c.name,"from URL",c.unsafe_url),l.failed=!0);l.content=null}).always(function(a){f.sync&=a.sync;b.elements.push(l);h.resolve()});e.push(h)});m.when(e).always(function(){b.sync=f.sync;d.resolve(b)});return d.promise()},getRequires:function(a,c){var b={elements:[]},d=m(),e=[],f={encoding:"UTF-8",sync:!0};y.each(c,function(c,d){var l=c.url||B.sanitize(c.unsafe_url,c.abs_url),h={},l=q(a,l,f),k=m();l.done(function(a){h.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;h.textContent='console.warn("Tampermonkey: " + decodeURIComponent("'+encodeURIComponent(a)+'"));\n';p.warn("externals: "+a)}).always(function(a){f.sync&=a.sync;
b.elements[d]=h;k.resolve()});e.push(k)});m.when(e).always(function(){b.sync=f.sync;b.elements=b.elements.filter(function(a){return a});d.resolve(b)});return d.promise()}};return b}();exts=O;var Da=function(){var d=function(d,f,h){var b=m(),a=[];h.forEach(function(c){c=c.textContent||"";c=ja.mkCompat(c,d.options.compatopts_for_requires?d:null,"off"!=k.values.runtime_strict_mode);a.push(c)});h="\n"+a.join("\n")+"\n";var c=A.getStorageByUid(d.uuid);f=ja.mkCompat(f,d,"off"!=k.values.runtime_strict_mode);
if(k.values.debug){f=f.split("\n");for(var g=!1,l,x=0;x<f.length;x++)if(l=f[x],!l.match(/^\s*$|^\s*\/\/\s*|^\s*\/\*.*\*\/\s*$|^\s*["']+use strict["']+;*\s*$/))if(l.match(/^\s*\/\*/)&&(g=!0),g)if(l.match(/\*\/\s*$/))g=!1;else{if(-1!=(l=l.search(/\*\//))){f[x]=y.insert(f[x],l+2,0,"debugger;");break}}else{f[x]="debugger;"+f[x];break}f=f.join("\n")}h={header:d.header,code:f,requires:h,storage:c,script:d,source_url:rea.extension.getURL("userscript.html")+"?id="+d.uuid};b.resolve(h);return b.promise()},
h={};return{bundle:function(e,f){var k,b,a=!0;if(k=h[f.uuid])return k;var c={},g="includes matches requires resources excludes connects textContent".split(" ");Object.keys(f).forEach(function(a){-1==g.indexOf(a)&&("options"==a?(c[a]=JSON.parse(JSON.stringify(f[a])),c[a].run_at=c[a].run_at||f.options.override.orig_run_at||"document-idle"):c[a]=f[a])});k=O.getResources(c.uuid,f.resources).then(function(b){a&&!b.sync&&(p.debug("ri: uncached @external detected -> fast script start disabled"),a=b.sync);
c.resources=b.elements;return O.getRequires(c.uuid,f.requires)}).then(function(b){a&&!b.sync&&(p.debug("ri: uncached @external detected -> fast script start disabled"),a=b.sync);b=b.elements;p.debug("run script "+c.name+" @ "+e.url);return d(c,f.textContent,b)}).always(function(){b=!0;delete h[c.uuid]});b||(h[c.uuid]=k);return k}}}(),N=function(){var d={},h={},e=function(b,a){var c,g=a.key||"general",d=a.timeout||3E5,e=window.setTimeout(function(){delete b[g]},d);(c=b[g])&&window.clearTimeout(c.to);
b[g]={ts:Date.now()+d,options:a,to:e}},f=function(b){var a=Date.now();return Object.keys(b).map(function(c){var g=b[c];c=y.copy(g.options,{});if(g=Math.max(0,g.ts-a))return c.timeout=g,c}).filter(function(a){return a})},k={all:function(b,a){k.actionPage(b,a);k.optionsPage(b,a)},removeAll:function(b){delete d[b];delete h[b]},actionPage:function(b,a){var c=rea.extension.getViews({type:"popup"});c&&c.length&&rea.extension.sendMessage({method:b,options:a},function(){});a&&e(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&&e(h,a)},actionStatus:function(){return f(h)},optionsStatus:function(){return f(d)}};return k}(),Z=function(){return{getConfig:function(){var d={version:0,last:0},h={scripts:0},e=r.getValue(n.CONSTANTS.STORAGE.UPDATE,h);"object"!==typeof e&&(e=h);e||(e=h);void 0==e.black&&(e.black=d);void 0==e.scripts&&(e.scripts=0);return e},setConfig:function(d){d&&r.setValue(n.CONSTANTS.STORAGE.UPDATE,
d)}}}(),ba=function(){var w=function(f,h){var b=0,a=0,c=0,g=d.getMessage("Script_Update"),l=d.getMessage("Check_for_userscripts_updates")+"...";f&&S.show(g,l,P.images.brand("tampermonkey"),{timeout:1E4});var x=A.getUidList().map(function(g){var l,f,x,v,w,r;return function(){v=A.getByUid(g);if(!v.script||!v.cond)return p.warn("update: inconsistent script entry",g,v),m.Breach();var a=!k.values.scriptUpdateCheckDisabled&&!v.script.enabled&&!h||!v.script.options.check_for_updates;if(h&&v.script.uuid!==
h||a||!(r=u.determineSourceURL(v.script))||v.script.evilness&&v.script.evilness>=Math.min(I.SEVERITY_MAX,k.values.script_blacklist_severity))return m.Breach();var c;if((c=u.determineOrigin(v.script))&&c.updates_allowed&&!c.updates_allowed(r))return m.Breach();b++;p.info("update: check for script updates @",g);return m.Pledge()}().then(function(){var a=u.determineMetaURL(v.script);if(!a)return m.Pledge();if("none"==a)return p.log("update: ignore non-updatable script",v.script.name),m.Breach();var c=
m();aa.internal({method:"GET",retries:n.XMLHTTPREQUEST.RETRIES,timeout:1E3*n.SCRIPT_DOWNLOAD.TIMEOUT,revalidate:!0,headers:{Accept:"text/x-userscript-meta, */*"},url:a},{ondone:function(b){4==b.readyState&&200==b.status?w=C.processMetaHeader(b.responseText):p.warn("update: unable to find meta data @ "+a+" req.status = "+b.status);c.resolve()}});return c.promise()}).then(function(){var a=!!w,c=a&&!!w.version,b=c&&(!v.script.version||C.versionCmp(w.version,v.script.version)==C.versionCmp.eNEWER);return a&&
c&&!b?m.Breach():m.Pledge()}).then(function(){var a;if(a=B.parse(r)){if(a.protocol.match(/(https?|file):/))return e.getScriptFromURL(r).fail(function(){p.warn("update: failed",v.script.name,r)});p.warn("update: can't download URL",v.script.name,r)}else p.warn("update: can't parse URL",v.script.name,r)}).then(function(c){var b;b=v.script.uuid;var g=C.createScriptFromSrc(c);if(!g.name||""==g.name||void 0===g.version||g.options.compat_uW_gmonkey)b=C.versionCmp.eERROR;else{var d;b=(d=A.getMetaByUid(b))?
d.system?null:g.version==d.version?C.versionCmp.eEQUAL:C.versionCmp(g.version,d.version):C.versionCmp.eNEWER}return b==C.versionCmp.eNEWER?(a++,l=v.script.name,f=r,x=c,m.Pledge()):m.Breach()}).then(function(){if(k.values.notification_silentScriptUpdate)return m.Pledge();var a=d.getMessage("There_is_an_update_for_0name0_avaiable_",l)+"\n"+d.getMessage("Click_here_to_install_it_"),c=d.getMessage("Just_another_service_provided_by_your_friendly_script_updater_")+":",b=m();S.show(c,a,P.images.brand("tampermonkey"),
{timeout:k.values.scriptUpdateHideNotificationAfter},b.resolve);return b.promise()}).then(function(a){var b=g||v.script.uuid;return void 0===a||a.clicked?u.doSave({url:f,uuid:b,replace:!b,src:x,ask:!k.values.notification_silentScriptUpdate}).done(function(a){a&&a.installed&&c++}):m.Breach()})});b&&N.all("status",{key:"script_update",class:"information",title:g,text:l,timeout:1E4});return m.sidebyside(x).then(function(){x.length&&0==a&&(p.debug("No update found"),f&&S.show("Narf!",d.getMessage("No_update_found__sry_"),
P.images.brand("tampermonkey"),{timeout:1E4}),N.all("status",{key:"script_update",class:"information",text:d.getMessage("No_update_found__sry_"),timeout:1E4}));return{found:a,installed:c}})},h=null,e={check:function(e,h,b){if(!e&&0>=k.values.scriptUpdateCheckPeriod)return m.Breach();var a=Z.getConfig();if(!e&&Date.now()-a.scripts<Math.max(k.values.scriptUpdateCheckPeriod,36E5))return m.Breach();var c,g;return m.Pledge().then(function(){var a=function(){g=null;var a=d.getMessage("Script_Update"),c=
d.getMessage("Waiting_for_sync_to_finish")+"...";g=S.show(a,c,P.images.brand("tampermonkey"),{timeout:6E4})};if(L.enabled){var b=m();L.addSyncDoneCallback(b.resolve);L.sync(50,!1);h&&(c=window.setTimeout(a,500));return b.promise()}}).then(function(){if(!e){var a=m(),c=function(){rea.idle.queryState(n.MISC.IDLE_TIMEOUT,function(a){"active"==a?window.setTimeout(c,1E3*Math.round(n.MISC.IDLE_TIMEOUT/2)):b()})},b=function(){var b;rea.windows.getAll({},function(g){g.forEach(function(a){"fullscreen"===a.state&&
(b=!0)});b?window.setTimeout(c,1E3*n.MISC.IDLE_TIMEOUT):a.resolve()})};c();return a.promise()}}).then(function(){var d=m();c&&(window.clearTimeout(c),c=null);g&&g.cancel();w(h,b).done(function(a){d.resolve(a.installed)}).fail(function(){d.resolve(null)});a=Z.getConfig();a.scripts=Date.now();Z.setConfig(a);return d.promise()})},getScriptFromURL:function(d){var e=m();-1!=["file:"].concat(n.REQUESTS.INTERNAL_PAGE_PROTOCOLS).indexOf(B.parse(d).protocol)?rea.file.get(d,function(b){e.resolve(H.arrbuf2str(b,
"UTF-8"))},function(b){e.reject({error:!0,responseText:b})}):aa.internal({method:"GET",retries:n.XMLHTTPREQUEST.RETRIES,timeout:1E3*n.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?e.reject({error:!0,responseText:b.responseText}):e.resolve(b.responseText)},onerror:function(b){e.reject({error:!0,responseText:b.responseText})},ontimeout:function(){e.reject({timeout:!0,responseText:""})}});
return e.promise()},init:function(){var d=function(){h&&(window.clearTimeout(h),h=null);0<k.values.scriptUpdateCheckPeriod&&(h=window.setTimeout(function(){h=null;e.check();d()},36E5))};d();k.addChangeListener("scriptUpdateCheckPeriod",d)}};return e}();trup=ba;var u=function(){var w=function(b){b.sort(function(a,c){return a.position-c.position});return b},h=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=C.createScriptFromSrc(b.src),
c=null,g={heading:null,errors:[],info:[],warnings:[],flags:{}},l=m(),e=Date.now(),f=b.save&&!b.ask&&k.values.editor_easySave,h=b.uuid,w,n;a.name&&void 0!=a.version?n=m.Pledge():(g.errors.push(d.getMessage("Invalid_UserScript__Sry_")+"\n\n"),b.name&&g.errors.push(d.getMessage("Script_name_0name0",b.name)+"\n\n"),b.url&&g.errors.push(d.getMessage("Downloaded_from_0url0",b.url)),p.warn("scriptman: invalid userscript",g,a),n=m.Breach());n.then(function(){b.replace&&!h&&(h=A.getUidsByName(a.name,a.namespace)[0]);
if(h)c=A.getMetaByUid(h);else if(a.uuid)h=a.uuid;else if(b.replace)h=y.createUUID();else return p.warn("scriptman: neither UUID, @uuid nor replace option set"),m.Breach();if(""!==h.replace(/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/,""))return p.warn("scriptman: invalid UUID",h),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 g.errors.push(d.getMessage("Invalid_UserScript_name__Sry_")),
m.Breach()}).then(function(){if(a.options.compat_uW_gmonkey)return g.errors.push(d.getMessage("This_script_uses_uW_gm_api_")),m.Breach()}).then(function(){if(c){c.name!=a.name&&(g.flags.renamed=!0);b.internal||c.evilness!=I.SEVERITY_FOISTED_SCRIPT||(g.warnings.push(d.getMessage("This_is_a_possibly_foisted_script_and_a_modification_will_enable_it_")),g.flags.forceAsk=!0);if(c.lastModified&&void 0!==b.lastModTime&&c.lastModified!==b.lastModTime){var l=d.getMessage("some_secs");try{var h=Math.max(1,
Math.floor((e-c.lastModified)/1E3));isNaN(h)||(l=h)}catch(k){}g.warnings.push(d.getMessage("CONFLICT__This_script_was_modified_0t0_seconds_ago_",l));g.flags.forceAsk=!0}a.version==c.version&&(b.save?g.flags.modification=!0:g.flags.reset=!0);b.clean&&(g.flags.factory=!0);w=!b.internal}else g.flags.first_install=!0,w=!b.internal||b.save;a.includes.length||a.matches.length||f||b.internal||g.warnings.push(d.getMessage("This_script_does_not_provide_any__include_information_"));g.flags.sync=!!b.sync;g.flags.internal=
b.internal;g.flags.ask=b.ask;g.flags.save=b.save;g.flags.whitewash=b.whitewash}).then(function(){a.uuid=h;a.system=b.defaultscript;a.evilness=u.getEvilness(a);a.position=u.determineLastPosition()+1;a.lastModified=e;if(b.force_meta){var d;if(d=b.force_meta.fileURL)a.fileURL=d;if(d=b.force_meta.lastModified)a.lastModified=d}g.flags.factory||g.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),!g.flags.factory&&!g.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 l=q.determineMetaURL(c),e=q.determineMetaURL(a),l=l?B.woHash(l):l,e=e?B.woHash(e):e;l==e||f||b.internal||g.warnings.push(d.getMessage("The_update_url_has_changed_from_0oldurl0_to__0newurl0",[l,e]));b.save||(y.adiff(c.includes,a.includes,"notinfirst").length+y.adiff(c.matches,a.matches,"notinfirst").length+
y.adiff(a.excludes,c.excludes,"notinfirst").length&&g.warnings.push(d.getMessage("At_least_one_of_the_include_match_or_exclude_statements_was_changed_")),y.adiff(c.connects||[],a.connects||[],"notinfirst").length&&g.warnings.push(d.getMessage("At_least_one_new_connect_statement_was_added_")))}}).then(function(){if(c&&!g.flags.factory&&a.version==c.version&&(b.defaultscript||b.noreinstall))return m.Breach()}).then(function(){c?(g.flags.factory||g.flags.reset?(g.flags.reset?(g.heading=d.getMessage("You_are_about_to_reinstall_a_UserScript_"),
g.flags.reinstall=!0):(g.heading=d.getMessage("You_are_about_to_install_a_UserScript_"),g.flags.install=!0),b.internal||g.warnings.splice(0,0,d.getMessage("All_script_settings_will_be_reset_"))):g.flags.modification?g.heading=d.getMessage("You_are_about_to_modify_a_UserScript_"):C.versionCmp(a.version,c.version)==C.versionCmp.eOLDER?(g.heading=d.getMessage("You_are_about_to_downgrade_a_UserScript"),g.flags.downgrade=!0,f||b.internal||g.warnings.splice(0,0,d.getMessage("The_downgraded_script_might_have_problems_to_read_its_stored_data_"))):
(g.heading=d.getMessage("You_are_about_to_update_a_UserScript_"),g.flags.update=!0),g.info.push({label:d.getMessage("Installed_Version_"),value:"v"+c.version})):(g.heading=d.getMessage("You_are_about_to_install_a_UserScript_"),f||b.internal||(g.info.splice(0,0,d.getMessage("Malicious_scripts_can_violate_your_privacy_")),I.getWarningsFor(q.determineSourceURL(a)).forEach(function(a){g.warnings.splice(0,0,a)})),g.flags.install=!0);g.flags.whitewash?g.action=d.getMessage("Enable"):g.flags.install?g.action=
d.getMessage("Install"):g.flags.reinstall?g.action=d.getMessage("Reinstall"):g.flags.modification?g.action=d.getMessage("Modify"):g.flags.downgrade?g.action=d.getMessage("Downgrade"):g.flags.update&&(g.action=d.getMessage("Update"))}).then(function(){b.url&&(a.fileURL=b.url);b.sync&&(a.sync=b.sync);b.force_options&&y.copy(b.force_options,a.options,(new C.Script).options,!0);b.force_settings&&y.copy(b.force_settings,a,["enabled","position"]);a=u.mergeCludes(a)}).then(function(){var c=!1,l;for(l in a.options)if(-1!=
l.search("compat_")&&!0===a.options[l]){c=!0;break}c&&g.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 e,f;(e=q.determineOrigin(a))&&(f=e.convert)&&(c=f(a),c.warning&&(b.internal?g.info.push(c.warning):g.warnings.push(c.warning)),a=c.script)}).then(function(){["requires","resources"].forEach(function(c){a[c]=y.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(){l.resolve({script:a,oldscript:c,messages:g,trigger_sync:!!w,short_info:[{label:d.getMessage("Author"),prop:"author"},{label:d.getMessage("Description"),prop:"description"},{label:d.getMessage("Source"),prop:"fileURL"}]})}).fail(function(){l.reject({messages:g})});return l.promise()},e=function(b){var a=m(),c=b.messages,g=b.script,d=b.trigger_sync,e=function(){c.flags.modification||O.dropAll(g.uuid);a.notify();var b=q.doModify(g.uuid,g,d)||
{};!c.flags.install&&!c.flags.update||c.flags.factory||c.flags.reset||M.tS(g.name,g.fileURL,c.flags.install?"i":"u");(c.flags.first_install||c.flags.factory)&&A.setStorageByUid(g.uuid,{ts:Date.now()});return b},f={uuid:g.uuid,lastModified:void 0,installed:!0,renamed:c.flags.renamed};c.warnings.length||c.flags.ask?X.install(b).done(function(c){c.ok&&e();f.installed=c.ok;f.aborted=c.aborted;a.resolve(f)}).fail(function(c){a.reject(c)}):window.setTimeout(function(){e();a.resolve(f)},1);return a.promise()},
f=y.getDebouncer(1E3),q={determineSourceURL:function(b){return b?y.select([b.downloadURL,b.fileURL],function(a){if(!a||"file:"!==B.parse(a).protocol)return a})[0]:null},determineMetaURL:function(b){if(!b)return null;var a,c=u.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 y.select([b.updateURL,b.downloadURL,a],function(a){if(!a||"file:"!==
B.parse(a).protocol)return a})[0]},mergeCludes:function(b){var a,c,g=b.options.override;["includes","excludes","matches"].forEach(function(a){b[a]=g["merge_"+a]&&g["orig_"+a]?g["orig_"+a].slice():[]});if(g.use_includes)for(a=0;a<g.use_includes.length;a++)c=b.excludes.indexOf(g.use_includes[a]),0<=c&&b.excludes.splice(c,1),b.includes.push(g.use_includes[a]);if(g.use_matches)for(a=0;a<g.use_matches.length;a++)c=b.excludes.indexOf(g.use_matches[a]),0<=c&&b.excludes.splice(c,1),b.matches.push(g.use_matches[a]);
if(g.use_excludes)for(a=0;a<g.use_excludes.length;a++)b.excludes.push(g.use_excludes[a]);return b},doSave:function(b){return h(b).then(e)},doRemove:function(b,a){A.removeByUid(b,a);A.setStorageByUid(b,null);O.dropAll(b);return m.Pledge()},doModify:function(b,a,c){void 0===c&&(c=!0);A.setByUid(b,a,c);return c?O.loadResources(b,a.resources).then(function(){return O.loadRequires(b,a.requires)}).then(function(){var c=[].concat(a.resources).concat(a.requires).map(function(a){return B.sanitize(a.unsafe_url,
a.abs_url)});return O.dropAllBut(b,c)}):m.Pledge()},exportToJson:function(b,a){var c=m(),g=u.determineScriptsToRun(null);b&&(g=y.select(g,function(a){return b[a.uuid]}));g=ta(g,{options_page:!0,externals:a.externals});a&&!a.storage||g.forEach(function(a){a.storage=A.getStorageByUid(a.uuid)});g={scripts:g};if(!a||a.global_settings)g.global_settings=r.getValue(n.CONSTANTS.STORAGE.CONFIG,{});c.resolve(g);return c.promise()},importFromJson:function(b){if(!b||!b.scripts||!b.scripts.length)return m.Breach();
for(var a={},c=[],g={},d={requires:{},resources:{}},f=0,k;k=b.scripts[f];f++)try{var z=m();"new-user-script"!=k.uuid&&(k.storage&&(g[k.uuid]=k.storage),["resources","requires"].forEach(function(a){var c;if(c=k[a])d[a][k.uuid]=c}),h({uuid:k.uuid,name:k.name,src:k.source,force_settings:{enabled:k.enabled,position:k.position},force_options:k.options,force_meta:{lastModified:k.lastModified},replace:!0,url:k.file_url||k.update_url,ask:!1}).done(function(c){a[y.createUUID()]=c;z.resolve()}).fail(function(a){p.warn("import: Error @ script",
k.name,a);z.resolve()}),c.push(z.promise()))}catch(w){p.warn("import: Error while importing script",k.name,w)}var q=function(){var a=m();m.when(c).always(function(){a.resolve()});return a.promise()}().then(function(){return X.import(a,b.global_settings)}).then(function(c){var b=m(),f=[],h=[];if(c.ok)for(var k=0,x;x=c.import_ids[k];k++)(function(){var c=x;if(a[c]){a[c].messages.warnings=[];var b=a[c].script.uuid,c=e(a[c]).progress(function(){["resources","requires"].forEach(function(a){var c;(c=d[a][b])&&
c.length&&c.forEach(function(a){O.setElement(b,a.url,{content:a.content||"",meta:a.mimetype||"text/javascript"},a.modified)})})}).done(function(){var a;g[b]&&(a=A.setStorageByUid(b,{data:g[b].data||{},ts:Date.now()}),h.push(a))});f.push(c)}})();m.when(f).always(function(){u.reorderScripts();m.when(h).always(function(){b.resolve(c)})});return b.promise()}).then(function(a){return b.global_settings&&a.global_settings?(a=r.setValue(n.CONSTANTS.STORAGE.CONFIG,b.global_settings).then(function(){q.done(function(){window.setTimeout(V.reset,
1)});return m.Pledge({global_settings:!0})}),r.setTemporary(!0),a):m.Pledge({})});return q},installFromUrl:function(b,a,c){var g=m(),l,e={messages:{errors:[d.getMessage("Unable_to_load_script_from_url_0url0",b)],warnings:[]}};a=a||{};c=c||{};var h=["url",b,JSON.stringify(a)].join("_");if(f.is(h))return p.debug("scriptman: de-bounced installFromUrl",b),m.Breach();f.add(h);if((l=B.parse(b))&&l.protocol.match(/(https?|file):/))"file:"!=l.protocol||n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS||p.warn("scriptman: Access to local files is forbidden! Loading the following script for installation may fail:",
b,"-> more info:","https://www.tampermonkey.net/faq.php#Q204");else return p.warn("scriptman: can't install from ",b),m.Breach(e);ba.getScriptFromURL(b).then(function(d){var l={url:b,src:d,ask:!0,replace:!0};a&&y.each(a,function(c,b){l[b]=a[b]});g.consume(q.installFromSource(d,l,c))}).fail(function(a){a?("file:"!=l.protocol||n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS||e.messages.warnings.unshift(d.getMessage("Tampermonkey_has_no_file_access_permission_")),e.heading=d.getMessage("You_are_about_to_install_a_UserScript_"),
c.silent_fail?g.reject(e):X.installError(e).always(function(a){g.reject(a)})):g.reject()});return g.promise()},installFromSource:function(b,a,c){var g=m(),l={src:b,ask:!0,replace:!0};a&&y.each(a,function(c,b){l[b]=a[b]});q.doSave(l).done(function(a){g.resolve(a.installed)}).fail(function(a){a?(a.heading=d.getMessage("You_are_about_to_install_a_UserScript_"),c.silent_fail?g.reject(a):X.installError(a).always(function(a){g.reject(a)})):g.reject()});return g.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):p.warn("scriptman: inconsistent script entry",a)});var a=new C.Script;a.position>b&&(b=a.position);return b},convertToRegExp:function(b,a){var c,d;try{a||"/"!=b.substr(0,1)?a?(d=B.getRegExpFromMatch(b),c=new RegExp(d)):(d=B.getRegExpFromInclude(b),c=new RegExp(d,"i")):(d=("^"==b.substr(1,1)?"":".*")+b.replace(/^\//g,"").replace(/\/$/g,"")+("$"==b.substr(-2,1)?"":
".*"),d=d.replace(/(\.\*){1,}/g,".*"),c=new RegExp(d,"i"))}catch(l){return p.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(l){var e=b[l]&&b[l].length?b[l].map(function(a){return q.convertToRegExp(a,"match"===l)}).filter(function(a){return!1!==a}):null;if(e||a)c[d[l]]=(c[d[l]]||[]).concat(e||[])});return c},validUrl:function(b,a,c){var d=!1;if(a.rinc){if(a.rinc.every(function(a){return q.matchUrl(b,
a)?(p.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 q.matchUrl(b,a)?(p.debug('scriptman: @exclude "'+a+'" matched'+(c?" ("+c+")":'"')),d=!1):!0});return d},getEvilness:function(b){var a=0;return b.fileURL&&(a=I.getEvilnessOf(b.fileURL))||b.downloadURL&&(a=I.getEvilnessOf(b.downloadURL))||b.updateURL&&(a=I.getEvilnessOf(b.updateURL))?(p.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=u.getEvilness(a.script);if(c!==a.script.evilness){if(c||void 0!==a.script.evilness)p.debug("scriptman: write blacklist state of ",a.script.name,c),c&&M.tS(a.script.name,c,"b");a.script.evilness=c;q.doModify(b,a.script,!1)}}})},reorderScripts:function(b,a){var c=q.determineScriptsToRun();if(b)for(var d=0;d<c.length;d++){var l=c[d];l.uuid==b&&(l.position=Number(a)+(l.position<a?.5:-.5))}c=w(c);d=1;for(l=0;l<c.length;l++){var e=c[l];e.position=d++;q.doModify(e.uuid,
e,!1)}},getScriptHistoryForTab:function(b){if(D.get.empty(b.id))p.debug("bg: WARN: Tabs.get.urls["+b.id+"] is empty!");else return D.get.history(b.id);return{}},getUniqueScriptsForTab:function(b){var a={};D.get.empty(b.id)?p.debug("bg: WARN: Tabs.get.urls["+b.id+"] is empty!"):y.each(D.get.urls(b.id),function(c,b){if(T.isAllowed(b)){var d=Y.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=r.getValue(n.CONSTANTS.PREFIX.COND+b,null)))return;c=q.regexify(c,!0);K.items.regexp.set(b,c)}return!!q.validUrl(a,c,b)}},determineScriptsToRun:function(b,a){var c=[];p.debug("scriptman: determineScriptsToRun @"+b);A.getUidList().forEach(function(g){var l=!0,e=0;b&&(e=Date.now(),l=q.scriptWillRun(g,b),e=Date.now()-e);var f=A.getByUid(g);f.script&&f.cond?(a&&1E3<e&&(p.warn("scriptman: checking "+f.script.name+"'s ("+g+") includes and excludes took "+e+"ms!"),
N.all("status",{key:"slowdown",class:"warning",text:d.getMessage("Script_0name0_is_slowing_down_some_page_loads_",f.script.name),timeout:3E5})),l&&c.push(f.script)):p.warn("scriptman: inconsistent script entry",g,f)});return w(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 q.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,l,e,f,h=[{tag:"includes",re:/(?: \|\| \(new RegExp\("\^)([^$]+)(?:\$"\)\)\.test\(document\.location\.href\))/g,idx:1,value:function(a){return"/^"+a.replace(/\\\\(.)/g,"\\$1")+"$/"}},{tag:"includes",re:/(?: \|\| \(document\.location\.href\.indexOf\(")([^\"]+)"(?:\) == 0\))/g,idx:1,value:function(a){return a+
"*"}},{tag:"matches",re:/(?: \|\| \(document\.domain == ")([^\"]+)"(?: \|\| document\.domain\.substring\(document\.domain\.indexOf\("[^\"]+"\) \+ 1\) == "[^\"]+"\))/g,idx:1,value:function(a){return"*."+a}}],k=new RegExp("(?:if \\(false)("+h.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&&(l=a.textContent.match(k))&&(l.forEach(function(b){h.forEach(function(d){for(;e=d.re.exec(b);)if(e.length>d.idx){var g=d.value(e[d.idx]);a.options.override["orig_"+d.tag].push(g);a[d.tag].push(g);f=!0}})}),f&&(b=d.getMessage("Automatically_added_user_includes_for_compatibility_reasons_")));return{script:a,warning:b}}}}},clean:function(b){A.getUidList().forEach(function(a){var c=A.getByUid(a);if(!c.script||!c.cond){if(b)return p.warn("scriptman: inconsistent script entry",
a,c);q.doRemove(a,!0)}})}};return q}();scma=u;var A=function(){var d=[],h={init:function(){r.addDifferentOriginChangeListener(n.CONSTANTS.PREFIX.STORE,function(d,f){if(f&&f.hasOwnProperty("value")&&f.origin){var k=d.replace(n.CONSTANTS.PREFIX.STORE,""),b;for(b in f.value.data)f.value.data.hasOwnProperty(b)&&function(){var a=b,c=f.value.data[b];h.notifyStorageListeners({uuid:k},null,function(b){var d={data:{},ts:0};d.data[a]=c;d.ts=f.value.data.ts;var e={storage:d};void 0===d.data[a]&&(e.removed=a);
b(e)})}()}})},getUidList:function(){var d=new RegExp("^"+n.CONSTANTS.PREFIX.SCRIPT_UID),f=[];r.listValues().forEach(function(h){-1!=h.search(d)&&f.push(h.replace(d,""))});return f},getUidsByName:function(d,f){var k=[];h.getUidList().forEach(function(b){var a=h.getMetaByUid(b);!a||a.name!=d||f&&f!=a.namespace||k.push(b)});return k},getUidByName:function(d){return h.getUidsByName(d)[0]},getStorageByUid:function(d){d=r.getValue(n.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,f){return f?r.setValue(n.CONSTANTS.PREFIX.STORE+d,f):r.deleteValue(n.CONSTANTS.PREFIX.STORE+d)},getMetaByUid:function(d){return r.getValue(n.CONSTANTS.PREFIX.META+d,null)},getByUid:function(d,f){if(!d)return p.error("sb: no UUID set"),{};var h,b=r.getValue(n.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);f&&(b=y.copy(b,{}));b.textContent=r.getValue(n.CONSTANTS.PREFIX.SCRIPT+d,b.textContent);b.textContent&&(h=b)}return{script:h,cond:r.getValue(n.CONSTANTS.PREFIX.COND+d,null)}},setByUid:function(d,f,h){var b={};if(!d)return p.error("sb: no UUID set",f),b;
if(null===f.textContent||void 0===f.textContent)throw Error("No script code set!");var a=r.getValue(n.CONSTANTS.PREFIX.META+d),c=!a,g={},l=y.copy(f,{});l.textContent=null;g[n.CONSTANTS.PREFIX.META+d]=l;g[n.CONSTANTS.PREFIX.SCRIPT_UID+d]=f.name;g[n.CONSTANTS.PREFIX.COND+d]={inc:f.includes,match:f.matches,exc:f.excludes};g[n.CONSTANTS.PREFIX.SCRIPT+d]=f.textContent;r.setValues(g);h&&(ma.onScriptsChanged(),c?L.scriptAddedCb(f.name,f):L.scriptChangedCb(f.name,f,a));K.items.rundata.removeAll();K.items.regexp.remove(d);
return b},removeByUid:function(d,f){void 0===f&&(f=!0);var m=h.getByUid(d);r.deleteValue(n.CONSTANTS.PREFIX.SCRIPT_UID+d);r.deleteValue(n.CONSTANTS.PREFIX.COND+d);r.deleteValue(n.CONSTANTS.PREFIX.SCRIPT+d);r.deleteValue(n.CONSTANTS.PREFIX.META+d);r.deleteValue(n.CONSTANTS.PREFIX.STORE+d);f&&(ma.onScriptsChanged(),m.script&&m.cond&&(L.scriptRemovedCb(m.script.name,m.script),k.values&&M.tS(m.script.name,null,"r")));K.items.rundata.removeAll();K.items.regexp.remove(d);return{}},addStorageListener:function(e,
f,h,b,a){d.push({tabid:e,id:f,uuid:h,time:b,response:a})},removeStorageListeners:function(e,f){void 0===f&&(f=!0);var h=d;d=[];h.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):f&&b.response({})}catch(a){p.debug("sb: listener clear for script",e,"failed! Page reload?!")}})},notifyStorageListeners:function(e,f,h){e=e||{};f=f||{};d.forEach(function(b){try{void 0!==f.uuid&&b.uuid===f.uuid||void 0!==f.tabid&&b.tabid===
f.tabid||void 0!==f.id&&b.id===f.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||h&&h(b.response)}catch(a){p.warn("sb: listener notification for script",e,"failed! Page reload?!")}})}};return h}();scbr=A;var qa=function(){var d=function(){A.getUidList().forEach(function(d){var e=A.getByUid(d);e.script&&e.cond&&e.script.evilness!=I.SEVERITY_FOISTED_SCRIPT&&(p.warn("content security: found unfamiliar script",e.script.name),e.script.evilness=I.SEVERITY_FOISTED_SCRIPT,
u.doModify(d,e.script,!1),M.tS(e.script.name,e.script.fileURL||e.script.downloadURL||e.script.updateURL,"f"))})};return{init:function(){return m.Pledge()},check:function(){return m.Pledge()},onInstalled:function(){n.DB.SECURE||d()},onUpdated:function(){}}}(),za=function(){var w={ping:{allow:{insecure:!0},exec:function(a,c,b){b({pong:!0,instanceID:xa,config:{layout:k.values.layout,dark:rea.runtime.isDarkMode()}})}},newTab:{allow:{extpage:!0},exec:function(a,c,b){("options"==c.extpage||"options"==a.origin?
m.Pledge(c.tab):pa()).then(function(c){rea.tabs.create({url:a.url,parent:c},function(a){b({tabId:a.id})})})}},tabs:{allow:{script:!0},exec:function(a,c,b){"get"==a.action?c.tab&&a.uuid?b({data:na.get(c.tab.id,a.uuid)}):(p.warn("bg: unable to process request",c,a),b({data:null})):"list"==a.action?a.uuid?b({data:na.getAll(a.uuid)}):(p.warn("bg: unable to process request",c,a),b({data:null})):"set"==a.action?(c.tab&&a.uuid?na.set(c.tab.id,a.uuid,a.tab):p.warn("bg: unable to process request",c,a),b({})):
b({error:"unknown action"})}},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?(p.warn("bg:","refused to close last tab!"),b({error:"refused to close last tab!"})):rea.tabs.remove(d,function(){b({error:rea.runtime.lastError})})}):
b({error:"internal error"})}},setOption:{allow:{extpage:!0},exec:function(a,c,b){var d="options"==c.extpage||"options"==a.origin;k.setValue(a.name,a.value).always(function(){d?U.create("options.settings").done(function(a){b({items:a,options:k.snapshot})}).fail(function(a){b({error:a,options:k.snapshot})}):b({})})}},reportAnIssue:{allow:{extpage:!0},exec:function(a,c,b){("options"==c.extpage||"options"==a.origin?m.Pledge(c.tab):pa()).then(function(c){var d,e,f,h;if(a.uuid&&(d=A.getByUid(a.uuid))&&
d.script&&d.cond){e=u.determineOrigin(d.script);var k;if("hoster"==a.to&&e)f=e,h=[f.token,f.id].join(":");else if(k=d.script.supportURL||e.issue_url||e.url)f={issue_url:k},h=e?[a.to,e.token,e.id].join(":"):[a.to,f.url].join(":");f&&(M.tS(d.script.name,h,"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)ca.dialog.shown(a.extra);else if("clicked"==a.action){var d,e;a.extra&&(d=a.extra.amount,
e=a.extra.currency);ca.clicked(a.type,d,e)}else if(ca.button[a.action])ca.button[a.action](a.type,a.extra);else p.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=ua.framework.prepare(u,A,n.RUNTIME.BROWSER,n.RUNTIME.BROWSER_VERSION,c))&&p.error(c);else if("enabled"==
a.name)k.setValue(a.name,!k.values[a.name]).always(function(){b({})});else if("installFromUrl"==a.name)u.installFromUrl(a.data).always(function(){b({})});else if("externals_delete"==a.name)O.cleanElement(a.scriptuid,a.safe_url),U.create("options.scripts").done(function(a){b({items:a,options:k.snapshot})}).fail(function(a){b({error:a,options:k.snapshot})});else if("focus_tab"==a.name)w.focusTab.exec({},{tab:{id:a.tabid}},b);else if("run_script_updates"==a.name)if(a.scriptuid){var d;ba.check(!0,!1,
a.scriptuid).done(function(a){d=a}).always(function(){b({scriptuid:a.scriptuid,updatable:d})})}else ba.check(!0,!0),b({});else p.warn("bg: Warning: unknown button "+a.name),b({})}},loadTree:{allow:{extpage:!0},exec:function(a,c,b){U.create(a.referrer,{complete:a.complete,url:a.url,uuid:a.uuid,filter:a.filter,tabId:a.tabId}).done(function(a){a={items:a,i18n:k.values.i18n,options:k.snapshot,xhr:W.getConfig(),begging:ca.needed()};b(a)}).fail(function(a){b({error:a,options:k.snapshot})})}},modifyScriptOptions:{allow:{extpage:!0},
exec:function(a,c,b){if(a.uuid){var l="options"==c.extpage||"options"==a.origin,e=void 0==a.reload||1==a.reload,f=!1,h=A.getByUid(a.uuid,!0),m=function(){e?(void 0!==a.position&&u.reorderScripts(a.uuid,a.position),l?w.loadTree.exec({referrer:"options.scripts"},c,b):rea.tabs.getSelected(null,function(c){U.create("actions").done(function(a){b({items:a,i18n:k.values.i18n,options:{enabled:k.values.enabled}})}).fail(function(){b({i18n:k.values.i18n,options:{enabled:k.values.enabled}})});a.uuid&&k.values.autoReload&&
rea.tabs.sendMessage(c.id,{method:"reload",frameId:0},function(){})})):b({})};if(h.script&&h.cond)if(a.whitewash&&h.script.evilness==I.SEVERITY_FOISTED_SCRIPT)e=!0,h.script&&h.cond?u.doSave({uuid:a.uuid,src:h.script.textContent,force_settings:{enabled:!0},whitewash:!0,save:!0}).always(m):(p.error(d.getMessage("fatal_error")+" ("+a.uuid+")!!!"),m());else{var n=!1,v=new C.Script;Object.keys(v.options).forEach(function(c){void 0!==a[c]&&(h.script.options[c]=a[c],f|=!0===L.SYNCED[c])});Object.keys(v.options.override).forEach(function(c){-1!=
c.search("merge_")&&void 0!==a[c]&&(h.script.options.override[c]=a[c],n=!0)});["includes","excludes","matches"].forEach(function(c){void 0!==a[c]&&(n=!0,h.script.options.override["use_"+c]=a[c])});["connects","blockers"].forEach(function(c){void 0!==a[c]&&(h.script.options.override["use_"+c]=a[c])});a.add_excludes&&(h.script.options.override.use_excludes=h.script.options.override.use_excludes.concat(a.add_excludes),n=!0);n&&(h.script=u.mergeCludes(h.script));a.temp_connects&&ia.setSessionConnects(h.script.uuid,
a.temp_connects);void 0!==a.enabled&&(h.script.enabled=a.enabled);f&&(h.script.lastModified=Date.now());void 0!==a.file_url&&(h.script.downloadURL=a.file_url);u.doModify(h.script.uuid,h.script,f).done(m).fail(function(){b({})})}else b({})}else b({})}},saveScript:{allow:{extpage:!0},exec:function(a,c,b){var l=void 0===a.reload||!!a.reload,e=function(a){l?U.create("options.scripts").done(function(c){a.items=c;a.options=k.snapshot;b(a)}).fail(function(a){b({error:a,options:k.snapshot})}):b({})};if(a.clean){p.debug("bg: clean userscript "+
a.uuid);c=A.getByUid(a.uuid);var f=function(c){U.create("options.scripts").done(function(d){b({cleaned:c.installed,items:d,options:k.snapshot});c.installed&&A.notifyStorageListeners({uuid:a.uuid},null,function(c){c({storage:A.getStorageByUid(a.uuid)})})}).fail(function(a){b({error:a,options:k.snapshot})})};c.script&&c.cond?u.doSave({name:a.name,uuid:a.uuid,src:c.script.textContent,clean:!0,ask:!1,internal:!0,save:!0}).always(function(a){f(a||{installed:!1})}):(p.error(d.getMessage("fatal_error")+
" ("+a.uuid+")!!!"),f({installed:!1}))}else if(a.code){var h=b;l&&(h=function(a){u.reorderScripts();e(a)});a.new_script&&(a.uuid=y.createUUID());u.doSave({name:a.name,uuid:a.uuid,force_url:a.force_url,src:a.code,ask:!k.values.editor_easySave,lastModTime:a.lastModTime,save:!0}).always(function(a){h(a||{installed:!1})})}else a.auto_save||(u.doRemove(a.uuid),u.reorderScripts()),e({})}},saveExternal:{allow:{extpage:!0},exec:function(a,c,b){O.setElement(a.uuid,a.url,{content:a.code||"",meta:a.mimetype||
"text/javascript"},!0);U.create("options.scripts").done(function(a){b({success:!0,items:a,options:k.snapshot})}).fail(function(a){b({error:a,options:k.snapshot})})}},saveStorageKey:{allow:{extpage:!0},exec:function(a,c,b){f.saveStorageKey.exec(null,a,c,b)}},exportToJson:{allow:{extpage:!0},exec:function(a,c,b){u.exportToJson(a.ids,a.options).done(function(a){b({json:a})}).fail(function(){b({})})}},importFromJson:{allow:{extpage:!0},exec:function(a,c,b){var l=void 0===a.reload||!!a.reload;u.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};l&&!c.reload?U.create("options.scripts").done(function(a){c.items=a;c.options=k.snapshot;b(c)}).fail(function(a){b({error:a,options:k.snapshot})}):b(c)})}},download:{allow:{extpage:!0},exec:function(a,c,b){f.download.exec(null,a,c,function(a){(a.error||a.load)&&b(a)})}},askCom:{allow:{extpage:!0},exec:function(a,c,b){X.onMessage(a.data).always(function(a){a.i18n=k.values.i18n;a.options=k.snapshot;
a.ext={version:rea.extension.manifest.version};b(a)})}},installScript:{allow:{extpage:!0},exec:function(a,c,b){if(c.tab){var l={};u.installFromUrl(a.url,{},{silent_fail:!0}).done(function(a){l={data:null,found:!0,installed:a}}).fail(function(a){l.err=a&&a.messages&&a.messages.errors?a.messages.errors[0]:d.getMessage("Unable_to_parse_this_")}).always(function(){b(l)})}else p.warn("bg: Error: unable to install script due to empty tabID!")}},execMenuCmd:{allow:{extpage:!0},exec:function(a,c,b){(a=da.getById(a.id))?
a.response({run:!0,menuId:a.id}):p.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&&D.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=B.woHash(a.url);a.cleanup?(D.events.clean(c.tab.id,d,e),R.setIcon(c.tab.id),R.setBadge(c.tab.id),b({})):D.events.run(c.tab.id,d,a.id,e,function(d){d=d?Y.answer(d,a.url):{fast:!0};
b(d);R.setIcon(c.tab.id);R.setBadge(c.tab.id)})}else b({})}},notification:{allow:{script:!0,extpage:!0},exec:function(a,c,b){var d=a.image?a.image:P.images.brand("tampermonkey");(function(){var b=m();a.highlight&&c.tab?S.highlight(c.tab.id,b.resolve):b.resolve();return b.promise()})().then(function(){var c=m();a.text?S.show(a.title,a.text,d,{timeout:a.timeout,silent:a.silent},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:u.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,k.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 e;if("off"!=k.values.external_connect&&
(e=c.url)&&T.isAllowed(e)){for(var f,h,m,w=Object.keys(b.externally_connectable),n=0;n<w.length;n++)if(f=w[n],c=b.externally_connectable[f],(h=u.regexify({match:[f]}))&&u.validUrl(e,h)&&(-1!=c.indexOf("*")||-1!=c.indexOf(a.method))){m=!0;break}if(m)if("getVersion"==a.method)d({version:rea.extension.manifest.version,id:rea.runtime.short_id});else if("all"!=k.values.external_connect)p.warn("mh: calling external method "+a.method+" is not permitted to "+e+" by the user");else if("isInstalled"==a.method){var v,
q,r,y;e=!1;h=a.script.name;(q=A.getUidsByName(h,a.script.namespace)[0])&&(v=A.getByUid(q))&&v.script&&(e=!0,y=v.script.enabled,r=v.script.version);d({name:h,installed:e,enabled:y,version:r})}else p.warn("mh: unknown external method "+a.method);else p.warn("mh: calling external method "+a.method+" is not permitted to "+e)}}},cookie:{allow:{script:!0},exec:function(a,c,b){var d="expirationDate domain httpOnly secure session name path sameSite value".split(" ").concat(["url"]),e=d.concat(["hostOnly"]);
c=a.url||c.url||null;c=a.details.url?B.sanitize(a.details.url,c)||a.details.url:c;if(n.DB.SECURE||"dhdg"!=rea.runtime.short_id)if(c)if(T.isAllowed(B.woHash(c)))if(u.scriptWillRun(a.uuid,c))if("list"==a.action)ra.getAll({url:c,domain:a.details.domain,name:a.details.name,path:a.details.path}).done(function(a){a=a.map(function(a){var c={};e.forEach(function(b){c[b]=a[b]});return c});b({data:{cookies:a}})});else if("delete"==a.action)ra.remove({url:c,name:a.details.name}).done(function(){b({data:{success:!0}})}).fail(function(a){b({data:{error:a}})});
else if("set"==a.action){var f={},h=a.details;d.forEach(function(a){void 0!==h[a]&&(-1!=["value","name"].indexOf(a)?f[a]=String(h[a]):f[a]=h[a])});f.url=f.url||c;ra.set(f).done(function(){b({data:{success:!0}})}).fail(function(a){b({data:{error:a}})})}else b({data:{error:"unknown action"}});else b({data:{error:"the URL needs to be included by the scripts @include or @match tag"}});else b({data:{error:"the URL is filtered by the security settings"}});else b({data:{error:"invalid URL"}});else b({data:{error:"not supported"}})}},
api:{allow:{script:!0},exec:function(a,c,b){M.tA(a.name,a.type);b()}}},h=function(a){var c=rea.runtime.id,c=!n.REQUESTS.HAS_SENDER_ID&&a.tab||a.id===c,b=null,d=n.REQUESTS.INTERNAL_PAGE_PROTOCOLS[0],d=d?d+"//":null,e=n.REQUESTS.GET_INTERNAL_PAGE_REGEXP();a=a.url?a.url:a.tab?a.tab.url:null;var f=c&&(!a||(d?0==a.search(d):!1));if(f||!d)a?(e=a.match(e))&&2==e.length&&(b=e[1]):b="*",!d&&b&&(f=!0);return{id_valid:c,url:a,page:b,extpage:f}},e=function(a,c,b){if(!G.late)return G.registerLateCallback(function(){e(a,
c,b)}),!0;var d=w[a.method];if(!d)return p.warn("mh: unknown method "+a.method),!1;if(!d.allow||!d.exec)return p.warn("mh: invalid implementation of "+a.method),!1;var f=h(c),k=f.extpage,m=f.page,f=f.id_valid;k?c.extpage=m:delete a.origin;var n="options"==m,q=!0;if("background"==m||d.allow.insecure||d.allow.extpage&&k||d.allow.options&&n||d.allow.script&&f&&!k){if(d=d.exec(a,c,function(a){q=!1;b(a)}),!1!==q&&!1!==d)return!0}else return!1===a.topframe&&(k||n)||p.warn("mh: this context doesn't have the permission to call \""+
a.method+'"'),!1},f={xhr:{allow:{script:!0},exec:function(a,c,b,d){var e=!1,f=function(){a.disconnect()};c.details.convertBinary=!0;c.details.partialSize=c.details.partialSize||n.XMLHTTPREQUEST.PARTIAL_SIZE;var h={};Object.keys(c.callbacks).forEach(function(a){var b="ondone"===a;if(c.callbacks[a]||b||"onload"===a)h[a]=function(c){c={data:c.response,exception:c.exception};c[a]=!0;d(c);b&&f()}});h.ondone||(h.ondone=f);var w;c.details.url=B.sanitize(c.details.url,c.url||b.url||null)||c.details.url;n.RUNTIME.WEBREQUEST_XHR_SUPPORT&&
"no"!=k.values.webrequest_modHeaders&&(c.details.headers=c.details.headers||{},c.details.headers.internal=c.uuid,n.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?ra.getAll({url: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(!e){var a;if(c.details.url&&(a=B.parse(c.details.url).protocol)&&-1!=["file:"].concat(n.REQUESTS.INTERNAL_PAGE_PROTOCOLS).indexOf(a)){var d=function(a){var b='Refused to connect to "'+c.details.url+'": '+a,d=W.makeErrorResponse(b);["onerror","ondone"].forEach(function(a){if(h[a])h[a]({response:d,exception:b})})};if("file:"==a){var f,l;n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS&&("all"==k.values.script_file_access?f=!0:"externals"==
k.values.script_file_access&&(l=A.getByUid(c.uuid))&&l.script&&l.cond&&-1!=[].concat(l.script.resources).concat(l.script.requires).map(function(a){return B.sanitize(a.unsafe_url,a.abs_url)}).indexOf(c.details.url)&&(f=!0));if(!f)return d("Access to this local file is forbidden!")}rea.file.get(c.details.url,function(a){var c={response_data:H.arrbuf2str(a),readyState:4,responseHeaders:"",status:0,statusText:""};["onload","ondone"].forEach(function(a){if(h[a])h[a]({response:c})})},d)}else w=ia.exec(c.details,
c.uuid,b||{},h)}});return function(){e=!0;w&&w.abort()}}},download:{allow:{script:!0},exec:function(a,c,b,d){c=c.details;c.internal=null===a;var e=J.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&&(J.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)&&ha.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,b,d,e){d.tab?b.uuid&&(a=A.getStorageByUid(b.uuid),a.data[b.key]=
b.value,a.ts=b.ts,A.setStorageByUid(b.uuid,a),A.notifyStorageListeners({uuid:b.uuid},{id:b.id},function(a){var d={data:{},ts:0};d.data[b.key]=b.value;d.ts=b.ts;var g={storage:d};void 0===d.data[b.key]&&(g.removed=b.key);a(g)})):p.warn("storage: unable to save storage due to empty tabID!");e({})}},openInTab:{allow:{script:!0},exec:function(a,b,d,e){var f=["active"],h={url:b.details.url},k=null;if(b=b.details.options){for(var m=0;m<f.length;m++)void 0!==b[f[m]]&&(h[f[m]]=b[f[m]]);b.insert&&(h.index=
d.tab.index+1);b.setParent&&(h.parent=d.tab)}rea.tabs.create(h,function(b){k=b.id;a&&(fa[k]={onClose:function(){a&&e({closed:!0})}},e({success:!0,tabId:k}))});a.onMessage.addListener(function(a){if(null!==k)if(a.close)rea.tabs.remove(k,function(){var a=rea.runtime.lastError;a?p.warn("tab.close",a.message):k=null});else if(void 0!==a.name){var b=3,c=function(){D.listeners.once.whenReady(k,function(){rea.tabs.sendMessage(k,{method:"setForeignAttr",attr:"name",value:a.name},function(d){d?e({name:a.name}):
0<b--?c():p.warn("foreignAttr: error setting attr")})})};c()}});return function(){null!==k&&delete fa[k];a=null}}},registerMenuCommand:{allow:{script:!0},exec:function(a,b,d,e){if(d.tab)return da.add(d.tab.id,b.name,b.uuid,b.accessKey,b.menuId,e),N.actionPage("update"),function(){da.clearById(b.menuId);N.actionPage("update")};p.warn("Unable to register menu cmd due to empty tabID!");a.disconnect()}},tabWatch:{allow:{extpage:!0},exec:function(a,b,d,e){var f=va.openAndWatch({url:b.url,index:(d.tab.index||
0)+1,parent:d.tab},function(b){b?e({tab:b}):(h(),a.disconnect())}),h=function(){f.cancel()};return h}}},q=function(){var a=function(a,b){var d=a.sender,e=f[b.method];if(!e)return p.warn("mh: unknown method "+b.method),!1;if(!e.allow||!e.exec)return p.warn("mh: invalid implementation of "+b.method),!1;var k=h(d),m=k.extpage,w=k.page,n="options"==w,k=k.id_valid&&!m;if("background"==w||e.allow.insecure||e.allow.extpage&&m||e.allow.options&&n||e.allow.script&&k)(d=e.exec(a,b,d,function(b){try{a.postMessage(b)}catch(d){p.debug("bg: Error sending port ("+
a.name+") message",b)}}))&&a.onDisconnect.addListener(d);else return!1===b.topframe&&(m||n)||p.warn("mh: this context doesn't have the permission to call \""+b.method+'"'),!1};return function(b){G.late?b.onMessage.addListener(function(d){void 0!==d.method&&a(b,d)}):G.registerLateCallback(function(){q(b)})}}(),b={init:function(){b.externally_connectable_reg=u.regexify({match:Object.keys(b.externally_connectable)});rea.extension.onMessage.addListener(e);rea.extension.onConnect.addListener(q);rea.extension.onConnectExternal.addListener(function(a){a.disconnect()})},
externally_connectable:{"*://www.tampermonkey.net/*":["getVersion"],"https://greasyfork.org/*":["*"],"https://userstyles.org/*":["*"]}};return b}(),ra=function(){return{getAll:function(d){var h=m();rea.cookies.getAll(d,h.resolve);return h.promise()},remove:function(d){var h=m();rea.cookies.remove(d,function(d){d?h.resolve():h.reject(rea.runtime.lastError||"unknown error")});return h.promise()},set:function(d){var h=m();rea.cookies.set(d,function(d){d?h.resolve():h.reject(rea.runtime.lastError||"unknown error")});
return h.promise()}}}(),da=function(){var d=[];return{add:function(h,e,f,k,b,a){d.push({tabId:h,name:e,uuid:f,accessKey:k,id:b,response:a})},list:function(){return d},listByTabId:function(h){var e={};return d.filter(function(d){var k=d.uuid+d.name;return d.tabId==h&&!e[k]&&(e[k]=!0)})},clearByTabId:function(h){d=d.filter(function(d){return d.tabId!=h})},getByTabId:function(h){return d.filter(function(d){return d.tabId==h})[0]},clearById:function(h){d=d.filter(function(d){return d.id!=h})},getById:function(h){return d.filter(function(d){return d.id==
h})[0]}}}(),Ka=function(){return{create:function(){var m,h,e,f,q,b,a,c,g,l,x,t,z;g=null;m={id:"general",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:k.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:k.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://www.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:k.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:!!k.values.statistics_enabled,validation:{image:"info",opacity:.9,msg:d.getMessage("Allow_Tampermonkey_to_collect_anonymous_statistics_via_Google_Analytics"),url:"https://www.tampermonkey.net/privacy.php#extension"}});m.items.push({name:d.getMessage("Debug_scripts"),level:100,id:"debug",option:!0,checkbox:!0,enabled:k.values.debug,desc:""});m.items.push({name:d.getMessage("Show_fixed_source"),
level:100,id:"showFixedSrc",option:!0,checkbox:!0,enabled:k.values.showFixedSrc,desc:""});m.items.push({name:d.getMessage("LogLevel"),id:"logLevel",level:0,option:!0,select:[].concat(n.RUNTIME.SAFARI?[{name:d.getMessage("Verbose"),value:80}]:[]).concat([{name:d.getMessage("Debug"),value:60},{name:d.getMessage("Warning"),value:30},{name:d.getMessage("Error"),value:0}]),value:k.values.logLevel,desc:""});x={id:"script_sync",name:d.getMessage("Script_Sync"),sub_menu_item:!0,level:50,need_save:!0,items:[]};
x.items.push({name:d.getMessage("Enable_Script_Sync"),id:"sync_enabled",level:50,option:!0,checkbox:!0,enabled:k.values.sync_enabled,desc:d.getMessage("Synchronize_your_scripts_across_browsers_and_operation_systems")});h=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:F.types.eCHROMESYNC,enable:b});a.push({name:d.getMessage("Google_Drive"),value:F.types.eGDRIVE,enable:b});n.RUNTIME.CHROME&&37>
n.RUNTIME.BROWSER_VERSION||n.RUNTIME.SAFARI&&8>n.RUNTIME.BROWSER_VERSION||n.RUNTIME.DOLPHIN?p.info("Script Sync: no Dropbox support due to missing SHA-256 capabilities"):a.push({name:d.getMessage("Dropbox"),value:F.types.eDROPBOX,enable:b});a.push({name:d.getMessage("OneDrive"),value:F.types.eONEDRIVE,enable:b});n.RUNTIME.SAFARI||(a.push({name:d.getMessage("Yandex_Disk"),value:F.types.eYANDEX,enable:b}),a.push({name:d.getMessage("WebDAV"),value:F.types.eWEBDAV,enable:{reset_sync:!0,cloud_url:!0,cloud_user:!0,
cloud_pass:!0}}));return a}();x.items.push({name:d.getMessage("Sync_Type"),id:"sync_type",enabler:!0,level:50,option:!0,select:h,value:k.values.sync_type});x.items.push({name:d.getMessage("URL"),id:"cloud_url",enabledBy:"sync_type",level:50,option:!0,text:!0,width:2,value:k.values.cloud_url});x.items.push({name:d.getMessage("Login"),id:"cloud_user",enabledBy:"sync_type",level:50,option:!0,text:!0,width:2,value:k.values.cloud_user});x.items.push({name:d.getMessage("Password"),id:"cloud_pass",enabledBy:"sync_type",
level:50,option:!0,text:!0,password:!0,width:2,value:k.values.cloud_pass});x.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_")});q={id:"ppearance",name:d.getMessage("Appearance"),sub_menu_item:!0,need_save:!0,items:[],warning:d.getMessage("A_reload_is_required"),reload:!0};q.items.push({name:d.getMessage("Layout"),id:"layout",level:0,option:!0,select:P.getLayouts(),
value:k.values.layout,desc:""});q.items.push({name:d.getMessage("Custom_CSS"),id:"layout_user_css",level:100,option:!0,input:!0,value:k.values.layout_user_css,desc:d.getMessage("You_can_add_your_custom_CSS_rules_here_")});g={};"off"==k.values.notification_showUpdate&&(g={image:"critical",msg:d.getMessage("Are_you_sure_that_you_don_t_want_to_be_notified_of_updates_")});q.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:k.values.notification_showUpdate,validation:g});q.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:k.values.favicon_service});
b={id:"action_menu",name:d.getMessage("Action_Menu"),sub_menu_item:!0,need_save:!0,items:[],level:50};b.items.push({name:d.getMessage("Hide_disabled_scripts"),id:"action_menu_scripts_hide_disabled",level:100,option:!0,checkbox:!0,enabled:k.values.action_menu_scripts_hide_disabled,desc:""});b.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:k.values.action_menu_columns});
b.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:k.values.action_menu_scripts_sort});b.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:k.values.appearance_badges});(n.RUNTIME.CHROME||n.RUNTIME.FIREFOX)&&b.items.push({name:d.getMessage("Icon_badge_color"),id:"appearance_badge_color",level:100,color:!0,value:k.values.appearance_badge_color});h={id:"editor",name:d.getMessage("Editor"),sub_menu_item:!0,level:20,need_save:!0,items:[],warning:d.getMessage("A_reload_is_required"),reload:!0};
h.items.push({name:d.getMessage("Enable_Editor"),id:"editor_enabled",level:100,option:!0,checkbox:!0,enabled:k.values.editor_enabled,desc:""});h.items.push({name:d.getMessage("Theme"),id:"editor_theme",level:50,option:!0,select:P.getEditorThemes(),value:k.values.editor_theme});h.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:k.values.editor_fontSize});h.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:k.values.editor_keyMap});h.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:k.values.editor_indentUnit,desc:""});h.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:k.values.editor_indentWithTabs,desc:""});h.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:k.values.editor_tabMode,desc:""});h.items.push({name:d.getMessage("Line_break"),id:"editor_lineWrapping",level:50,option:!0,checkbox:!0,enabled:k.values.editor_lineWrapping,
desc:""});h.items.push({name:d.getMessage("Reindent_on_typing"),id:"editor_electricChars",level:50,option:!0,checkbox:!0,enabled:k.values.editor_electricChars,desc:""});h.items.push({name:d.getMessage("Enable_autoSave"),id:"editor_autoSave",level:20,option:!0,checkbox:!0,enabled:k.values.editor_autoSave,desc:""});h.items.push({name:d.getMessage("Enable_easySave"),id:"editor_easySave",level:20,option:!0,checkbox:!0,enabled:k.values.editor_easySave,desc:""});h.items.push({name:d.getMessage("Highlight_trailing_whitespace"),
id:"editor_highlightTrailingWhitespace",level:50,option:!0,checkbox:!0,enabled:k.values.editor_highlightTrailingWhitespace,desc:""});h.items.push({name:d.getMessage("Trim_trailing_whitespace_from_modified_lines"),id:"editor_trimTrailingSpacesFromModifiedLines",level:50,option:!0,checkbox:!0,enabled:k.values.editor_trimTrailingSpacesFromModifiedLines,desc:""});h.items.push({name:d.getMessage("Auto_syntax_check_on_typing"),id:"editor_autoLint",level:50,option:!0,checkbox:!0,enabled:k.values.editor_autoLint,
desc:d.getMessage("Enable_this_option_to_automatically_check_the_code_on_typing_")});h.items.push({name:d.getMessage("Auto_syntax_check_max_length"),id:"editor_autoLintMaxLen",level:50,option:!0,text:!0,value:k.values.editor_autoLintMaxLen,desc:d.getMessage("Check_only_scripts_up_to_this_size_automatically_")});h.items.push({name:d.getMessage("Custom_Linter_Config"),id:"editor_linter_config",level:100,option:!0,input:!0,json:!0,value:k.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"}});f={id:"script_update",name:d.getMessage("Script_Update"),sub_menu_item:!0,level:0,items:[]};f.items.push({name:d.getMessage("Check_disabled_scripts"),id:"scriptUpdateCheckDisabled",level:0,option:!0,checkbox:!0,enabled:k.values.scriptUpdateCheckDisabled,desc:""});f.items.push({name:d.getMessage("Dont_ask_me_for_simple_script_updates"),id:"notification_silentScriptUpdate",level:80,
option:!0,checkbox:!0,enabled:k.values.notification_silentScriptUpdate,desc:""});f.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:k.values.scriptUpdateCheckPeriod,desc:""});f.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:k.values.scriptUpdateHideNotificationAfter,desc:""});e={id:"externals",name:d.getMessage("Externals"),sub_menu_item:!0,level:0,items:[]};e.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:k.values.external_update_interval,desc:""});a={id:"security",name:d.getMessage("Security"),sub_menu_item:!0,need_save:!0,level:50,items:[]};n.OPTIONS.HAS_CSP&&(a.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:k.values.webrequest_fixCSP,desc:d.getMessage("Tampermonkey_might_not_be_able_to_provide_access_to_the_unsafe_context_when_this_is_disabled")}),a.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:k.values.webrequest_modHeaders,warning:d.getMessage("Tampermonkey_needs_to_be_restarted_to_make_this_change_apply_Do_you_want_to_continue_"),desc:""}));n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS&&a.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:k.values.script_file_access});
a.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:k.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_")});
a.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:k.values.require_sri_mode,desc:d.getMessage("Script_authors_can_secure_external_resources_by_adding_a_SRI_hash_to_the_URL_")});a.items.push({name:d.getMessage("connect_mode"),id:"connect_mode",
level:50,option:!0,select:(80<=k.values.configMode||-1!=["off","casual"].indexOf(k.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:k.values.connect_mode,desc:""});n.RUNTIME.INCOGNITO_MODE&&!rea.extension.inIncognitoContext&&(g="temporary"==k.values.incognito_mode?{}:{image:"critical",
msg:"Permanent mode is still a BETA feature!"},a.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:k.values.incognito_mode,validation:g}));a.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:k.values.page_filter_mode,desc:""});a.items.push({name:d.getMessage("Whitelisted_Pages"),id:"page_whitelist",level:50,option:!0,input:!0,array:!0,value:k.values.page_whitelist,desc:""});a.items.push({name:d.getMessage("Blacklisted_Pages"),id:"forbiddenPages",level:50,option:!0,input:!0,array:!0,value:k.values.forbiddenPages,desc:""});c={id:"blackcheck",name:d.getMessage("BlackCheck"),sub_menu_item:!0,need_save:!0,level:50,items:[]};
c.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:k.values.script_blacklist_type});c.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:I.SEVERITY_MAX}],value:k.values.script_blacklist_severity});c.items.push({name:d.getMessage("Manual_Script_Blacklist"),id:"require_blacklist",level:50,option:!0,input:!0,
array:!0,value:k.values.require_blacklist,desc:""});if(n.OPTIONS.CAN_DOWNLOAD){var r=!1;g={};y.map("exe sh crx com bat scr".split(" "),function(a){return"name."+a}).forEach(function(a){r|=J.is_whitelisted(a)});r&&(g={image:"critical",msg:d.getMessage("Your_whitelist_seems_to_include_executable_files_This_means_your_userscripts_may_download_malware_or_spyware_to_your_harddisk_")});z={id:"downloads",name:d.getMessage("Downloads")+" BETA",sub_menu_item:!0,need_save:!0,level:50,items:[]};z.items.push({name:d.getMessage("Download_Mode"),
id:"downloads_mode",level:50,option:!0,select:y.select([{name:d.getMessage("Default"),value:J.staticVars.DEFAULT},{name:d.getMessage("Disabled"),value:J.staticVars.OFF},{name:d.getMessage("Native"),value:J.staticVars.NATIVE},{name:d.getMessage("Browser_API"),value:rea.downloads.supported?J.staticVars.CHROME:null}],function(a){return a.value}),value:k.values.downloads_mode,desc:d.getMessage("The_Browser_API_mode_requires_a_special_permission_")});z.items.push({name:d.getMessage("Whitelisted_File_Extensions"),
id:"downloads_extension_whitelist",level:50,option:!0,input:!0,array:!0,value:k.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:g})}l={id:"experimental",name:d.getMessage("Experimental"),sub_menu_item:!0,level:80,items:[]};n.RUNTIME.FAST_EXEC_SUPPORT&&(g="fast"==k.values.runtime_inject_mode?{image:"critical",msg:"This might cause higher CPU usage!"}:
{},l.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:k.values.runtime_inject_mode,validation:g}));l.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:k.values.runtime_strict_mode});rea.webRequest.filterResponseData&&n.OPTIONS.HAS_CSP&&l.items.push({name:d.getMessage("Add_Tampermonkey_to_the_site_s_content_csp"),id:"webrequest_fixContentCSP",level:80,option:!0,select:[{name:d.getMessage("Yes"),value:"yes"},{name:d.getMessage("No"),value:"no"}],value:k.values.webrequest_fixContentCSP,warning:"Warning: enabling this option is may break pages!"});g={id:"userscripts",name:d.getMessage("Userscripts"),sub_menu_item:!0,need_save:!0,
level:80,items:[]};g.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:k.values.scriptUrlDetection});g.items.push({name:d.getMessage("New_script_template_"),id:"script_templates",level:80,option:!0,input:!0,array:!0,named:!0,value:k.values.script_templates});t={id:"reset",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_")});ua&&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,q,b,f,e,void 0,x,void 0,void 0,
h,a,c,z,g,l,t].filter(function(a){return!!a})}}}(),U=function(){return{create:function(w,h){w=w||"";h=h||{};var e=function(b){return m.onebyone(b).fail(function(){p.warn("tree: wait failed!")}).then(function(a){return a.filter(function(a){return a})})},f=function(b,a){for(var c=b.replace(/\.$/,"").split("."),d=q;c.length;){var e=c.shift();if(d[e]){if("function"===typeof d[e])return function(){return d[e](h,!a)};d=d[e];c.length||c.unshift("root")}else return p.warn("tree: unable to find",b,h),function(){return m.Pledge([])}}p.warn("tree: unable to find",
b,h);return function(){return m.Pledge([])}},q={actions:{root:function(b){var a=m();rea.tabs.getSelected(null,function(c){c&&0<=c.id?h.tab=c:b.tabId&&(h.tab={id:b.tabId,url:null});c=e([f("actions.general"),f("actions.scripts"),f("actions.commands")]);a.consume(c)});return a.promise()},general:function(){var b=h.tab,a=b?b.url:null,c=a&&4<a.length&&""==a.substr(0,4).replace(/file|http/,"")?a:"",g=[],b={name:"enabled",sub_menu_item:!0,pos:"top",items:[],tabId:b?b.id:null};b.items.push({name:d.getMessage("Enabled"),
display:k.values.enabled?null:"greyed",id:"enabled",button:!0,reload:!0,enabler:!0});b.items=b.items.concat(N.actionStatus().map(function(a){return{options:a,globalhint:!0}}));g.push(b);var e;!oa.isScriptUrl(a,!0)||(e=oa.isScriptUrl(a))&&"manual"!=k.values.scriptUrlDetection||b.items.push({name:e?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="+H.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://www.tampermonkey.net/faq.php?"+c,newtab:!0},{name:" "+d.getMessage("Changelog"),url:"https://www.tampermonkey.net/changelog.php?"+c,newtab:!0}]});g.push(a);return m.Pledge(g)},
scripts:{root:function(b){var a=h.tab,c=a?a.url:null,g=[],e=c?B.parse(c):null,e=e&&-1!=["http:","https:","file:"].indexOf(e.protocol)?B.woHash(e):"",f,n={name:"scripts",sub_menu_item:!0,pos:"center",items:[]},p=Y.getContexters(!0,null),w={},q={},v={},r={},la={};a&&[u.getUniqueScriptsForTab(a),u.getScriptHistoryForTab(a)].forEach(function(a,b){var c;Object.keys(a).forEach(function(g){var e=a[g];b?(w[g]=e.urls,q[g]=e.count,v[g]=e.all_time,(c=r[g])||(e=A.getByUid(g),r[g]=e.script&&e.cond?c=e.script:
c={uuid:g,name:d.getMessage("This_script_was_deleted"),enabled:!0,deleted:!0}),la[g]="a"+c.name.toLowerCase()+c.position):(r[g]=c=e.script,la[g]="z"+c.name.toLowerCase()+c.position)})});var ya;ya="position"==k.values.action_menu_scripts_sort?function(a,b){return a.position-b.position}:"name"==k.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"==k.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 la[a.uuid].localeCompare(la[b.uuid])};var r=y.values(r).sort(ya),p=ta([].concat(r).concat(p),{active_urls:w,active_counts:q,all_time_active_counts:v}),D=a?La(a.id):{};k.values.action_menu_scripts_hide_disabled&&(p=p.filter(function(a){return a.enabled||q[a.uuid]}));p.forEach(function(a){var b;if(b=D[a.uuid])a.menu_cmds=b});!k.values.action_menu_scripts_hide_disabled&&2<Math.min(k.values.action_menu_columns,(b?b.available_columns:
null)||99)?(f={name:"scripts_right",sub_menu_item:!0,pos:"right",items:[]},p.forEach(function(a){(a.enabled||q[a.uuid]?n:f).items.push(a)}),g.push(n),f.items.length&&g.push(f)):(f=n,n.items=n.items.concat(p),g.push(n));k.values.enabled&&!p.length&&c&&(T.isAllowed(c)?n.items.push({name:d.getMessage("No_script_is_running"),image:"no_script"}):n.items.push({name:d.getMessage("This_page_is_blacklisted_at_the_security_settings"),image:"critical"}));b=d.getLocale();k.values.enabled&&(p.length?(a={name:"scripts_new",
sub_menu_item:!0,pos:"center",items:[]},g.push(a)):a=n,a.items.push({name:d.getMessage("Get_new_scripts___"),image:"script_search",url:"https://www.tampermonkey.net/scripts.php"+(b?"?locale="+b:""),newtab:!0}),a.items.push({name:d.getMessage("Add_new_script___"),image:"script_add",url:rea.extension.getURL("options.html")+"#url="+H.Base64.encode(e)+"&nav=new-user-script",newtab:!0}));return m.Pledge(g)}},commands:function(){var b=[],a=d.getLocale(),c={name:"commands",id:"commands",sub_menu_item:!0,
pos:"left",items:[]};c.items.push({name:d.getMessage("Check_for_userscripts_updates"),id:"run_script_updates",button:!0,image:"update"});80<=k.values.configMode&&c.items.push({name:d.getMessage("Report_a_bug"),image:"bug",url:"https://www.tampermonkey.net/bug",newtab:!0});n.RUNTIME.SAFARI||c.items.push({name:d.getMessage("Please_consider_a_contribution"),image:"contrib",url:"https://www.tampermonkey.net/contrib.php?src=a"+(a?"&locale="+a:""),newtab:!0});b.push(c);return m.Pledge(b)}},options:{root:function(){return e([f("options.general"),
f("options.verification"),f("options.scripts"),f("options.settings")])},general:function(){var b,a=[];a.push({name:"Version",id:null,version:!0,value:rea.extension.manifest.version});rea.extension.inIncognitoContext&&"temporary"==k.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=N.optionsStatus().map(function(a){return{options:a,globalhint:!0}}))&&b.length?a=a.concat(b):(b=ga.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=[];ka.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(),g={name:d.getMessage("Installed_userscripts"),main_menu_item:!0,
scriptTab:!0,id:"dashboard"};(function(){if(b.complete||!a)return e(y.map(["options.scripts.userscripts","options.scripts.new"],function(a){return f(a)}));g.referrer="options.scripts";g.partial=!0;return e([f("options.scripts.new")])})().done(function(a){g.items=a;c.resolve([g])}).fail(c.reject);return c.promise()},"new":function(){var b=[];b.push({name:d.getMessage("New_userscript"),id:null,image:"script_add",icon:P.images.origin("unknown"),nnew:!0,uuid:"new-user-script",position:-1,positionof:n.RUNTIME.MAX_SCRIPTS,
enabled:!0,userscript:!0});return m.Pledge(b)},userscripts:{root:function(b,a){var c=b.complete||!a?null:"options.scripts.userscripts",c=ta(u.determineScriptsToRun(null),{options_page:!0,referrer:c}),g=c.length,e=d.getLocale();c.push({name:d.getMessage("No_script_is_installed"),image:"info",visible:!g});c.push({name:d.getMessage("Get_some_scripts___"),image:"edit_add",url:"https://www.tampermonkey.net/scripts.php"+(e?"?locale="+e:""),newtab:!0,visible:!g});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=k.values.showFixedSrc?ja.mkCompat(b.script.textContent,b.script,"off"!=k.values.runtime_strict_mode):b.script.textContent,m.Pledge([b]);p.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||B.sanitize(a.unsafe_url,a.abs_url);if(a==b.url&&(a=O.getElement(b.uuid,a))&&a.data&&a.data.content)return c=a.data.content,!0});return m.Pledge([c])}p.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(Ka.create()):(e.referrer="options.settings",f=m.Pledge());f.done(function(a){e.items=a;c.resolve([e])}).fail(c.reject);return c.promise()}}};p.debug("tree: loading",w,h);return f(w,!0)()}}}(),La=function(d){var h={};d=null==d||void 0==d?da.list():da.listByTabId(d);for(var e in d)if(d.hasOwnProperty(e)){var f=d[e];(h[f.uuid]=h[f.uuid]||[]).push({name:f.name,uuid:f.uuid,id:f.id,accessKey:f.accessKey,image:"menu_cmd",menucmd:!0})}return h},
ta=function(m,h){var e=[];h=h||{};var f=new C.Script;["author","copyright"].forEach(function(d){f[d]=!1});Object.keys(m).forEach(function(n){var b=m[n],a;if(h.options_page){a={};var c=["textContent","requires","resources"];Object.keys(f).forEach(function(d){-1==c.indexOf(d)&&(y.toType(f[d]),a[d]=b[d])});h.referrer?(a.referrer=h.referrer,a.length=b.textContent.length):a.code=b.textContent;["requires","resources"].forEach(function(c){a[c]=y.map(b[c],function(a){var d=a.url||B.sanitize(a.unsafe_url,
a.abs_url),e=O.getElement(b.uuid,d),f=0,k=null,m=null,n,p,w,q;e&&e.data&&(e.data.content&&(q=e.data.content,f=q.length),m=e.data.sri,k=e.ts,n=e.modified,w=e.data.meta||"text/plain",p="requires"==c||/text\/.*|application\/(?:x-)?(?:java|ecma)script/.test(w));return{display_url:a.url||a.unsafe_url,abs_url:a.abs_url,unsafe_url:a.unsafe_url,url:d,data:{length:f,content:h.externals?q:void 0},sri:m,ts:k,mimetype:w,editable:p,modified:n}})});a.origin=u.determineOrigin(b);a.contexter=u.isContexter(b);a.temp_connects=
ia.getSessionConnects(b.uuid);n=A.getStorageByUid(b.uuid);a.storage_key_count=Object.keys(n.data).length;a.remote_url=L.getSyncRemoteUrl(b);a.lastUpdated=b.lastUpdated}else n=u.determineOrigin(b),a={name:b.name,name_i18n:b.name_i18n,uuid:b.uuid,system:b.system,support:!!b.supportURL||n&&!!n.issue_url,abuse:n&&!!n.abuse_url,active_urls:(h.active_urls||{})[b.uuid],active_count:(h.active_counts||{})[b.uuid],all_time_active_count:(h.all_time_active_counts||{})[b.uuid],referrer:h.referrer,contexter:u.isContexter(b),
enabled:b.enabled,position:b.position,deleted:b.deleted};b.evilness&&(b.evilness==I.SEVERITY_FOISTED_SCRIPT?a.foisted=d.getMessage("The_origin_of_this_script_cant_be_determined_"):b.evilness>=Math.min(I.SEVERITY_MAX,k.values.script_blacklist_severity)&&(a.blacklisted=d.getMessage("This_script_is_blacklisted_")));b.evilness&&(a.warnings=I.getWarningsFor(u.determineSourceURL(b)));a.file_url=b.downloadURL||b.fileURL;a.positionof=m.length;a.userscript=!0;b.icon64||b.icon||(a.icon64=P.images.origin("unknown"));
b.options&&Object.keys(f.options).forEach(function(c){a[c]=b.options[c]});e.push(a)});return e},V={run:function(d,h){var e=1,f=function(){0==--e&&(h&&h(),rea.page.reload())};if("config"==d){var k=r.listValues();Object.keys(k).forEach(function(b){b=k[b];-1==b.search(n.CONSTANTS.PREFIX.SCRIPT)&&-1==b.search(n.CONSTANTS.PREFIX.COND)&&-1==b.search(n.CONSTANTS.PREFIX.STORE)&&-1==b.search(n.CONSTANTS.PREFIX.META)&&(e++,r.deleteValue(b).always(f))})}else"factory"==d&&(e++,J.remove_permission().done(f),e++,
r.factoryReset().always(f));f()},reset:function(d){V.run(null,d)},factoryReset:function(d){V.run("factory",d)},configReset:function(d){V.run("config",d)}},R=function(){var m=function(){rea.runtime.lastError&&void 0},h={init:function(){h.setIcon();var d=k.values.appearance_badge_color||"#ee3131";"#"!==d[0]&&(d="#"+d);rea.browserAction.setBadgeBackgroundColor({color:d})},setIcon:function(e){var f,h;h=null;var b=f=!1;void 0===e||D.get.empty(e)||(f=D.get.blocker(e),b=D.get.forbidden(e));b?(f="_forbidden",
h=d.getMessage("At_least_one_part_of_this_page_is_listed_at_the_forbidden_pages_setting_")):f?(f="_blocker",h=d.getMessage("Some_scripts_might_be_blocked_by_the_javascript_settings_for_this_page_or_a_script_blocker_")):f=k.values.enabled&&void 0!==e?"":"_grey";p.debug("badge: set icon "+f);f={path:rea.extension.getURL("images/icon"+f+".png")};h={title:h?h:rea.extension.manifest.name};null!=e&&(f.tabId=e,h.tabId=e);try{rea.browserAction.setIcon(f,m),rea.browserAction.setTitle(h)}catch(a){p.warn("bg: ERROR while setIcon! "+
a.message)}},setBadge:function(d){var f=0;"off"==k.values.appearance_badges?f=0:"running"==k.values.appearance_badges?d&&!D.get.empty(d)&&(f=D.get.stats(d).running):"running_unique"==k.values.appearance_badges?d&&!D.get.empty(d)&&(f=D.get.stats(d,!0).unique):"disabled"==k.values.appearance_badges&&d&&!D.get.empty(d)&&(f=D.get.stats(d).disabled);p.debug("badge: set "+f);f?rea.browserAction.setBadgeText({text:f.toString(),tabId:d}):rea.browserAction.setBadgeText({text:"",tabId:d})}};return h}(),ca=
function(){var d=null,h={init:function(){d=r.getValue(n.CONSTANTS.STORAGE.BEGGING,null);var e,f=Date.now();d?(e=r.getValue(n.CONSTANTS.STORAGE.LAST_START,0))&&12096E5<f-e&&(d.later={type:"after_pause",ts:f},h.save()):(d={first_run:{type:"from_init",ts:f}},h.save())},save:function(){r.setValue(n.CONSTANTS.STORAGE.BEGGING,d)},needed:function(){var e=Date.now(),f=d.first_run?d.first_run.ts+12096E5<e:!0,h=!d.hide,b=!d.contributed,e=d.later?d.later.ts+12096E5<e:!0;if(!n.RUNTIME.SAFARI&&!n.RUNTIME.DOLPHIN&&
f&&h&&b&&e)return d.later?"l":"i"},clicked:function(d,f,h){M.tG("clicked",d,f+h)},dialog:{shown:function(e){var f=Date.now();d.dialog={ts:f,extra:e};h.save();M.tG("dialog")}},button:function(){var e={};["contributed","later","hide"].forEach(function(f){e[f]=function(e,b){var a=Date.now();d[f]={ts:a,type:e,extra:b};h.save();M.tG("button",f)}});return e}()};return h}(),ma=function(){var d=function(a,b){p.debug(a,b);if(b&&a.menuItemId){var c=A.getByUid(a.menuItemId);c&&c.script?Da.bundle({url:a.frameUrl||
a.pageUrl||"<unknown>"},c.script,!0).then(function(c){var d=m();c.method="executeScript";a.frameUrl?c.url=B.woHash(a.frameUrl):c.topframe=!0;rea.tabs.sendMessage(b.id,c,d.resolve);return d.promise()}):p.debug("ctxm: unable to find script "+a.menuItemId,a,b)}},h=[],e=null,f=!1,k=function(a){var b=[];y.each(a,function(a){var c=m();rea.contextMenus.create({id:a.uuid,contexts:["all"],parentId:e,title:a.name,type:"normal",documentUrlPatterns:["http://*/*","https://*/*","file://*/*"]},function(){c.resolve()});
h.push(a.uuid);b.push(c.promise())});return m.when(b)},b=function(){var a=m();rea.contextMenus.removeAll(function(){e=null;a.resolve()});return a.promise()},a=function(){var a=m();b().then(function(){e=rea.contextMenus.create({contexts:["all"],title:"Tampermonkey",type:"normal",documentUrlPatterns:["http://*/*","https://*/*","file://*/*"]},function(){a.resolve()})});return a.promise()},c=function(){var c=Y.getContexters(!0,null);if(c.length){var d;d=e?m.Pledge():a();return d.then(function(){return k(c)})}return b().then(g.clean)},
g={init:function(){rea.contextMenus.supported&&(g.clean().then(c).then(function(){f=!0}),rea.contextMenus.onClicked.addListener(d))},clean:function(){var a=m();h.forEach(function(a){rea.contextMenus.remove(a)});h=[];a.resolve();return a.promise()},onScriptsChanged:function(){if(rea.contextMenus.supported&&f)return g.clean().then(c)},getContexterCount:function(){return h.length}};return g}(),ha=function(){var d={},h={},e=("TM_"+y.createUUID().substr(0,5)).toLowerCase(),f=["x-webkit-csp","x-content-security-policy",
"content-security-policy"],m=rea.webRequest.extraHeaderNeeded,b=function(a,b){var c,d,e,g,f,h=a.split(";");h.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 /)&&(g=b)});var k,l;void 0!==e&&void 0===d&&(c=!0,h.push(h[e].replace(/default-src /,"script-src ")),d=h.length-1);void 0!==e&&void 0===g&&(c=!0,h.push(h[e].replace(/default-src /,"img-src ")),g=h.length-1);void 0!==g&&(l=!1,k=h[g],-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&&(h[g]=k,c=!0));void 0!==d&&(l=!1,k=h[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'/,"")),n.RUNTIME.FIREFOX&&(-1==k.search(/'unsafe-inline'/)&&(l=f=!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&&(h[d]=k,c=!0));void 0!==e&&(l=!1,k=h[e],f&&-1!=k.search(/ 'self'/)&&(l=!0,h[e]=k.replace(/default-src /,"default-src blob: data: ")),l&&(c=!0));return c?h.join(";"):null},a=function(a,b){var c,d,e=a.split(";");e.forEach(function(a,b){0===a.search(/^\s*sync-xhr /)&&(d=b)});var g,f;void 0!==d&&(f=!1,g=e[d],-1!=g.search(/'none'/)&&(f=!0,g=g.replace(/ 'none'/," *")),f&&(e[d]=g,c=!0));return c?e.join(";"):null},c=function(a,b){var c={},d=a.url;Object.keys(b).forEach(function(a){var e=b[a];y.each(e.rules,
function(a,b){var g,f;if((g=a.selector)&&(f=a.action)){var h,k=e.id+"/"+b;(h=K.items.regexp.get(k))||(h=u.regexify({inc:g.include,match:g.match,exc:g.exclude}),K.items.regexp.set(k,h));if(u.validUrl(d,h)){if(f.cancel)return p.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},!1;if(f.redirect){var l,m,n,v;f.redirect.url?l=f.redirect.url:(m=f.redirect.from)&&(n=f.redirect.to)&&(v=d.match(m,n))&&(v.shift(),l=
n,v.concat(["","",""]).forEach(function(a,b){l=l.replace("$"+(b+1),a||"")}));g=function(b){p.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}})};l?(l=B.woHash(l),T.isAllowed(l)?u.scriptWillRun(e.uuid,l)?(p.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):g("the redirect URL needs to be included by the scripts @include or @match tag"):g("the redirect URL is filtered by the security settings")):g("unable to determine the redirect URL")}}}})});return c},g=function(a){var b;n.RUNTIME.CHROME&&63<=n.RUNTIME.BROWSER_VERSION?b=a.initiator:n.RUNTIME.FIREFOX&&(b=a.originUrl);return b&&0!==(b+"/").indexOf(rea.extension.getURL("/"))?b:null},l=function(a){if(!g(a)){var b=[],c=a.requestHeaders||[],d,f,k={},l=new RegExp("^"+e),c=c.filter(function(c){if(c.name&&
0==c.name.search(l))f=c.name.replace(l,""),k[f.toLowerCase()]=!0,"internal"==f?h[a.requestId]=c.value:c.value&&b.push({name:f,value:H.decodeS(c.value)}),d=!0;else return!0});if(d)return{requestHeaders:c.filter(function(a){return!a.name||!k[a.name.toLowerCase()]}).concat(b)}}},r=function(a){if(G.late)if("main_frame"==a.type){if(D.events.reset(a.tabId,!0),0<a.tabId&&"POST"!=a.method&&"auto"==k.values.scriptUrlDetection&&oa.isScriptUrl(a.url))return u.installFromUrl(a.url,{},{silent_fail:!0}).fail(function(b){p.info("webRequest: user script detected @ "+
a.url+" was invalid",b?b.messages:"");rea.tabs.update(a.tabId,{url:a.url+"#bypass=true"},function(){})}).done(function(){n.RUNTIME.EDGE&&rea.tabs.query({windowType:"normal"},function(b){b.forEach(function(b){b.id===a.tabId&&rea.tabs.update(b.id,{url:b.url},function(){})})})}),n.RUNTIME.EDGE?{cancel:!0}:{redirectUrl:"javascript:history.back()"}}else{var b,d;if((b=D.get.requests(a.tabId,a.frameId))&&(d=c(a,b)))return d}else G.registerLateCallback(function(){r(a)})},t=function(c,e){if(G.late){var g=
c.responseHeaders||[];if("xmlhttprequest"==c.type){var l,m;if(h[c.requestId]){n.XMLHTTPREQUEST.COOKIE_PASSTHROUGH||g.forEach(function(a){a.name&&a.value&&-1!=a.name.toLowerCase().indexOf("set-cookie")&&(g.push({name:"tm-setcookie"+rea.runtime.short_id.toLowerCase(),value:a.value}),m=!0)});if(l=d[c.requestId])g.push({name:"tm-finalurl"+rea.runtime.short_id.toLowerCase(),value:l}),m=!0;if(m)return{responseHeaders:g}}}else{var p,q,r,z,x=n.OPTIONS.HAS_CSP&&"yes"==k.values.webrequest_fixCSP,y=x&&n.RUNTIME.CHROME&&
60<=n.RUNTIME.BROWSER_VERSION;g.some(function(a){if(a.name)return a=a.name.toLowerCase(),q|="location"==a,x&&(r|=-1!=f.indexOf(a)),y&&(z|="feature-policy"==a),q});if(!q){(l=D.events.response(c.tabId,c.frameId,c.url))&&(r||z)&&g.forEach(function(d,e){if(d.name&&d.value){var h=d.name.toLowerCase();if(-1!=f.indexOf(h)){var k;if(k=b(d.value,c))p=!0,g[e]={name:d.name,value:k}}"feature-policy"==h&&(h=a(d.value,c))&&(p=!0,g[e]={name:d.name,value:h})}});var u;if(n.RUNTIME.FAST_EXEC_SUPPORT&&-1!=["instant"].indexOf(k.values.runtime_inject_mode)&&
(u=D.events.run(c.tabId,c.frameId,null,c.url))){var A=B.parse(c.url),A=A.pathname+A.search,A="TM_"+rea.runtime.short_id+H.Base64.encode(A.length+A).substr(0,255).replace(/[#=\/]/g,"_")+Date.now();u=Y.answer(u,c.url);u=JSON.stringify(u);u=new Blob([u],{type:"binary/octet-stream"});u=URL.createObjectURL(u);D.set.objurl(c.tabId,c.frameId,u);g.push({name:"set-cookie",value:A+"="+window.encodeURIComponent(u)+"; max-age=15;"});p=!0}if(l&&!e&&rea.webRequest.filterResponseData&&n.OPTIONS.HAS_CSP&&"yes"==
k.values.webrequest_fixCSP&&"yes"==k.values.webrequest_fixContentCSP&&-1!=["main_frame","sub_frame"].indexOf(c.type)){var E;g.some(function(a){if(a.name&&a.value&&"content-type"==a.name.toLowerCase()&&"text/html"==a.value.split(";")[0].toLowerCase().trim())return E=!0});if(E){var C=rea.webRequest.filterResponseData(c.requestId);C.ondata=function(a){var d=(new TextDecoder("x-user-defined")).decode(a.data,{stream:!0}),e=new RegExp('(<head>[\\s\\S]*)(<meta[^>]+http-equiv="(?:'+f.join("|")+')"[^>]*>)([\\s\\S]*?<\\/head>)',
"i"),g,d=d.replace(e,function(a,d,e,f){return d+e.replace(/(content=")([^">]+)(")/,function(a,d,e,f){if(a=b(e||"",c))g=!0;return d+(a||e)+f})+f});g?C.write(H.str2arrbuf(d)):C.write(a.data);C.disconnect();C=null};C.onstop=function(){C&&C.disconnect()}}}if(p)return n.RUNTIME.FIREFOX&&(g=g.filter(function(a){return"cache-control"!=a.name.toLowerCase()}),g.push({name:"cache-control",value:"no-cache, no-store, must-revalidate"})),{responseHeaders:g}}}}else G.registerLateCallback(function(){t(c,!0)})},
z=function(a){d[a.requestId]=a.redirectUrl},E=function(a){G.late?"xmlhttprequest"==a.type?(delete h[a.requestId],delete d[a.requestId]):a.fromCache&&D.events.response(a.tabId,a.frameId,a.url):G.registerLateCallback(function(){E(a)})},A=function(a){"xmlhttprequest"==a.type?(delete h[a.requestId],delete d[a.requestId]):D.events.reset(a.tabId,!0)};return{getPrefix:function(){return e},init:function(a){try{var b;b=n.RUNTIME.EDGE?["http://*/*","https://*/*"]:["http://*/*","https://*/*","ftp://*/*","file:///*"].concat(n.RUNTIME.WEBREQUEST_WEBSOCKET?
["ws://*/*","wss://*/*"]:[]);a?(rea.webRequest.onBeforeRequest.addListener(r,{urls:b,types:["main_frame","sub_frame","script","xmlhttprequest"].concat(n.RUNTIME.WEBREQUEST_WEBSOCKET?["websocket"]:[])},["blocking"]),rea.webRequest.onHeadersReceived.addListener(t,{urls:b,types:["main_frame","sub_frame","xmlhttprequest"]},["blocking","responseHeaders"].concat(m?["extraHeaders"]:[])),n.RUNTIME.WEBREQUEST_XHR_SUPPORT&&rea.webRequest.onBeforeRedirect.addListener(z,{urls:b,types:["xmlhttprequest"]},[]),
rea.webRequest.onResponseStarted.addListener(E,{urls:b,types:["main_frame","sub_frame","xmlhttprequest"]},[]),rea.webRequest.onErrorOccurred.addListener(A,{urls:b,types:["main_frame","xmlhttprequest"]})):n.RUNTIME.WEBREQUEST_XHR_SUPPORT&&"no"!=k.values.webrequest_modHeaders&&rea.webRequest.onBeforeSendHeaders.addListener(l,{urls:b,types:["xmlhttprequest"]},["blocking","requestHeaders"].concat(m?["extraHeaders"]:[]));rea.webRequest.handlerBehaviorChanged()}catch(c){p.warn("webRequest: error initializings",
c.message)}},scripts:{set:function(a,b,c,d,e){var g=[];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});g.push({selector:b,action:c})});D.set.requests(a,b,c,{id:c+"@"+a+":"+b+"#"+Date.now(),rules:g,uuid:c,
callback:e})}}}}(),G={late:!1,callbacks:[],init:function(){},registerLateCallback:function(d){p.debug("toea: register callback");G.callbacks.push(d)},ensureLate:function(d){G.late?d():G.registerLateCallback(d)},setReady:function(){p.debug("toea: run "+G.callbacks.length+" callbacks");G.late=!0;for(var d=0;d<G.callbacks.length;d++)G.callbacks[d]();G.callbacks=[]}},Ma=function(){var d=!1,h=null,e=function(){d||(p.debug("Unloader.onbeforeunload()"),h&&h(),d=!0)};return{init:function(d){h=d;window.addEventListener("beforeunload",
e,!1)}}}(),ga=function(){var w=null,h=rea.extension.manifest.version,e=null,f=!1,q=!1,b=function(){if(G.late){var a="version="+h+"&ext="+rea.runtime.short_id+"&updated=true",c;f?(c="https://www.tampermonkey.net/installed.php?"+a,q=!0):(a+="&old="+e,c="https://www.tampermonkey.net/changelog.php?"+a);"off"!=k.values.notification_showUpdate&&("notification"==k.values.notification_showUpdate?S.showUpdate(d.getMessage("Updated_to__0version0",h),d.getMessage("Click_here_to_see_the_recent_changes"),P.images.brand("tampermonkey"),
function(a){a.clicked&&rea.tabs.create({url:c},function(){})}):"changelog"==k.values.notification_showUpdate&&(q||(c+="&intr=true"),q=!0,rea.tabs.create({url:c,active:q},function(){})))}else G.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(n.MISC.IDLE_TIMEOUT,function(b){a="active"==b;d()});return c.promise()},c=function(){var a=m(),b=function(){var b=Date.now(),c=r.getValue(n.CONSTANTS.STORAGE.LAST_START,
0),b=Math.round((b-c)/1E3),c=b<=n.MISC.DISTURBANCE_ALLOWED;p.debug("upd: restart?",c,"(",b,"seconds ago)");a.resolve(c)};G.late?b():G.registerLateCallback(b);return a.promise()}(),g=function(){var d=!1,e=!1;a().then(function(a){e=a;return c}).then(function(a){d=a}).always(function(){q=!e||d;b();x=!0})},l=null,x=!1,t={scheduleNotification:function(a,b){x||(e=a,f|=b,l&&window.clearTimeout(l),l=window.setTimeout(g,1E3))},updateAvailable:function(){return w},onInstalled:function(){t.scheduleNotification(null,
!0)},onUpdated:function(a){t.scheduleNotification(a,!1)},onUpdateAvailable:function(a){p.info("An update to version",a.version,"is available");w=a.version;window.setTimeout(function(){S.show(d.getMessage("Update"),d.getMessage("0name0_0version0_is_available__Please_re_start_your_browser_to_update_",rea.extension.manifest.name,a.version),P.images.brand("tampermonkey"),{timeout:6E4})},864E5)}};(function(){G.registerLateCallback(function(){r.setValue(n.CONSTANTS.STORAGE.LAST_START,Date.now())})})();
return t}(),Na=function(d){(function(){var h=m();"toggle-enable"==d?(k.values.enabled=!k.values.enabled,h.resolve()):rea.tabs.getSelected(null,function(e){var f;"open-dashboard"==d?f=rea.extension.getURL("options.html")+"#nav=dashboard":"open-dashboard-with-running-scripts"==d?f=rea.extension.getURL("options.html")+"#nav=dashboard&filter="+encodeURIComponent(e.url):"open-new-script"==d&&(f=rea.extension.getURL("options.html")+"#url="+H.Base64.encode(e.url)+"&nav=new-user-script");h.resolve(f?{url:f,
active:!0,parent:e}:null)});return h.promise()})().then(function(d){d&&rea.tabs.create(d)})},va=function(){var d=[],h=function(a,b,e){if(G.late){var f=e.pendingUrl||e.url;"auto"==k.values.scriptUrlDetection&&oa.isScriptUrl(f)&&u.installFromUrl(f,{},{silent_fail:!0});f?"loading"==b.status?D.events.loading(e.id,0,f):"complete"==b.status&&D.events.complete(e.id,0,f):p.warn("tabUpdates: no tab url set! ",e);d.forEach(function(a){a({reason:"updated",status:b.status},e)})}else window.setTimeout(function(){h(a,
b,e)},100)},e=function(a,b){fa[a]&&(fa[a].onClose(),delete fa[a]);D.events.remove(a);d.forEach(function(b){b({reason:"removed"},{id:a})})},f=function(a,b){e(b,{});R.setIcon(a);R.setBadge(a);d.forEach(function(b){b({reason:"replaced"},a)})},m=function(a){G.late?(D.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(){m(a)},100)},b={init:function(){rea.tabs.onUpdated.addListener(h);rea.tabs.onRemoved.addListener(e);
rea.tabs.onReplaced.addListener(f);rea.webNavigation.supported&&rea.webNavigation.onCommitted.addListener(m)},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(){var a=rea.runtime.lastError;a?p.warn("tab.close",a.message):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}(),Ea=function(){var d="temporary"==k.values.incognito_mode&&rea.extension.inIncognitoContext;r.setTemporary(d);d&&(k.values.sync_enabled=!1,k.values.scriptUpdateCheckPeriod=0,k.values.sync_type=0,k.values.statistics_enabled=!1)},Oa=function(){p.set(k.values.logLevel);d.setLocale(k.values.i18n);var m=n.RUNTIME.WEBREQUEST_XHR_SUPPORT&&"no"!=k.values.webrequest_modHeaders;W=Registry.get("xmlhttprequest");
W.setConfig({prefix:m?ha.getPrefix():null,mozAnon:n.RUNTIME.FIREFOX});aa.init();M.init("bg",rea.extension.manifest.version,k.values.statistics_enabled,!0);D.listeners.add.onReset(function(d,e){da.clearByTabId(d);A.removeStorageListeners({tabid:d},!1);e||R.setIcon(d)});m=function(d){0<=d&&rea.tabs.get(d,function(e){!rea.runtime.lastError&&e&&(R.setIcon(d),R.setBadge(d))})};D.listeners.add.onCommited(m);D.listeners.add.onCompleted(m);D.listeners.add.onCompleted(ia.purgeAppeals);D.listeners.add.onRemoved(ia.purgeAppeals);
D.listeners.add.onRemoved(na.cleanTab);L.init().done(function(d){d&&L.sync()});T.init();I.init();A.init();m=function(){J.set_mode(k.values.downloads_mode);J.set_whitelist(k.values.downloads_extension_whitelist)};m();J.config_changed_listener=m;sa.init();ha.init();ma.init();ca.init();ba.init()},W,ja,C,F,ua;init=function(){d.init();G.init();ha.init(!0);va.init();za.init();rea.commands.supported&&rea.commands.onCommand.addListener(Na);Ma.init(function(){L.finalize()});ja=Registry.get("compat",n);C=Registry.get("parser");
C.init(ja);F=Registry.get("syncinfo",va);ua=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"});rea.runtime.onUpdateAvailable.addListener(ga.onUpdateAvailable);rea.runtime.onInstalled.addListener(function(d){p.debug("bg: onInstalled",d);d||(d={reason:"mandatory_argument_is_not_set"});if("install"==d.reason)qa.onInstalled();else if("update"==d.reason)qa.onUpdated(d.previousVersion);
G.ensureLate(function(){if("chrome_update"==d.reason)M.tB({updated:!0});else if("install"==d.reason)ga.onInstalled();else if("update"==d.reason)ga.onUpdated(d.previousVersion)})});r.init().then(Fa).then(qa.init).then(k.init).then(function(){cfgo=k;Ea();Oa();Ja();R.init();window.setTimeout(ba.check,1E4);qa.check().then(function(){p.debug("Listeners registered!");window.setTimeout(G.setReady,1)})})};init()}});
