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