'use strict';var trup,init,lfgs,sycl,cfgo,uris,clip,dast,perm,blak,scbr,exts,down,D=!1;
Registry.require("promise statistics convert xmlhttprequest downloads cache storage uri compat parser helper syncinfo notify asker i18n native".split(" "),function(){var pa=function(a){D|=60<=a;J.debug(!1);p.debug(D,!1);P.debug(D)},n=rea.FEATURES,ea=function(){var a=[],d=!0,c=function(a,c,f){var b={title:a.join("\n\n")};console.warn(a.join("\n"));rea.browserAction.setIcon(c);rea.browserAction.setTitle(b);c=function(b,f,c){b={name:"1",sub_menu_item:!0,pos:"left",items:[]};b.items.push({name:a[0],image:"info"});
1<a.length&&b.items.push({name:a[1]});c({items:[b],options:{enabled:!1}})};f||rea.extension.onMessage.addListener(c)};return{run:function(){try{if(Registry.verify("58").length){var a={path:rea.extension.getURL("images/icon_paused.png")};d=!1;c(["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."],a)}}catch(e){d=!1,console.error(e.message)}"chromeStorage"!=n.DB.USE||
n.DB.NO_WARNING||window.setTimeout(function(){p.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(){});var a={path:rea.extension.getURL("images/icon_paused.png")};c(["Tampermonkey detected that the extension storage is unreliable!"],
a,!0)})},1E3);return d},pause:c,setWarning:function(c,d,f){a.push({text:c,description:d,url:f})},getWarnings:function(){return a}}}();if(ea.run()){var K=n.WEBREQUEST,l=Registry.get("promise"),s=Registry.get("helper"),T=Registry.get("cache"),M=Registry.get("statistics"),p=Registry.get("storage"),P=Registry.get("notify"),fa=Registry.get("asker"),N=Registry.get("native"),Q=Registry.get("permission");perm=Q;dast=p;var qa=s.createUUID(),O={},X={};D&&console.debug("Starting background fred @"+qa);T.create("rundata").setOptions({timeout:180,
check_interval:120,retimeout_on_get:!0}).init();T.create("resources").setOptions({timeout:1800,check_interval:300}).init();var Ba=function(){var a=l(),d,c,k=rea.extension.manifest.version,e=p.getSchemaVersion(),f=e;p.getVersion("0.0.0.0").then(function(a){c=a;d=w.versionCmp(k,c)==w.versionCmp.eNEWER;return p.isWiped()}).then(function(a){!d&&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"],console.warn(a.join("\n")),ea.setWarning.apply(this,a))}).always(function(){var b=[],h=0,r=function(){if(h<b.length){var c=b[h].schema;b[h].cond(c)?b[h].fn().done(function(){c&&(console.log("Converted database from",f,"to",c),f=c);h++;r()}).fail(function(){a.reject()}):(h++,r())}},u=function(){console.warn("Incognito mode detected. Database conversion can only be done in non-incognito mode! Stopping now...");var a={path:rea.extension.getURL("images/icon_paused.png")};
ea.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."],a)},b=[{cond:function(){return d&&!n.RUNTIME.FIREFOX&&"chromeStorage"==n.DB.USE&&!p.getValue(n.CONSTANTS.STORAGE.LEGACY_VERSION)&&w.versionCmp("3.5.3603",c)==w.versionCmp.eNEWER},fn:function(){var a=l();rea.extension.inIncognitoContext?(u(),a.reject()):(console.log("Update database..."),f="3.5.3603",p.migrate("sql","chromeStorage").done(function(){console.log("Copied config for default usage of chrome storage");
a.resolve()}));return a.promise()}},{cond:function(){return d&&w.versionCmp("3.6.3650",f)==w.versionCmp.eNEWER&&w.versionCmp("3.5.3650",c)==w.versionCmp.eNEWER},fn:function(){var a=l();if(rea.extension.inIncognitoContext)u(),a.reject();else{f="3.6.3650";var b=[];[{o:"TM_config",n:n.CONSTANTS.STORAGE.CONFIG},{o:"TM_update_check",n:n.CONSTANTS.STORAGE.UPDATE},{o:"TM_version"},{o:"TM_unload_ts"}].forEach(function(a){if(a.n){var f=p.getValue(a.o);void 0!==f&&b.push(p.setValue(a.n,f))}b.push(p.deleteValue(a.o))});
var h=/@re$/,d=[];p.listValues().forEach(function(a){-1!=a.search(h)&&(a=a.replace(h,""),d.push(a))});d.forEach(function(a){var f=p.getValue(a+"@st"),c=p.getValue(a),h=p.getValue(a+"@re"),d=p.getValue(a+"@source"),r=x.getUidByName(a)||s.createUUID();b.push(p.deleteValue(a+"@st"));b.push(p.deleteValue(a));b.push(p.deleteValue(a+"@re"));b.push(p.deleteValue(a+"@source"));c&&h&&d?(b.push(p.setValue(n.CONSTANTS.PREFIX.SCRIPT_UID+r,a)),b.push(p.setValue(n.CONSTANTS.PREFIX.COND+r,h)),b.push(p.setValue(n.CONSTANTS.PREFIX.STORE+
r,f)),b.push(p.setValue(n.CONSTANTS.PREFIX.SCRIPT+r,d)),b.push(p.setValue(n.CONSTANTS.PREFIX.META+r,c))):console.warn("invalid script entry",{source:d,meta:c,cond:h})});h=/@st$/;p.listValues().forEach(function(a){-1!=a.search(h)&&b.push(p.deleteValue(a))});l.when(b).done(function(){console.log("Converted database from",c,"to",f);a.resolve()})}return a.promise()}},{schema:"3.7.0",cond:function(a){return w.versionCmp(a,f)==w.versionCmp.eNEWER},fn:function(){var a=l();if(rea.extension.inIncognitoContext)u(),
a.reject();else{var b=[],f=RegExp("^"+n.CONSTANTS.PREFIX.META);p.listValues().forEach(function(a){if(-1!=a.search(f)){var c=p.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(p.setValue(a,c)))}});l.when(b).done(function(){a.resolve()})}return a.promise()}},{schema:"4258",cond:function(a){return w.versionCmp(a,f)==w.versionCmp.eNEWER},fn:function(){var a=l();if(rea.extension.inIncognitoContext)u(),
a.reject();else{var b=p.getValue(n.CONSTANTS.STORAGE.CONFIG);b&&b.sync_enabled&&2==b.sync_type&&(b.sync_version=1,p.setValue(n.CONSTANTS.STORAGE.CONFIG,b));a.resolve()}return a.promise()}},{schema:"4526",cond:function(a){return d&&n.RUNTIME.SAFARI&&"chromeStorage"==n.DB.USE&&w.versionCmp(a,f)==w.versionCmp.eNEWER},fn:function(){var a=l();rea.extension.inIncognitoContext?(u(),a.reject()):(console.log("Update database..."),p.migrate("localStorage","chromeStorage").done(function(){console.log("Copied config for default usage of setting storage");
a.resolve()}).fail(a.reject));return a.promise()}},{schema:"4871",cond:function(a){return d&&w.versionCmp(a,f)==w.versionCmp.eNEWER},fn:function(){var a=l(),b,f,c=p.getValue(n.CONSTANTS.STORAGE.CONFIG);c&&c.scriptTemplate&&(f=g.getDefaults())&&(b=f.script_templates)&&b[0]&&b[0].value&&(b[0].value=c.scriptTemplate,delete c.scriptTemplate,p.setValue(n.CONSTANTS.STORAGE.CONFIG,c));a.resolve();return a.promise()}},{cond:function(){return d||w.versionCmp(f,e)==w.versionCmp.eNEWER},fn:function(){var a=
l();p.setVersion(k,f).done(function(){a.resolve()});return a.promise()}},{cond:function(){return d},fn:function(){console.log("First run of version "+k+"!");Aa.scheduleNotification(c,"0.0.0.0"==c);return l.Pledge()}},{cond:function(){return!0},fn:function(){var b=l();a.resolve();window.setTimeout(b.resolve,n.MISC.TIMEOUT);return b.promise()}}];r()});return a.promise()},ga=function(){var a={get:function(a,c){var k=(0==a)+"#"+c,e=T.items.rundata.getj(k);if(e)e.oldret.user_agent[a]=e.oldret.user_agent[e.frameId],
e=e.oldret;else{var e=[],f=0,b={},h={};if(c)for(var r=v.determineScriptsToRun(c),u=0;u<r.length;u++){var t=r[u];t.enabled?t.evilness&&t.evilness>=g.values.script_blacklist_severity||0!=a&&(!0===t.options.noframes||null===t.options.noframes&&!0===t.options.override.orig_noframes)||v.isContexter(t)||(t.options.user_agent&&(h[a]=t.options.user_agent),b[t.name]=!0,e.push(t)):f++}e={runners:e,disabled:f,script_map:b,user_agent:h};c&&T.items.rundata.setj(k,{frameId:a,oldret:e})}return e},getUserAgent:function(d,
c){return a.get(d,c).user_agent},getContexters:function(a,c){for(var k=[],e=v.determineScriptsToRun(c),f=0;f<e.length;f++){var b=e[f];b.enabled&&(0==a||!0!==b.options.noframes&&(null!==b.options.noframes||!0!==b.options.override.orig_noframes))&&v.isContexter(b)&&k.push(b)}return k}};return a}(),z=function(){var a={},d=1,c=d++,k=d++,e=d++,f=d++,b=d++,h=d++,r=d++,u=d++,t=function(){var a={frames:{0:{state:c}},tabs:{reset_ts:(new Date).getTime()},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},q={},C={},F={},B={listeners:{once:{whenReady:function(b,c){if(!a[b]||a[b].frames[0].state<f)B.listeners.once.onReady(b,c);else c()},onReady:function(a,b){var c=function(a){B.listeners.remove.onCommited(f);B.listeners.remove.onCompleted(h);a&&b()},f=B.listeners.add.onCommited(function(b){b===a&&c(!0)}),h=B.listeners.add.onCompleted(function(b){b===a&&c(!0)})}},add:{onReset:function(a){var b=
s.createUUID();q[b]=a;return b},onCommited:function(a){var b=s.createUUID();C[b]=a;return b},onCompleted:function(a){var b=s.createUUID();F[b]=a;return b}},remove:function(){return{onReset:function(a){delete q[a]},onCommited:function(a){delete C[a]},onCompleted:function(a){delete F[a]}}}()},events:{reset:function(b,f){a[b]=t();a[b].frames[0].state=c;s.each(q,function(a){a&&a(b,f)})},request:function(b,c,f){g.values.enabled&&(a[b]=a[b]||t(),a[b].frames[c]=a[b].frames[c]||{},a[b].frames[c].state=k,
f=A.woHash(f),ha.isAllowed(f)&&(f=ga.getUserAgent(c,f),f[c]&&B.set.extra(b,c,"user_agent",f[c])))},response:function(b,f,h){if(g.values.enabled){a[b]=a[b]||t();a[b].frames[f]=a[b].frames[f]||{};var r=a[b].frames[f].state||c;a[b].frames[f].state=e;0===f&&(a[b].tabs.response_ts=(new Date).getTime());h=A.woHash(h);r<e&&B.scripts.determine(b,f,h);return(b=a[b].scripts[h])?b.runners.length:0}},commited:function(b,h,r){if(g.values.enabled){var d=A.parse(r);if("http:"===d.protocol||"https:"===d.protocol||
"file:"===d.protocol)a[b]=a[b]||t(),a[b].frames[h]=a[b].frames[h]||{},d=a[b].frames[h].state||c,a[b].frames[h].state=f,d<e&&(r=A.woHash(r),B.scripts.determine(b,h,r)),s.each(C,function(a){a&&a(b)})}},loading:function(f,h,r){if(g.values.enabled){var d=A.parse(r);"http:"!==d.protocol&&"https:"!==d.protocol&&"file:"!==d.protocol||0!==h||"file:"!==d.protocol||(a[f]=a[f]||t(),a[f].frames[h]=a[f].frames[h]||{},d=a[f].frames[h].state||c,a[f].frames[h].state=b,d<e&&(r=A.woHash(r),B.scripts.determine(f,h,
r)))}},run:function(b,f,c,r,d){if(g.values.enabled){var k=0===f?f:c;a[b]=a[b]||t();a[b].frames[k]=a[b].frames[k]||{};a[b].frames[k].state=h;var e=A.woHash(r);r=a[b].scripts[e];if(!r&&(B.scripts.determine(b,f,e),r=a[b].scripts[e],!r)){console.warn("tv: no script run info for tab "+b+" @ "+e,D?a[b].scripts:"");return}B.scripts.updateMaps(b,c,r.script_map);B.scripts.updateUrls(b,c,e);B.scripts.updateStats(b,c,r.runners.length,r.disabled);B.scripts.run(b,f,c,e,r.runners,function(f){a[b]&&delete a[b].scripts[e];
d(f)})}},complete:function(b,f,d){d=A.parse(d);if(g.values.enabled&&("http:"===d.protocol||"https:"===d.protocol||"file:"===d.protocol)){if(0===f){a[b]=a[b]||t();a[b].frames[f]=a[b].frames[f]||{};var k=a[b].frames[f].state||c;a[b].frames[f].state=r;if(!z.get.empty(b)&&z.get.stats(b).running){if(k<h){console.warn("tv: no script run info!");return}"file:"===d.protocol?window.setTimeout(function(){rea.tabs.sendMessage(b,{method:"onLoad",frameId:f},function(){})},500):(rea.tabs.sendMessage(b,{method:"onLoad",
frameId:f},function(){}),G.runCheck&&rea.contentSettings.javascript.clear({}))}}s.each(F,function(a){a&&a(b)})}},unload:function(b,f,c){f=0===f?f:c;a[b]=a[b]||t();a[b].frames[f]=a[b].frames[f]||{};a[b].frames[f].state=u;if(a[b]&&a[b].contexts.onUnload[c]){for(f=0;f<a[b].contexts.onUnload[c].length;f++)a[b].contexts.onUnload[c][f]();a[b].contexts.onUnload[c]=[]}},remove:function(b){delete a[b]}},scripts:{updateStats:function(b,f,c,h){a[b].stats.running+=c;a[b].stats.disabled+=h;a[b].contexts.onUnload[f]=
a[b].contexts.onUnload[f]||[];a[b].contexts.onUnload[f].push(function(){a[b].stats.running-=c;a[b].stats.disabled-=h});a[b].tabs.ts=(new Date).getTime()},updateMaps:function(b,f,c){var h=1,r=function(f,c){void 0===a[b].maps[c]&&1===h&&(a[b].maps[c]=0);a[b].maps[c]+=h};s.each(c,r);a[b].contexts.onUnload[f]=a[b].contexts.onUnload[f]||[];a[b].contexts.onUnload[f].push(function(){a[b]&&(h=-1,s.each(c,r))})},updateUrls:function(b,f,c){var h=1,r=function(){void 0===a[b].urls[c]&&1===h&&(a[b].urls[c]=0);
a[b].urls[c]+=h;a[b].urls.length=-1};r();a[b].contexts.onUnload[f]=a[b].contexts.onUnload[f]||[];a[b].contexts.onUnload[f].push(function(){a[b]&&(h=-1,r())})},determine:function(b,f,c){var h=null;ha.isAllowed(c)?h=c:(D&&console.log("This URL is filtered by the security settings:",c,"-> Do nothing!"),z.set.forbidden(b,f));f=ga.get(f,h);a[b].scripts[c]=f;return f.runners.length},run:function(a,b,f,c,h,r){a=[];b=n.RUNTIME.ALLOWS_FAST_DOCUMENT_START&&g.values.runtime_fastDocumentStart;for(f=0;f<h.length;f++){var d=
h[f];a.push(ra.bundle({url:c},d,b&&("document-start"===d.options.run_at||!d.options.run_at&&"document-start"===d.options.override.orig_run_at)))}l.when(a).always(r)}},set:{extra:function(b,f,c,h){a[b]=a[b]||t();null===f?a[b].extra[c]=h:(a[b].extra[c]=a[b].extra[c]||{},a[b].extra[c][f]=h)},blocker:function(a){B.set.extra(a,null,"blocker",!0)},forbidden:function(a,b){0===b&&B.set.extra(a,null,"forbidden",!0)}},get:{extra:function(b,f,c,h){void 0===h&&(h=null);var r=null,r=(a[b]?a[b].extra:{})[c];null!==
f&&r&&(r=r[f]);return r||h},empty:function(b){var f=!0;if(a[b]&&0!=a[b].urls.length){if(-1==a[b].urls.length)return a[b].urls.length=0,s.each(a[b].urls,function(f,c){"length"!==c&&0<f&&a[b].urls.length++}),B.get.empty(b);f=!1}return f},urls:function(b){return a[b]?a[b].urls:{}},stats:function(b,f){var c={};if(a[b]&&(c.running=a[b].stats.running,c.disabled=a[b].stats.disabled,f)){c.unique=0;for(var h in a[b].maps)a[b].maps.hasOwnProperty(h)&&0<a[b].maps[h]&&c.unique++}return c},tabs:function(){var b=
{};s.each(a,function(a,f){b[f]={ts:a.response_ts}});return b},blocker:function(a){return B.get.extra(a,null,"blocker")},forbidden:function(a){return B.get.extra(a,null,"forbidden")},user_agent:function(a,b){return B.get.extra(a,b,"user_agent")}}};return B}(),ma=function(){return{isScriptUrl:function(a){if(!a||-1!=a.search(/\#bypass=true/)||-1!=a.search(n.REQUESTS.GET_INTERNAL_PAGE_REGEXP()))return!1;a=a.split(/[\?#$]/)[0];var d=-1!=a.search(/.+\.user\.(js\#|js\?|js$)/)||-1!=a.search(/.+\.tamper\.(js\#|js\?|js$)/);
return d?!(-1!=a.search(/^htt[ps]{1,2}:\/\/code\.google\.com/)||-1!=a.search(/^htt[ps]{1,2}:\/\/github\.com/)&&-1==a.search(/^htt[ps]{1,2}:\/\/github\.com\/[a-zA-Z0-9%-]\/[a-zA-Z0-9%-]\/raw\//)):d}}}(),sa=function(){var a=function(a){var c=l(),k=(new Date).getTime();a.url+=-1!=a.url.search("\\?")?"&":"?";a.url+="ts="+k;var k=function(b){if(4==b.readyState&&(200==b.status||0==b.status))if("arraybuffer"==e.responseType){if(b.response){c.resolve({decoded:!0,encoding:a.encoding,content:L.arrbuf2str(b.response,
a.encoding)});return}}else if(null!==b.response&&void 0!==b.response){c.resolve({decoded:!0,encoding:a.encoding,content:b.response});return}c.reject({content:""})},e={method:"GET",retries:0,responseType:"arraybuffer",url:a.url};if(a.sync){var f=U(e,{});4==f.readyState&&403==f.status&&(delete e.responseType,f=U(e,{}));k(f)}else U(e,{ondone:k});return c.promise()};return{getSource:function(d){"string"===typeof d&&(d={url:d});return a(d)}}}();lfgs=sa;var ha=function(){return{isAllowed:function(a){var d=
!1,c=!1,k=0!=g.values.forbiddenPages.length,e=0!=g.values.page_whitelist.length;switch(g.values.page_filter_mode){case "black":c=k;break;case "off":break;case "white":d=e;break;default:d=e,c=k}k={inc:d?g.values.page_whitelist:void 0,exc:c?g.values.forbiddenPages:void 0};return!c&&!d||v.validUrl(a,k)}}}(),Z=function(){var a={init:function(){var d=l(),c=function(){"server"===g.values.script_blacklist_type&&window.setTimeout(a.checkUpdate,2E4)};c();g.addChangeListener("script_blacklist_type",c);d.resolve();
return d.promise()},getEvilnessOf:function(a){if("off"===g.values.script_blacklist_type)return!1;if(!a)return 0;var c=!1,k=0,e=function(f){var b=!1;if(f.length)return(b="/"==f.substr(0,1)?v.matchUrl(a,f):-1!=a.search(f))&&console.debug('black: entry "'+f+'" matched'),c|=b,!0!=c};s.each(g.values.require_blacklist,e);c?k=11:"server"===g.values.script_blacklist_type&&s.each(g.values.script_blacklist_server,function(a){if(a&&(s.each(a.rules,function(a){e(a);return!0!=c}),c))return k=a.severity,!1});return Number(k)},
checkUpdate:function(a){var c=l(),k=Y.getConfig(),e;if(a||6048E5<(new Date).getTime()-k.black.last){var f=function(a){var f=l();U({method:"GET",url:a,retries:n.XMLHTTPREQUEST.RETRIES,overrideMimeType:"text/plain; charset=x-user-defined"},{ondone:function(a){f.resolve(a)}});return f.promise()};f("https://blacklist.tampermonkey.net/get.php?version=get").then(function(b){if(4==b.readyState&&200==b.status){try{e=JSON.parse(b.responseText).version}catch(c){console.log("black: unable to parse version response! "+
b.responseText)}console.log("black: local version: "+k.black.version+" remote: "+e);if(e>k.black.version||a)return f("https://blacklist.tampermonkey.net/get.php")}}).then(function(a){if(a&&4==a.readyState&&200==a.status)try{var f=JSON.parse(a.responseText);f&&f.blacklist&&1==f.version&&(g.values.script_blacklist_server=f.blacklist);console.log("black: updated blacklist to ",f)}catch(c){console.log("black: blacklist update failed! ",a.responseText)}}).always(function(){k=Y.getConfig();k.black.last=
(new Date).getTime();k.black.version=e||k.black.version;Y.setConfig(k);c.resolve()})}else c.resolve();return c.promise()}};return a}();blak=Z;var Ca=function(){for(var a=[],d=[],c=0;c<a.length;c++){var e=Registry.getRaw("system/"+a[c]+".tamper.js");e&&d.push(e)}return d},I=function(){var a=0,d=[],c={to:null,force:null,t:0},k={},m=function(a){D&&console.debug("sync: import",a.uuid,a.name,a.url);var b={imported:g.values.sync_type},f={},c;for(c in q.SYNCED)!0===q.SYNCED[c]&&(f[c]=a.options[c]);return v.installFromUrl(a.url,
{uuid:a.uuid,ask:!1,internal:!0,sync:b,force_options:f},{silent_fail:!0})},f=function(a){D&&console.debug("sync: export",a.name,a.url);return J.add(a)},b=function(a){var b=a.downloadURL?a.downloadURL.split("#")[0]:null,f=a.fileURL?a.fileURL.split("#")[0]:null,c=s.select([f,b],function(a){if(!a||"file:"!==A.parse(a).protocol)return a})[0],b={uuid:a.uuid,name:a.name,options:{},durl:b,furl:f,url:c},h;for(h in q.SYNCED)!0===q.SYNCED[h]&&null!==a.options[h]&&(b.options[h]=a.options[h]);return b},h=function(){var a=
[];x.getUidList().forEach(function(f){f=x.getByUid(f);f.script&&f.cond&&a.push(b(f.script))});return a},r=function(b){if(q.enabled)if(0<a)b&&q.addSyncDoneCallback(function(a){a&&q.sync(50,b)});else{a++;var c=null,r=null,u=!0,t={},n=function(a){if(a){(a=a.split("#")[0])&&(a=a.toLowerCase());for(var b=0;b<c.length;b++){var f=c[b].furl?c[b].furl.toLowerCase():null,h=c[b].durl?c[b].durl.toLowerCase():null;if(f==a||h==a)return c[b]}}return null},p=function(a){if(a)for(var b=0;b<r.length;b++)if(r[b].uuid==
a)return r[b];return null},s=function(a){if(a){a=a.split("#")[0];for(var b=0;b<r.length;b++)if(r[b].url==a)return r[b]}return null},w=function(a){if(!a)return null;for(var b=0;b<c.length;b++)if(c[b].uuid==a)return c[b]};(function(){c=h();return J.list().done(function(a){r=a}).fail(function(){D&&console.error("sync: unable to get remotelist!")})})().then(function(){for(var a=l(),b=[],f=0;f<r.length;f++)b.push(function(){var a,b=r[f],c=!1,h=!1,d=2==g.values.sync_version?w(b.uuid):n(b.url);if(d)if(c=
!0,t[b.url]=!0,b.uuid&&(t[b.uuid]=!0),b.content&&L.MD5(b.content)!=L.MD5(d.textContent))h=!0;else for(a in q.SYNCED)if(!0===q.SYNCED[a]&&d.options[a]!=b.options[a]){h=!0;break}if(c)if(b.options.removed)D&&console.debug("sync: remove local script",b.uuid,b.name,b.url),v.doRemove(d.uuid,!1);else if(h)if(D&&console.debug("sync: update local script",b.uuid,b.name,b.url),h=x.getByUid(d.uuid),h.script&&h.cond){for(a in q.SYNCED)!0===q.SYNCED[a]&&(h.script.options[a]=b.options[a]);b.content&&(h.script.textContent=
b.content);v.doModify(h.script.uuid,h.script,!1)}else console.log(e.getMessage("fatal_error")+"("+d.name+")!!!");if(!c&&!b.options.removed)if(a=l(),k[b.url]||b.uuid&&k[b.uuid])D&&console.warn("sync: skip previously failed import",b);else return m(b).done(function(a){a||(D&&console.warn("sync: unable to import",b),k[b.url]=!0,b.uuid&&(k[b.uuid]=!0))}).fail(function(){D&&console.warn("sync: unable to load",b);k[b.url]=!0;b.uuid&&(k[b.uuid]=!0)}).always(a.resolve),a.promise();return l.Pledge()}());l.when(b).done(function(){a.resolve()});
return a.promise()}).then(function(){c=h();return l.Pledge()}).then(function(){if(!J.isWritable())return l.Pledge();for(var a=l(),b=[],h=0;h<c.length;h++)b.push(function(){var a=c[h],b=!1;if(!a.url||t[a.url]||t[a.uuid])return l.Pledge();if(2==g.values.sync_version?p(a.uuid):s(a.url))b=!0;return b?l.Pledge():f(a).done(function(a){})}());l.when(b).done(function(){a.resolve()});return a.promise()}).fail(function(){u=!1}).done(function(){u=!0}).always(function(){D&&console.debug("sync: finished");if(0==
--a)for(var b=u;d.length;)d.shift()(b)})}},u=function(){q.enabled&&q.sync(500,!0)},t=null,q={enabled:!1,SYNCED:{comment:!0},createTeslaData:function(){for(var a=l(),b=[],f=h(),c=0;c<f.length;c++)if(f[c].url){var r=JSON.stringify(f[c].options),r=f[c].name.replace(/\|/g,"!")+"|"+r+"|"+f[c].url.replace(/\|/g,"%7C");b.push(r)}a.resolve(b);return a.promise()},configChangeListener:function(){t||(t=window.setTimeout(function(){t=null;q.init().done(function(){q.enabled&&q.sync(3E3)})},3E3))},init:function(){var a=
l();q.enabled=!1;(function(){return g.values.sync_enabled&&g.values.sync_type?J.init(g.values.sync_type,g.values.sync_version,g.values.sync_id).done(function(a){q.enabled=a;q.enabled?J.addChangeListener(u):console.warn("sync: init failed!")}):l.Pledge()})().always(function(){a.resolve(q.enabled)});return a.promise()},finalize:function(){},reset:function(){return J.reset()},addSyncDoneCallback:function(a){d.push(a)},sync:function(a,b){var f=(new Date).getTime();a=a||500;b=c.force||b;c.to?(window.clearTimeout(c.to),
c.ts<f+a&&(a=c.ts-f,1>a&&(a=1))):D&&console.debug("sync: schedule sync for run in "+a+" ms");c.force=b;c.ts=f+a;c.to=window.setTimeout(function(){r(c.force);c.to=null;c.force=null},a)},scriptAddedCb:function(a,c){if(q.enabled&&J.isWritable()){var h=b(c);h.url&&A.parse(h.url).protocol.match(/https?:/)&&f(h)}},scriptChangedCb:function(a,c,h){if(q.enabled&&J.isWritable()&&(a=b(c),a.url))for(var r in q.SYNCED)if(!0===q.SYNCED[r]&&c.options[r]!=h.options[r]){f(a);break}},scriptRemovedCb:function(a,f){if(q.enabled&&
J.isWritable()){var c=b(f);c.url&&(D&&console.debug("sync: remove",c.name,c.url),J.remove(c))}}};return q}();sycl=I;var Da=function(){g.addChangeListener("scriptblocker_overwrite",G.init);g.addChangeListener("sync_enabled",I.configChangeListener);g.addChangeListener("sync_type",I.configChangeListener);g.addChangeListener("sync_id",I.configChangeListener);g.addChangeListener("sync_version",I.configChangeListener);g.addChangeListener("logLevel",function(){pa(g.values.logLevel)});g.addChangeListener("i18n",
function(){e.setLocale(g.values.i18n)});g.addChangeListener("native_import_path",function(){N.setPath(g.values.native_import_path)});g.addChangeListener("incognito_mode",function(){ta()});g.addChangeListener("statistics_enabled",function(){M.setEnabled(g.values.statistics_enabled)});g.addChangeListener("require_blacklist",v.blackCheckAll);g.addChangeListener("script_blacklist_server",v.blackCheckAll);g.addChangeListener("script_blacklist_type",v.blackCheckAll);g.addChangeListener("downloads_extension_whitelist",
H.config_changed_listener);g.addChangeListener("downloads_mode",H.config_changed_listener)},g=function(){var a={},d={enabled:!0,configMode:0,safeUrls:!0,tryToFixUrl:!0,debug:!1,logLevel:0,showFixedSrc:!1,webrequest_modHeaders:"yes",webrequest_fixCSP:"yes",scriptblocker_overwrite:"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/* jshint -W097 */\n'use strict';\n\n// Your code here..."},
{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-core/5.6.15/browser-polyfill.min.js\n// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js\n// @match        <$URL$>\n// ==/UserScript==\n\n/* jshint ignore:start */\nvar inline_src = (<><![CDATA[\n/* jshint ignore:end */\n/* jshint esnext:true */\n\n// Your code here...\n\n/* jshint ignore:start */\n]]\x3e</>).toString();\nvar c = babel.transform(inline_src);\neval(c.code);\n/* jshint ignore:end */"},
{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/extras/coffee-script.js\n// @match        <$URL$>\n// ==/UserScript==\n/* jshint ignore:start */\nvar inline_src = (<><![CDATA[\n\n// Your code here\n\n]]\x3e</>).toString();\nvar compiled = this.CoffeeScript.compile(inline_src);\neval(compiled);\n/* jshint ignore:end */"}],
scriptUpdateCheckPeriod:864E5,scriptUpdateHideNotificationAfter:15E3,scriptUpdateCheckDisabled:!1,scriptUrlDetection:"auto",runtime_fastDocumentStart:!0,runtime_strict_mode:"byscript",runtime_strong_mode:"default",autoReload:!1,appearance_badges:"running",appearance_badge_color:"gcal"===rea.runtime.short_id?"#444":"#ee3131",editor_enabled:!0,editor_keyMap:"windows",editor_indentUnit:4,editor_indentWithTabs:!1,editor_tabMode:"indent",editor_electricChars:!0,editor_autoSave:!1,editor_easySave:!0,native_import:!0,
native_import_path:null,native_import_post_action:"disable",i18n:null,action_menu_columns:2<=n.ACTIONMENU.COLUMNS?2:1,action_menu_scripts_hide_disabled:!1,action_menu_scripts_sort:"position",incognito_mode:"temporary",layout:"default",sync_enabled:!1,sync_type:2,sync_version:2,sync_id:"",statistics_enabled:!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,require_timeout:2E4,require_blacklist:["/^https?:\\/\\/example.com(:[0-9]{1,5})?\\/.*/"],script_blacklist_server:[],script_blacklist_type:"server",script_blacklist_severity:4,page_filter_mode:"black",page_whitelist:["/https?:\\/\\/greasyfork\\.org\\/.*/","http://xkcd.com/970/"],forbiddenPages:"*.paypal.tld/* https://*deutsche-bank-24.tld/* https://*bankamerica.tld/* /^.*:\\/\\/apis\\.google\\.com\\/((?!render)([^\\/]+)\\/)+([^\\/]+)?$/ *://www.facebook.com/plugins/* *://platform.twitter.com/widgets/*".split(" ")},
c=function(c,f){var b=p.getValue(n.CONSTANTS.STORAGE.CONFIG,{}),h=void 0===b[c]?d[c]:b[c];b[c]=f;p.setValue(n.CONSTANTS.STORAGE.CONFIG,b);a[c]&&JSON.stringify(h)!=JSON.stringify(f)&&a[c].forEach(function(a){try{a(c,h,f)}catch(b){console.warn("config: changeListener error",b)}})},e={init:function(){var a=l();e.values={};for(var f in d)d.hasOwnProperty(f)&&function(){var a=f;e.values.__defineGetter__(a,function(){var b=p.getValue(n.CONSTANTS.STORAGE.CONFIG,{});return void 0===b[a]?d[a]:b[a]});e.values.__defineSetter__(a,
function(b){c(a,b)})}();e.images={};e.images.icon="images/icon.png";e.initialized=!0;var b=Ca(),h;for(h in b){var r=b[h];window.setTimeout(function(){v.doSave({url:null,src:r,ask:!1,replace:!0,internal:!0})},1)}a.resolve();return a.promise()},getDefaults:function(){return d},addChangeListener:function(c,f){a[c]||(a[c]=[]);a[c].push(f)}};return e}(),U=function(a,d){return ba(a,d,{internal:!0})},R=function(){var a={key:function(a,f){return n.CONSTANTS.PREFIX.EXTERNAL+s.select([a,f?L.MD5(f):null],function(a){return a}).join(":")},
list:function(a){var f=RegExp("^"+a);return s.select(p.listValues(),function(a){return-1!=a.search(f)})},set:function(b,f,c){b=a.key(b,f);var d={};s.each(c,function(a,b){"content"==b&&(b="base",a=L.encodeS(a));d[b]=a});p.setValue(b,{ts:(new Date).getTime(),url:f,resource:d})},get:function(b,f){var c=a.key(b,f),c=p.getValue(c),d;if(c&&c.resource){var e={};s.each(c.resource,function(a,b){"base"==b&&(b="content",a=L.decodeS(a));e[b]=a});d={ts:c.ts,url:c.url,data:e}}return d},clean:function(b,f){var c=
a.key(b,f);p.deleteValue(c)},cleanAll:function(b,f){var c,d=a.list(a.key(b));if(f){var e={};s.each(f,function(f){f=a.key(b,f);e[f]=!0});c=[];s.each(d,function(a){e[a]||c.push(a)})}else c=d;c.forEach(function(a){p.deleteValue(a)})}},d=function(a,f){var c=l(),d={method:"GET",url:a,retries:n.XMLHTTPREQUEST.RETRIES,responseType:f.via_arraybuffer?"arraybuffer":void 0},e=function(d){var e={content:""};if(4!=d.readyState||200!=d.status&&0!=d.status)c.reject(e);else{var k,m=d.responseHeaders?d.responseHeaders.split("\n"):
null,g;for(g in m){var u=m[g].split(":"),t=u.shift()||"",u=u.join(":")||"";if("content-type"==t.trim().toLowerCase()&&-1!=u.search("image")){k=u.trim();break}}k||(-1!=a.search(".ico$")||-1!=a.search(".jpg$")?k="image/x-icon":-1!=a.search(".gif$")?k="image/gif":-1!=a.search(".png$")?k="image/png":s.isLocalImage(a)&&(k="image/x-icon"));e.meta=k;e.content=f.via_arraybuffer?L.arrbuf2str(d.response):d.responseText;c.resolve(e)}},k=function(){c.reject({})};f.sync?e(U(d,{})):(d.timeout=g.values.require_timeout,
U(d,{onload:e,onerror:k,ontimeout:k}));return c.promise()},c=s.getDebouncer(9E3),e=function(b,f,c){c.no_storage=!0;m(b,f,c).done(function(c){a.set(b,f,c.resource)}).fail(function(){}).always(function(){var c=a.get(b,f);c&&c.data?a.set(b,f,c.data):console.warn("externals: should never happen!")})},m=function(b,f,r){var m=l(),t=A.parse(f),q={sync:r.sync},C;if(f)if(Z.getEvilnessOf(f)>=g.values.script_blacklist_severity)q.resource={blacklisted:!0,content:""},m.reject(q);else if(!r.no_storage&&"file:"!==
t.protocol&&(C=a.get(b,f))){var F=a.key(b,f),B=(new Date).getTime();0<g.values.external_update_interval&&B-C.ts>g.values.external_update_interval&&!c.is(F)&&(1<g.values.external_update_interval&&c.add(F),D&&console.log("externals: resource needs update",f,(new Date(C.ts)).toISOString(),(new Date(B)).toISOString()),window.setTimeout(function(){e(b,f,r)},3E3));q.resource=C.data;m.resolve(q)}else q.sync=!1,"file:"==t.protocol&&-1==f.search(n.REQUESTS.GET_INTERNAL_PATH_REGEXP(!0))?(n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS||
console.warn("externals: Access to local files is forbidden! Loading the following @resource may fail:",f,"-> more info:","http://tampermonkey.net/faq.php#Q204"),C=sa.getSource({url:f,encoding:r.encoding})):C=d(f,{via_arraybuffer:r.via_arraybuffer}),C.done(function(c){!r.no_storage&&t.protocol&&"file:"!==t.protocol&&-1==f.search(n.REQUESTS.GET_INTERNAL_PATH_REGEXP(!0))&&a.set(b,f,c);q.resource=c;m.resolve(q)}).fail(function(a){D&&console.log("externals: get.failed",b,f,a);q.resource={failed:!0,content:""};
m.reject(q)});else q.resource={forbidden:!0,content:""},m.reject(q);return m.promise()},f={getElement:function(b,f){return a.get(b,f)},cleanElement:function(b,f){return a.clean(b,f)},dropAll:function(b){a.cleanAll(b);return l.Pledge()},dropAllBut:function(b,f){a.cleanAll(b,f);return l.Pledge()},loadResources:function(a,c){var d=l();f.getResources(a,c).always(function(){d.resolve()});return d.promise()},loadRequires:function(a,c){var d=l();f.getRequires(a,c).always(function(){d.resolve()});return d.promise()},
getResources:function(a,f){var c={elements:[]},d=l(),e=[],k={via_arraybuffer:!0,sync:!0};f.forEach(function(f){var d={name:f.name},h=m(a,f.url,k),g=l();h.done(function(a){a=a.resource;var b=[f.url,a.content.length].join(),c=T.items.resources.get(b)||{};try{d.resText=c.resText?c.resText:L.UTF8.decode(a.content)}catch(h){d.resText=""}try{d.resURL=c.resUrl?c.resURL:a.meta?"data:"+a.meta+";base64,"+L.Base64.encode(a.content):L.Base64.encode(a.content)}catch(e){d.resURL=f.url}T.items.resources.set(b,{resText:d.resText,
resURL:d.resURL})}).fail(function(a){a.resource&&a.resource.forbidden?console.warn("externals: can't load @resource",f.name,"from forbidden URL",f.unsafe_url):a.resource&&a.resource.blacklisted?console.warn("externals: can't load @resource",f.name,"from blacklisted URL",f.unsafe_url):console.warn("externals: can't load @resource",f.name,"from URL",f.unsafe_url);d.resText="";d.resURL=""}).always(function(a){k.sync&=a.sync;c.elements.push(d);g.resolve()});e.push(g)});l.when(e).always(function(){c.sync=
k.sync;d.resolve(c)});return d.promise()},getRequires:function(a,f){var c={elements:[]},d=l(),e=[],k={encoding:"UTF-8",sync:!0};s.each(f,function(f,d){var h={},g=m(a,f.url,k),u=l();g.done(function(a){h.textContent=a.resource.content||""}).fail(function(a){a.resource&&a.resource.forbidden?(h.textContent='// this @require ("'+encodeURIComponent(f.unsafe_url)+'") is not allowed!\n',console.warn("externals: can't load @require from forbidden URL",f.unsafe_url)):a.resource&&a.resource.blacklisted?(h.textContent=
'// this @require ("'+encodeURIComponent(f.unsafe_url)+'") is blacklisted!\n',console.warn("externals: can't load @require from blacklisted URL",f.unsafe_url)):(h.textContent='// this @require ("'+encodeURIComponent(f.unsafe_url)+'") could not be loaded!\n',console.warn("externals: can't load @require from URL",f.unsafe_url))}).always(function(a){k.sync&=a.sync;c.elements[d]=h;u.resolve()});e.push(u)});l.when(e).always(function(){c.sync=k.sync;c.elements=c.elements.filter(function(a){return a});d.resolve(c)});
return d.promise()}};return f}();exts=R;var ra=function(){var a=function(a,c,e){var m=l(),f=[];e.forEach(function(b){b=b.textContent||"";b=ia.mkCompat(b,a.options.compatopts_for_requires?a:null,"off"!=g.values.runtime_strict_mode);f.push(b)});e="\n"+f.join("\n")+"\n";var b=x.getStorageByUid(a.uuid);c=ia.mkCompat(c,a,"off"!=g.values.runtime_strict_mode);g.values.debug&&(c="debugger;\n"+c);m.resolve({header:a.header,code:c,requires:e,storage:b,script:a});return m.promise()};return{bundle:function(d,
c,e){var m={},f;for(f in c)"includes"!=f&&"matches"!=f&&"requires"!=f&&"resources"!=f&&"excludes"!=f&&"textContent"!=f&&("options"==f?(m[f]=JSON.parse(JSON.stringify(c[f])),m[f].run_at=m[f].run_at||c.options.override.orig_run_at||"document-idle"):m[f]=c[f]);return R.getResources(m.uuid,c.resources).then(function(a){e&&!a.sync&&(D&&console.warn("ri: uncached @external detected -> fast script start disabled"),e=a.sync);m.resources=a.elements;return R.getRequires(m.uuid,c.requires)}).then(function(b){e&&
!b.sync&&(D&&console.warn("ri: uncached @external detected -> fast script start disabled"),e=b.sync);b=b.elements;console.log("run script "+m.name+" @ "+d.url);return a(m,c.textContent,b)})}}}(),ua=function(a){a&&(a+=(-1==a.search("\\?")?"?":"&")+"ts="+(new Date).getTime());return a},va=function(){var a=rea.extension.getViews({type:"popup"});a&&a.length&&rea.extension.sendMessage({method:"updateActions"},function(){})},Y=function(){return{getConfig:function(){var a={version:0,last:0},d={scripts:0},
c=p.getValue(n.CONSTANTS.STORAGE.UPDATE,d);"object"!==typeof c&&(c=d);c||(c=d);void 0==c.black&&(c.black=a);void 0==c.scripts&&(c.scripts=0);return c},setConfig:function(a){a&&p.setValue(n.CONSTANTS.STORAGE.UPDATE,a)}}}(),ja=function(){var a=function(a,c){var k=0,m=0;if(a){var f=e.getMessage("Script_Update"),b=e.getMessage("Check_for_userscripts_updates")+"...";P.show(f,b,rea.extension.getURL("images/icon128.png"),1E4)}f=x.getUidList().map(function(a){var b,f,d,q,C;console.log("update: check for script updates @",
a);return function(){q=x.getByUid(a);if(!q.script||!q.cond)return console.warn("update: inconsistent script entry",a,q),l.Breach();var b=!g.values.scriptUpdateCheckDisabled&&!q.script.enabled&&!c;return c&&q.script.uuid!==c||b||!v.determineSourceURL(q.script)?l.Breach():l.Pledge()}().then(function(){var a=v.determineMetaURL(q,!0);if(!a)return l.Pledge();var b=l();ba({method:"GET",retries:n.XMLHTTPREQUEST.RETRIES,timeout:1E3*n.SCRIPT_DOWNLOAD.TIMEOUT,headers:{Accept:"text/x-userscript-meta"},url:a},
{ondone:function(f){4==f.readyState&&200==f.status?C=w.processMetaHeader(f.responseText):console.log("update: unable to find meta data @ "+a+" req.status = "+f.status);b.resolve()}});return b.promise()}).then(function(){var a=!!C,b=a&&!!C.version,f=b&&(!q.script.version||w.versionCmp(C.version,q.script.version)==w.versionCmp.eNEWER);return a&&b&&!f?l.Breach():l.Pledge()}).then(function(){var a=l(),b={method:"GET",retries:n.XMLHTTPREQUEST.RETRIES,timeout:1E3*n.SCRIPT_DOWNLOAD.TIMEOUT,url:v.determineSourceURL(q.script,
!0)};ba(b,{ondone:function(f){4==f.readyState&&200==f.status?a.resolve(f.responseText):(console.log("update: failed",q.script.name,b.url),a.reject())}});return a.promise()}).then(function(a){var c;var e=q.script.uuid;c=w.createScriptFromSrc(a);c=c.name&&""!=c.name&&void 0!==c.version?(e=x.getMetaByUid(e))&&e.system?null:c.options.compat_uW_gmonkey?w.versionCmp.eERROR:-1!=c.name.search("@")?w.versionCmp.eERROR:e&&c.version==e.version?w.versionCmp.eEQUAL:e&&w.versionCmp(c.version,e.version)==w.versionCmp.eOLDER?
w.versionCmp.eOLDER:w.versionCmp.eNEWER:w.versionCmp.eERROR;return c==w.versionCmp.eNEWER?(k++,b=q.script.name,f=v.determineSourceURL(q.script),d=a,l.Pledge()):l.Breach()}).then(function(){if(g.values.notification_silentScriptUpdate)return l.Pledge();var a=e.getMessage("There_is_an_update_for_0name0_avaiable_",b)+"\n"+e.getMessage("Click_here_to_install_it_"),f=e.getMessage("Just_another_service_provided_by_your_friendly_script_updater_")+":",c=l();P.show(f,a,rea.extension.getURL("images/icon128.png"),
g.values.scriptUpdateHideNotificationAfter,c.resolve);return c.promise()}).then(function(b){var c=a||q.script.uuid;return void 0===b||b.clicked?v.doSave({url:f,uuid:c,replace:!c,src:d,ask:!g.values.notification_silentScriptUpdate}).done(function(a){a&&a.installed&&m++}):l.Breach()})});return l.sidebyside(f).then(function(){0==k&&a&&(D&&console.debug("No update found"),P.show("Narf!",e.getMessage("No_update_found__sry_"),rea.extension.getURL("images/icon128.png"),1E4));return{found:k,installed:m}})};
return{check:function(d,c,k){if(!d&&!g.values.scriptUpdateCheckPeriod)return l.Breach();var m=Y.getConfig();if(!d&&(new Date).getTime()-m.scripts<g.values.scriptUpdateCheckPeriod)return l.Breach();var f=l();d=function(){b&&(window.clearTimeout(b),b=null);h&&h.cancel();a(c,k).done(function(a){f.resolve(a.installed)}).fail(function(){f.resolve(null)});m=Y.getConfig();m.scripts=(new Date).getTime();Y.setConfig(m)};var b,h,r=function(){h=null;var a=e.getMessage("Script_Update"),b=e.getMessage("Waiting_for_sync_to_finish")+
"...";h=P.show(a,b,rea.extension.getURL("images/icon128.png"),6E4)};I.enabled?(I.addSyncDoneCallback(d),I.sync(50,!1),c&&(b=window.setTimeout(r,500))):d();return f.promise()}}}();trup=ja;var v=function(){var a=function(a){a.sort(function(a,f){return a.position-f.position});return a},d=function(a){void 0===a.ask&&(a.ask=!0);if(void 0===a.url||null==a.url)a.url="";""===a.force_url&&(a.force_url=null);var b=w.createScriptFromSrc(a.src),c=null,d={heading:null,errors:[],info:[],warnings:[],flags:{}},k=
l(),t=(new Date).getTime(),q=a.save&&!a.ask&&g.values.editor_easySave,n=a.uuid,F;b.name&&void 0!=b.version?F=l.Pledge():(d.errors.push(e.getMessage("Invalid_UserScript__Sry_")+"\n\n"),a.name&&d.errors.push(e.getMessage("Script_name_0url0",a.name)+"\n\n"),a.url&&d.errors.push(e.getMessage("Downloaded_from_0url0",a.url)),console.warn("scriptman: invalid userscript",d,b),F=l.Breach());F.then(function(){a.replace&&!n&&(n=x.getUidsByName(b.name,b.namespace)[0]);if(n)c=x.getMetaByUid(n);else if(b.uuid)n=
b.uuid;else if(a.replace)n=s.createUUID();else return console.error("scriptman: neither UUID, @uuid nor replace option set"),l.Breach();if(""!==n.replace(/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/,""))return console.error("scriptman: invalid UUID",n),l.Breach();if(!a.clean&&!a.defaultscript&&c&&c.system)return l.Breach()}).then(function(){if(a.clean&&a.name&&a.name!=b.name||-1!=b.name.search("\n"))return d.errors.push(e.getMessage("Invalid_UserScript_name__Sry_")),l.Breach()}).then(function(){if(b.options.compat_uW_gmonkey)return d.errors.push(e.getMessage("This_script_uses_uW_gm_api_")),
l.Breach()}).then(function(){if(c){c.name!=b.name&&(d.flags.renamed=!0);if(c.lastModified&&void 0!==a.lastModified&&c.lastModified!==a.lastModified){var k=e.getMessage("some_secs");try{var m=Math.max(1,Math.floor((t-c.lastModified)/1E3));isNaN(m)||(k=m)}catch(g){}d.warnings.push(e.getMessage("CONFLICT__This_script_was_modified_0t0_seconds_ago_",k));d.flags.forceAsk=!0}b.version==c.version&&(a.save?d.flags.modification=!0:d.flags.reset=!0);a.clean&&(d.flags.factory=!0)}else d.flags.first_install=!0;
b.includes.length||b.matches.length||(k="/"+A.staticVars.urlAllHttp_+"/",q||a.internal||d.warnings.push(e.getMessage("This_script_does_not_provide_any__include_information_")+"\n"+e.getMessage("Tampermonkey_assumes_0urlAllHttp0_in_order_to_continue_",k)),b.includes.push(k));d.flags.sync=!!a.sync;d.flags.internal=a.internal;d.flags.ask=a.ask}).then(function(){b.uuid=n;b.lastUpdated=a.force_meta&&a.force_meta.lastModified||t;b.system=a.defaultscript;b.evilness=v.getEvilness(b);b.position=v.determineLastPosition()+
1;d.flags.factory||d.flags.reset||(a.force_url&&(b.updateURL=null,b.downloadURL=a.force_url),c&&(b.options.override=c.options.override,b.options.comment=c.options.comment));b.options.override.orig_includes=b.includes;b.options.override.orig_excludes=b.excludes;b.options.override.orig_matches=b.matches;b.options.override.orig_noframes=b.options.noframes;b.options.override.orig_run_at=b.options.run_at||"document-idle";b.options.noframes=null;b.options.run_at=null}).then(function(){if(c&&(b.fileURL=
c.fileURL,b.position=c.position,c.sync&&(b.sync=c.sync),!d.flags.factory&&!d.flags.reset)){b.enabled=c.enabled;b.options.noframes=c.options.noframes;b.options.run_at=c.options.run_at;b.options.awareOfChrome||(b.options.compat_forvarin=c.options.compat_forvarin);a.save&&!a.force_url&&(b.downloadURL=c.downloadURL||b.downloadURL);var k=m.determineMetaURL(c),g=m.determineMetaURL(b),k=k?A.woHash(k):k,g=g?A.woHash(g):g;k==g||q||a.internal||d.warnings.push(e.getMessage("The_update_url_has_changed_from_0oldurl0_to__0newurl0",
[k,g]))}}).then(function(){if(c&&!d.flags.factory&&b.version==c.version&&(a.defaultscript||a.noreinstall))return l.Breach()}).then(function(){c?(d.flags.factory||d.flags.reset?(d.flags.reset?(d.heading=e.getMessage("You_are_about_to_reinstall_a_UserScript_"),d.flags.reinstall=!0):(d.heading=e.getMessage("You_are_about_to_install_a_UserScript_"),d.flags.install=!0),a.internal||d.warnings.splice(0,0,e.getMessage("All_script_settings_will_be_reset_"))):d.flags.modification?d.heading=e.getMessage("You_are_about_to_modify_a_UserScript_"):
w.versionCmp(b.version,c.version)==w.versionCmp.eOLDER?(d.heading=e.getMessage("You_are_about_to_downgrade_a_UserScript"),d.flags.downgrade=!0,q||a.internal||d.warnings.splice(0,0,e.getMessage("The_downgraded_script_might_have_problems_to_read_its_stored_data_"))):(d.heading=e.getMessage("You_are_about_to_update_a_UserScript_"),d.flags.update=!0),d.info.push({label:e.getMessage("Installed_Version_"),value:"v"+c.version})):(d.heading=e.getMessage("You_are_about_to_install_a_UserScript_"),q||a.internal||
d.info.splice(0,0,e.getMessage("Malicious_scripts_can_violate_your_privacy_")),d.flags.install=!0);d.flags.install?d.action=e.getMessage("Install"):d.flags.reinstall?d.action=e.getMessage("Reinstall"):d.flags.modification?d.action=e.getMessage("Modify"):d.flags.downgrade?d.action=e.getMessage("Downgrade"):d.flags.update&&(d.action=e.getMessage("Update"))}).then(function(){a.url&&(b.fileURL=a.url);a.sync&&(b.sync=a.sync);a.force_options&&s.copy(a.force_options,b.options,(new w.Script).options,!0);
a.force_settings&&s.copy(a.force_settings,b,["enabled","position"]);b=v.mergeCludes(b)}).then(function(){var a=!1,c;for(c in b.options)if(-1!=c.search("compat_")&&!0===b.options[c]){a=!0;break}a&&d.info.push({label:e.getMessage("Note"),value:e.getMessage("A_recheck_of_the_GreaseMonkey_FF_compatibility_options_may_be_required_in_order_to_run_this_script_")})}).then(function(){["requires","resources"].forEach(function(a){b[a]=s.map(b[a],function(a){a.unsafe_url=a.url;a.url=A.sanitize(a.unsafe_url,b.fileURL?
b.fileURL.split("/").slice(0,-1).join("/"):null);return a})})}).done(function(){k.resolve({script:b,messages:d,short_info:[{label:e.getMessage("Author"),prop:"author"},{label:e.getMessage("Description"),prop:"description"},{label:e.getMessage("Source"),prop:"fileURL"}]})}).fail(function(){k.reject({messages:d})});return k.promise()},c=function(a){var b=l(),c=a.messages,d=a.script,e=!c.flags.internal,k=function(){var a=m.doModify(d.uuid,d,e)||{};(c.flags.first_install||c.flags.factory)&&x.setStorageByUid(d.uuid,
{ts:(new Date).getTime()});return a},g={lastModified:void 0,installed:!0,renamed:c.flags.renamed};c.warnings.length||c.flags.ask?fa.install(a).done(function(a){a.ok&&k();g.installed=a.ok;g.aborted=a.aborted;b.resolve(g)}).fail(function(a){b.reject(a)}):(k(),b.resolve(g));return b.promise()},k=s.getDebouncer(1E3),m={determineSourceURL:function(a,b){if(!a)return null;var c=s.select([a.downloadURL,a.fileURL],function(a){if(!a||"file:"!==A.parse(a).protocol)return a})[0];return c&&b?ua(c):c},determineMetaURL:function(a,
b){if(!a)return null;var c;a.fileURL&&(c=a.fileURL.replace(".user.js",".meta.js"),a.fileURL==c&&(c=a.fileURL.replace(".tamper.js",".meta.js")),a.fileURL==c&&(c=null));return(c=s.select([a.updateURL,a.downloadURL,c],function(a){if(!a||"file:"!==A.parse(a).protocol)return a})[0])&&b?ua(c):c},mergeCludes:function(a){var b,c,d=a.options.override;a.includes=d.merge_includes&&d.orig_includes?d.orig_includes.slice():[];a.excludes=d.merge_excludes&&d.orig_excludes?d.orig_excludes.slice():[];a.matches=d.merge_matches&&
d.orig_matches?d.orig_matches.slice():[];for(b=0;b<d.use_includes.length;b++)c=a.excludes.indexOf(d.use_includes[b]),0<=c&&a.excludes.splice(c,1),a.includes.push(d.use_includes[b]);if("undefined"!==typeof d.use_matches)for(b=0;b<d.use_matches.length;b++)c=a.excludes.indexOf(d.use_matches[b]),0<=c&&a.excludes.splice(c,1),a.matches.push(d.use_matches[b]);for(b=0;b<d.use_excludes.length;b++)a.excludes.push(d.use_excludes[b]);return a},doSave:function(a){return d(a).then(c)},doRemove:function(a,b){x.removeByUid(a,
b);x.setStorageByUid(a,null);R.dropAll(a);return l.Pledge()},doModify:function(a,b,c){void 0===c&&(c=!0);x.setByUid(a,b,c);return c?R.loadResources(a,b.resources).then(function(){return R.loadRequires(a,b.requires)}).then(function(){return R.dropAllBut(a,s.map([].concat(b.resources).concat(b.requires),function(a){return a.url}))}):l.Pledge()},exportToJson:function(a,b){var c=l(),d=v.determineScriptsToRun(null);a&&(d=s.select(d,function(b){return a[b.uuid]}));d=na(d,!0);b&&!b.storage||d.forEach(function(a){a.storage=
x.getStorageByUid(a.uuid)});d={scripts:d};if(!b||b.global_settings)d.global_settings=p.getValue(n.CONSTANTS.STORAGE.CONFIG,{});c.resolve(d);return c.promise()},importFromJson:function(a){if(!a||!a.scripts||!a.scripts.length)return l.Breach();for(var b={},e=[],k={},g=0,m;m=a.scripts[g];g++)try{var q=l();"new-user-script"!=m.uuid&&(m.storage&&(k[m.uuid]=m.storage),d({uuid:m.uuid,name:m.name,src:m.source,force_settings:{enabled:m.enabled,position:m.position},force_options:m.options,force_meta:{lastModified:m.lastModified},
replace:!0,url:m.file_url||m.update_url,ask:!1}).done(function(a){b[s.createUUID()]=a;q.resolve()}).fail(function(a){console.warn("import: Error @ script",m.name,a);q.resolve()}),e.push(q.promise()))}catch(C){console.log("import: Error while importing script",m.name,C)}var F=function(){var a=l();l.when(e).always(function(){a.resolve()});return a.promise()}().then(function(){return fa.import(b,a.global_settings)}).then(function(a){var f=l(),d=[],e=[];if(a.ok)for(var h=0,m;m=a.import_ids[h];h++)(function(){var a=
m;if(b[a]){b[a].messages.warnings=[];var f=c(b[a]).done(function(){var c;(c=b[a].script.uuid)&&k[c]&&(c=x.setStorageByUid(c,{data:k[c].data||{},ts:(new Date).getTime()}),e.push(c))});d.push(f)}})();l.when(d).always(function(){v.reorderScripts();l.when(e).always(function(){f.resolve(a)})});return f.promise()}).then(function(b){return a.global_settings&&b.global_settings?(b=p.setValue(n.CONSTANTS.STORAGE.CONFIG,a.global_settings).then(function(){F.done(function(){window.setTimeout(V.reset,1)});return l.Pledge({global_settings:!0})}),
p.setTemporary(!0),b):l.Pledge({})});return F},installFromUrl:function(a,b,c){var d=l(),g=A.parse(a),t={messages:{errors:[e.getMessage("Unable_to_load_script_from_url_0url0",a)],warnings:[]}};b=b||{};c=c||{};var q=[a,JSON.stringify(b)].join("_");if(k.is(q))return D&&console.log("scriptman: de-bounced installFromUrl",a),l.Breach();k.add(q);if(!g.protocol.match(/(https?|file):/))return console.warn("scriptman: can't install from ",a),l.Breach(t);"file:"!=g.protocol||n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS||
console.warn("scriptman: Access to local files is forbidden! Loading the following script for installation may fail:",a,"-> more info:","http://tampermonkey.net/faq.php#Q204");var p=function(a,b){if(!a)if(b)a=t,"file:"!=g.protocol||n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS||a.messages.warnings.unshift(e.getMessage("Tampermonkey_has_no_file_access_permission_"));else{d.reject();return}a.heading=e.getMessage("You_are_about_to_install_a_UserScript_");c.silent_fail?d.reject(a):fa.installError(a).always(function(a){d.reject(a)})},
q=function(a){p(null,a)};U({method:"GET",retries:n.XMLHTTPREQUEST.RETRIES,timeout:1E3*n.SCRIPT_DOWNLOAD.TIMEOUT,url:a},{onload:function(c){if(4==c.readyState)if(200==c.status||0==c.status){var e={url:a,src:c.responseText,ask:!0,replace:!0};b&&s.each(b,function(a,c){e[c]=b[c]});m.doSave(e).done(function(a){d.resolve(a.installed)}).fail(p)}else d.reject()},onerror:q,ontimeout:q});return d.promise()},determineLastPosition:function(){var a=0;x.getUidList().forEach(function(b){var c=x.getByUid(b);c.script&&
c.cond?c.script.position&&c.script.position>a&&(a=c.script.position):console.warn("scriptman: inconsistent script entry",b)});var b=new w.Script;b.position>a&&(a=b.position);return a},matchUrl:function(a,b,c){var d,e;try{!c&&1<b.length&&"/"==b.substr(0,1)?d=RegExp(".*"+b.replace(/^\//g,"").replace(/\/$/g,"")+".*","i"):c?(e=A.getRegExpFromMatch(b),d=RegExp(e)):(e=A.getRegExpFromInclude(b,{tryToFixUrl:g.values.tryToFixUrl,safeUrls:g.values.safeUrls}),d=RegExp(e,"i"))}catch(k){return console.warn("scriptman: invalid regexp ",
b),!1}return""===a.replace(d,"")},validUrl:function(a,b,c){var d,e=!1;if(b.inc||b.match){for(d in b.inc)if("string"!==typeof b.inc[d])console.warn("scriptman: include["+d+'] "'+b.inc[d]+'" '+(c?"@"+c+" ":"")+"can't be compared to \""+a+'"');else if(m.matchUrl(a,b.inc[d])){D&&console.log('scriptman: @include "'+b.inc[d]+'" matched'+(c?" ("+c+")":'"'));e=!0;break}if(b.match)for(d in b.match)if("string"!==typeof b.match[d])console.warn("scriptman: match["+d+'] "'+b.match[d]+'" '+(c?"@"+c+" ":"")+"can't be compared to \""+
a+'"');else if(m.matchUrl(a,b.match[d],!0)){D&&console.log('scriptman: @match "'+b.match[d]+'" matched'+(c?" ("+c+")":'"'));e=!0;break}if(!e)return e}else e=!0;for(d in b.exc)if(m.matchUrl(a,b.exc[d])){D&&console.log('scriptman: @exclude "'+b.exc[d]+'" matched'+(c?" ("+c+")":'"'));e=!1;break}return e},getEvilness:function(a){var b=0;return a.fileURL&&(b=Z.getEvilnessOf(a.fileURL))||a.downloadURL&&(b=Z.getEvilnessOf(a.downloadURL))||a.updateURL&&(b=Z.getEvilnessOf(a.updateURL))?(D&&console.log("scriptman: found blacklisted script",
a),b):0},blackCheckAll:function(){x.getUidList().forEach(function(a){var b=x.getByUid(a);if(b.script&&b.cond){var c=v.getEvilness(b.script);if(c!==b.script.evilness){if(c||void 0!==b.script.evilness)D&&console.log("scriptman: write blacklist state of ",b.script.name,c),c&&M.tS(b.script.name,c,"b");b.script.evilness=c;m.doModify(a,b.script,!1)}}})},reorderScripts:function(c,b){var d=m.determineScriptsToRun();if(c)for(var e=0;e<d.length;e++){var k=d[e];k.uuid==c&&(k.position=Number(b)+(k.position<b?
0.5:-0.5))}d=a(d);e=1;for(k=0;k<d.length;k++){var g=d[k];g.position=e++;m.doModify(g.uuid,g,!1)}},getUniqueScriptsForTab:function(a){var b=[];z.get.empty(a.id)?console.warn("bg: WARN: Tabs.get.urls["+a.id+"] is empty!"):s.each(z.get.urls(a.id),function(a,c){if(ha.isAllowed(c))for(var f=v.determineScriptsToRun(c),d=0;d<f.length;d++){for(var e=!1,k=0;k<b.length;k++)if(b[k].uuid==f[d].uuid){e=!0;break}e||b.push(f[d])}});return b},determineScriptsToRun:function(c){var b=[];D&&console.log("scriptman: determineScriptsToRun @"+
c);x.getUidList().forEach(function(a){if(c){var d=p.getValue(n.CONSTANTS.PREFIX.COND+a,null);if(!d||!m.validUrl(c,d,a))return}d=x.getByUid(a);d.script&&d.cond?b.push(d.script):console.warn("scriptman: inconsistent script entry",a,d)});return a(b)},isContexter:function(a){return a.options&&("context-menu"===a.options.run_at||null===a.options.run_at&&"context-menu"===a.options.override.orig_run_at)},determineOrigin:function(a){if(a=a.fileURL||a.downloadURL||a.updateURL){var b=a.match(/https?:\/\/userscripts\.org\/scripts\/(source|version)\/([0-9]{1,9})\.user\.js/)||
a.match(/https?:\/\/userscripts-mirror\.org\/scripts\/(source|version)\/([0-9]{1,9})\.user\.js/);if(b&&3==b.length)return{id:b[2],token:"uso",url:"http://userscripts-mirror.org/scripts/show/"+b[2],issue_url:"http://contactbyweb.com/userscripts-mirror"};if((b=a.match(/https?:\/\/greasyfork\.org\/scripts\/([^/]+)\/code\/.*\.user\.js/))&&2==b.length)return{id:b[1],token:"gf",url:"https://greasyfork.org/scripts/"+b[1],issue_url:"https://greasyfork.org/scripts/"+b[1]+"/feedback"};if((b=a.match(/https?:\/\/openuserjs\.org\/install\/([^/]+)+\/(.*)\.user\.js/))&&
3==b.length)return b.shift(),{id:b.join("/"),token:"ouj",url:"https://openuserjs.org/scripts/"+b[0]+"/"+b[1],issue_url:"https://openuserjs.org/scripts/"+b[0]+"/"+b[1]+"/issues"};if((b=a.match(/https?:\/\/monkeyguts\.com\/(codepages\/)?([0-9]{1,9})\.user\.js/))&&3==b.length)return{id:b[2],token:"mog",url:"https://monkeyguts.com/code.php?id="+b[2],issue_url:"https://monkeyguts.com/code.php?nav=rev&id="+b[2]};if((a=a.match(/https?:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/.*\.user\.js/)||a.match(/https?:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/.*\.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"}}}};return m}(),x=function(){var a=[],d={init:function(){p.addDifferentOriginChangeListener(n.CONSTANTS.PREFIX.STORE,function(a,e){if(e&&e.hasOwnProperty("value")&&e.origin){var m=a.replace(n.CONSTANTS.PREFIX.STORE,""),f;for(f in e.value.data)e.value.data.hasOwnProperty(f)&&function(){var a=f,c=e.value.data[f];d.notifyStorageListeners({uuid:m},null,function(d){var f=
{data:{},ts:0};f.data[a]=c;f.ts=e.value.data.ts;var m={storage:f};void 0===f.data[a]&&(m.removed=a);d(m)})}()}})},getUidList:function(){var a=RegExp("^"+n.CONSTANTS.PREFIX.SCRIPT_UID),d=[];p.listValues().forEach(function(e){-1!=e.search(a)&&d.push(e.replace(a,""))});return d},getUidsByName:function(a,e){var m=[];d.getUidList().forEach(function(f){var b=d.getMetaByUid(f);!b||b.name!=a||e&&e!=b.namespace||m.push(f)});return m},getUidByName:function(a){console.warn("sb: deprecated fn");return d.getUidsByName(a)[0]},
getStorageByUid:function(a){a=p.getValue(n.CONSTANTS.PREFIX.STORE+a,{ts:0,data:{}});"undefined"===typeof a.ts&&(a.ts=0);"undefined"===typeof a.data&&(a.data={});return a},setStorageByUid:function(a,d){return d?p.setValue(n.CONSTANTS.PREFIX.STORE+a,d):p.deleteValue(n.CONSTANTS.PREFIX.STORE+a)},getMetaByUid:function(a){return p.getValue(n.CONSTANTS.PREFIX.META+a,null)},getByUid:function(a){if(!a)return console.error("sb: no UUID set"),{};var d,e=p.getValue(n.CONSTANTS.PREFIX.META+a,null);if(e){var f=
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};f(e.requires);f(e.resources);e.uuid=a;e.textContent=p.getValue(n.CONSTANTS.PREFIX.SCRIPT+a,e.textContent);e.textContent&&(d=e)}return{script:d,cond:p.getValue(n.CONSTANTS.PREFIX.COND+a,null)}},setByUid:function(a,d,e){var f={};if(!a)return console.error("sb: no UUID set",d),f;var b=p.getValue(n.CONSTANTS.PREFIX.META+a),h=!b;p.setValue(n.CONSTANTS.PREFIX.SCRIPT_UID+a,d.name);p.setValue(n.CONSTANTS.PREFIX.COND+
a,{inc:d.includes,match:d.matches,exc:d.excludes});p.setValue(n.CONSTANTS.PREFIX.SCRIPT+a,d.textContent);d.textContent=null;e&&(f.lastModified=(new Date).getTime(),d.lastModified=f.lastModified);p.setValue(n.CONSTANTS.PREFIX.META+a,d);e&&(ka.onScriptsChanged(),h?I.scriptAddedCb(d.name,d):I.scriptChangedCb(d.name,d,b),g.values&&M.tS(d.name,d.fileURL,h?"i":"u"));T.items.rundata.removeAll();return f},removeByUid:function(a,e){void 0===e&&(e=!0);var m=d.getByUid(a);p.deleteValue(n.CONSTANTS.PREFIX.SCRIPT_UID+
a);p.deleteValue(n.CONSTANTS.PREFIX.COND+a);p.deleteValue(n.CONSTANTS.PREFIX.SCRIPT+a);p.deleteValue(n.CONSTANTS.PREFIX.META+a);p.deleteValue(n.CONSTANTS.PREFIX.STORE+a);e&&(ka.onScriptsChanged(),m.script&&m.cond&&I.scriptRemovedCb(m.script.name,m.script),g.values&&M.tS(m.script.name,null,"r"));T.items.rundata.removeAll();return{}},addStorageListener:function(c,d,e,f,b){a.push({tabid:c,id:d,uuid:e,time:f,response:b})},removeStorageListeners:function(c,d){void 0===d&&(d=!0);var e=a;a=[];for(var f in e){var b=
e[f];try{void 0!==c.tabid&&c.tabid!==b.tabid||void 0!==c.uuid&&c.uuid!==b.uuid||void 0!==c.id&&c.id!==b.id?a.push(b):d&&b.response({})}catch(h){D&&console.debug("sb: listener clear for script",c,"failed! Page reload?!")}}},notifyStorageListeners:function(c,d,e){c=c||{};d=d||{};for(var f in a){var b=a[f];try{void 0!==d.uuid&&b.uuid===d.uuid||void 0!==d.tabid&&b.tabid===d.tabid||void 0!==d.id&&b.id===d.id||void 0!==c.tabid&&c.tabid!==b.tabid||void 0!==c.uuid&&c.uuid!==b.uuid||void 0!==c.id&&c.id!==
b.id||e&&e(b.response)}catch(h){console.log("sb: listener notification for script",c,"failed! Page reload?!")}}}};return d}();scbr=x;var wa=function(){var a=function(a,c){var k=null,g=a.sender,f=this,b=function(b){try{a.postMessage(b)}catch(c){}};if("xhr"==c.method){var h=function(){a.disconnect()};c.details.convertBinary=!0;c.details.partialSize=c.details.partialSize||n.XMLHTTPREQUEST.PARTIAL_SIZE;var r={};Object.keys(c.callbacks).forEach(function(a){r[a]=function(c){c={data:c};c[a]=!0;b(c);"ondone"===
a&&h()}});r.ondone||(r.ondone=h);ba(c.details,r)}else if("download"==c.method)H.start(c.details,{onload:function(a){b({load:!0,data:a})},onprogress:function(a){b({progress:!0,data:a})},onerror:function(a){b({error:!0,data:a})},ontimeout:function(a){b({timeout:!0,data:a})},ondone:function(){a.disconnect()}});else if("addStorageListener"==c.method)g.tab?(x.addStorageListener(g.tab.id,c.id,c.uuid,(new Date).getTime(),b),k=function(){x.removeStorageListeners({uuid:c.uuid,id:c.id},!1)}):(console.log(e.getMessage("Unable_to_load_storage_due_to_empty_tabID_")),
b({error:!0}));else if("removeStorageListener"==c.method)g.tab?(x.removeStorageListeners({uuid:c.uuid,id:c.id}),b({error:!1})):(console.warn("Unable to remove storage listener due to empty tabID!"),b({error:!0}));else if("saveStorageKey"==c.method)g.tab?c.uuid&&(g=x.getStorageByUid(c.uuid),g.data[c.key]=c.value,g.ts=c.ts,x.setStorageByUid(c.uuid,g),x.notifyStorageListeners({uuid:c.uuid},{id:c.id},function(a){var b={data:{},ts:0};b.data[c.key]=c.value;b.ts=c.ts;var d={storage:b};void 0===b.data[c.key]&&
(d.removed=c.key);a(d)})):console.log(e.getMessage("Unable_to_save_storage_due_to_empty_tabID_")),b({});else if("openInTab"==c.method){var k=["active"],u={url:c.details.url};if(c.details.options){for(var l=0;l<k.length;l++)void 0!==c.details.options[k[l]]&&(u[k[l]]=c.details.options[k[l]]);c.details.options.insert&&(u.index=g.tab.index+1)}k=function(){f.disconnected=!0;f.tabId&&delete X[f.tabId]};rea.tabs.create(u,function(a){f.tabId=a.id;X[a.id]={onClose:function(){b({close:!0})}};b({success:!0,
tabId:a.id})})}else if("nameTab"==c.method){if(f.tabId){var q=3,p=function(){z.listeners.once.whenReady(f.tabId,function(){rea.tabs.sendMessage(f.tabId,{method:"setForeignAttr",attr:"name",value:c.name},function(a){a?b({name:c.name}):0<q--?p():D&&console.warn("foreignAttr: error setting attr")})})};p()}}else"closeTab"==c.method?(f.tabId&&X[f.tabId]&&rea.tabs.remove(f.tabId),b({}),window.setTimeout(function(){try{f.disconnected||a.disconnect()}catch(b){}f.disconnected=!0},1E3)):"registerMenuCmd"==
c.method&&(g.tab?($.add(g.tab.id,g.tab.url,c.name,c.accessKey,c.menuId,b),va(),k=function(){$.clearById(c.menuId);va()}):(console.log("Unable to register menu cmd due to empty tabID!"),b({run:!1})));k&&a.onDisconnect.addListener(k)};return function(d){if(E.late){var c={};d.onMessage.addListener(function(e){a.apply(c,[d,e])})}else E.registerLateCallback(function(){wa(d)})}}(),da={ping:{allow:{insecure:!0},exec:function(a,d,c){c({pong:!0,instanceID:qa,config:{layout:g.values.layout}})}},newTab:{allow:{extpage:!0},
exec:function(a,d,c){rea.tabs.create({url:a.url},function(a){c({tabId:a.id})})}},getTab:{allow:{script:!0},exec:function(a,d,c){d.tab&&a.uid?(O[d.tab.id]||(O[d.tab.id]={}),O[d.tab.id][a.uid]||(O[d.tab.id][a.uid]={}),c({data:O[d.tab.id][a.uid]})):(console.log("bg: unable to process request",d,a),c({data:null}))}},getTabs:{allow:{script:!0},exec:function(a,d,c){if(a.uid){d={};for(var e in O)d[e]={},d[e]=O[e][a.uid];c({data:d})}else console.log("bg: unable to process request",d,a),c({data:null})}},setTab:{allow:{script:!0},
exec:function(a,d,c){if(d.tab&&a.uid){O[d.tab.id]||(O[d.tab.id]={});var e={},g;for(g in a.tab)e[g]=a.tab[g];O[d.tab.id][a.uid]=e}else console.log("bg: unable to process request",d,a);c({})}},focusTab:{allow:{script:!0},exec:function(a,d,c){(a=d&&d.tab?d.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,d,c){var e=d&&d.tab?d.tab.id:null;e?rea.tabs.query({windowType:"normal"},function(a){1>=
a.length?(console.warn("bg:","refused to close last tab!"),c({error:"refused to close last tab!"})):rea.tabs.remove(e,function(){c({})})}):c({error:"internal error"})}},copyToClipboard:{allow:{script:!0,extpage:!0},exec:function(a,d,c){d.tab?oa.copy(a.data):console.log("bg: unable to process request",d,a);c({})}},setOption:{allow:{extpage:!0},exec:function(a,d,c){d="options"==d.extpage||"options"==a.origin;g.values[a.name]=a.value;d?W.create("options.settings").done(function(a){c({items:a,options:g.values})}).fail(function(a){c({error:a,
options:g.values})}):c({})}},reportAnIssue:{allow:{extpage:!0},exec:function(a,d,c){var e,g,f;a.uuid&&(e=x.getByUid(a.uuid))&&e.script&&e.cond&&(d=v.determineOrigin(e.script),"author"==a.to&&e.script.supportURL?(g={url:e.script.supportURL},f=d?[a.to,d.token,d.id].join(":"):[a.to,g.url].join(":")):d&&(g=d,f=[g.token,g.id].join(":")),g&&(M.tS(e.script.name,f,"m"),rea.tabs.create({url:g.issue_url||g.url,active:!0},function(){})));c({})}},begEvent:{allow:{extpage:!0},exec:function(a,d,c){if("dialog"==
a.action)aa.dialog.shown(a.extra);else if("clicked"==a.action){var e,g;a.extra&&(e=a.extra.amount,g=a.extra.currency);aa.clicked(a.type,e,g)}else if(aa.button[a.action])aa.button[a.action](a.extra);else console.log("bg: Warning: unknown request ",a);c({})}},buttonPress:{allow:{extpage:!0},exec:function(a,d,c){var e=function(){c({})};if("reset_simple"==a.name)V.reset(e);else if("reset_factory"==a.name)V.factoryReset(e);else if("create_tesla_data"==a.name)I.createTeslaData().done(function(a){oa.copy({content:L.UTF8.encode(a.join("<br>")),
type:"html"});e()});else if("reset_chrome_sync"==a.name)I.reset().always(e);else if("install_tests"==a.name)(d=ca.framework.prepare(v.doSave,n.RUNTIME.BROWSER,e))&&console.error(d);else if("enabled"==a.name)g.values[a.name]=!g.values[a.name],c({});else if("installFromUrl"==a.name)v.installFromUrl(a.data).always(function(){c({})});else if("externals_delete"==a.name)R.cleanElement(a.scriptuid,a.url),W.create("options.scripts").done(function(a){c({items:a,options:g.values})}).fail(function(a){c({error:a,
options:g.values})});else if("run_script_updates"==a.name)if(a.scriptuid){var m;ja.check(!0,!1,a.scriptuid).done(function(a){m=a}).always(function(){c({scriptuid:a.scriptuid,updatable:m})})}else ja.check(!0,!0),c({});else console.log("bg: Warning: unknown button "+a.name),c({})}},loadTree:{allow:{extpage:!0},exec:function(a,d,c){W.create(a.referrer,{complete:a.complete,uuid:a.uuid}).done(function(a){c({items:a,i18n:g.values.i18n,options:g.values,begging:aa.needed()})}).fail(function(a){c({error:a,
options:g.values})})}},modifyScriptOptions:{allow:{extpage:!0},exec:function(a,d,c){if(a.uuid){var e="options"==d.extpage||"options"==a.origin,m=void 0==a.reload||!0==a.reload,f=x.getByUid(a.uuid);if(f.script&&f.cond){var b=!1,h=new w.Script;Object.keys(h.options).forEach(function(b){"undefined"!==typeof a[b]&&(f.script.options[b]=a[b])});Object.keys(h.options.override).forEach(function(c){-1!=c.search("merge_")&&"undefined"!==typeof a[c]&&(f.script.options.override[c]=a[c],b=!0)});"undefined"!==
typeof a.enabled&&(f.script.enabled=a.enabled);"undefined"!==typeof a.includes&&(f.script.options.override.use_includes=a.includes,f.script.options.override.use_excludes=a.excludes,f.script.options.override.use_matches=a.matches,b=!0);b&&(f.script=v.mergeCludes(f.script));v.doModify(f.script.uuid,f.script).done(function(){m?(void 0!==a.position&&v.reorderScripts(a.uuid,a.position),e?da.loadTree.exec({referrer:"options.scripts"},d,c):rea.tabs.getSelected(null,function(b){W.create("actions").done(function(a){c({items:a,
i18n:g.values.i18n,options:{enabled:g.values.enabled,layout:g.values.layout}})}).fail(function(){c({i18n:g.values.i18n,options:{enabled:g.values.enabled,layout:g.values.layout}})});a.uuid&&g.values.autoReload&&rea.tabs.sendMessage(b.id,{method:"reload",frameId:0},function(){})})):c({})}).fail(function(){c({})});return!0}}c({})}},modifyNativeScript:{allow:{extpage:!0},exec:function(a,d,c){if(a.nid){var k=void 0==a.reload||!0==a.reload;N.getUserscriptById(a.nid).then(function(c){if(c)if("installed"==
a.actionid){if("false"==a.value)return N.uninstall(c)}else{if("enabled"==a.actionid)return N.setEnabled(c,a.value);if("imported"==a.actionid&&"true"==a.value){var f=N.getUserscriptSource(c);if(f)return v.doSave({src:f,ask:!0,replace:!0}).then(function(a){if(a.installed){if("disable"==g.values.native_import_post_action)return N.setEnabled(c,!1);if("uninstall"==g.values.native_import_post_action)return N.uninstall(c)}});rea.tabs.sendMessage(d.tab.id,{method:"showMsg",msg:e.getMessage("Please_double_check_the_native_script_import_settings__")},
function(){})}}else k=!1;return l.Pledge()}).always(function(){k?da.loadTree.exec({referrer:"options.scripts"},d,c):c({})});return!0}c({})}},saveScript:{allow:{extpage:!0},exec:function(a,d,c){var k=void 0===a.reload||!!a.reload,m=function(a){k?W.create("options.scripts").done(function(b){a.items=b;a.options=g.values;c(a)}).fail(function(a){c({error:a,options:g.values})}):c({})};if(a.clean){D&&console.debug("bg: clean userscript "+a.uuid);d=x.getByUid(a.uuid);var f=function(b){W.create("options.scripts").done(function(d){c({cleaned:b.installed,
items:d,options:g.values});b.installed&&x.notifyStorageListeners({uuid:a.uuid},null,function(b){b({storage:x.getStorageByUid(a.uuid)})})}).fail(function(a){c({error:a,options:g.values})})};d.script&&d.cond?v.doSave({name:a.name,uuid:a.uuid,src:d.script.textContent,clean:!0,ask:!0,save:!0}).always(function(a){f(a||{installed:!1})}):(console.error(e.getMessage("fatal_error")+" ("+a.uuid+")!!!"),f({installed:!1}))}else if(a.code){var b=c;k&&(b=function(a){v.reorderScripts();m(a)});a.new_script&&(a.uuid=
s.createUUID());v.doSave({name:a.name,uuid:a.uuid,force_url:a.force_url,src:a.code,ask:!g.values.editor_easySave,lastModified:a.lastModified,save:!0}).always(function(a){b(a||{installed:!1})})}else v.doRemove(a.uuid),v.reorderScripts(),m({})}},exportToJson:{allow:{extpage:!0},exec:function(a,d,c){v.exportToJson(a.ids,a.options).done(function(a){c({json:a})}).fail(function(){c({})})}},importFromJson:{allow:{extpage:!0},exec:function(a,d,c){var k=void 0===a.reload||!!a.reload;v.importFromJson(a.json).fail(function(a){c({error:a||
e.getMessage("An_error_occured_during_import_")})}).done(function(a){var d={reload:a.global_settings};k&&!d.reload?W.create("options.scripts").done(function(a){d.items=a;d.options=g.values;c(d)}).fail(function(a){c({error:a,options:g.values})}):c(d)})}},askCom:{allow:{extpage:!0},exec:function(a,d,c){fa.onMessage(a.data).always(function(a){a.i18n=g.values.i18n;a.options={statistics_enabled:g.values.statistics_enabled};a.ext={version:rea.extension.manifest.version};c(a)})}},installScript:{allow:{insecure:!0},
exec:function(a,d,c){if(d.tab){var g={};v.installFromUrl(a.url,{},{silent_fail:!0}).done(function(a){g={data:null,found:!0,installed:a}}).fail(function(a){g.err=a&&a.messages&&a.messages.errors?a.messages.errors[0]:e.getMessage("Unable_to_parse_this_")}).always(function(){c(g)})}else console.log(e.getMessage("Unable_to_install_script_due_to_empty_tabID_"))}},execMenuCmd:{allow:{extpage:!0},exec:function(a,d,c){(a=$.getById(a.id))?a.response({run:!0,menuId:a.id}):console.error("bg: Error: unable to find MC id "+
a.id);c({})}},getWebRequestInfo:{allow:{script:!0},exec:function(a,d,c){d.tab?c({webRequest:K}):(console.log("Unable to run scripts due to empty tab id"),c({}))}},unLoad:{allow:{script:!0},exec:function(a,d){a.topframe||a.id&&z.events.unload(d.tab.id,d.tab.frameId,a.id)}},prepare:{allow:{script:!0},exec:function(a,d,c){if(d.tab){var e=a.topframe?0:null,m=A.woHash(a.url);z.events.run(d.tab.id,e,a.id,m,function(f){f=s.select(f,function(a){return a});var b=[{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(g.values.downloads_mode))return!0}).map(function(a){return a.m})[0]||"disabled",b={scripts:f,contexters:ka.getContexterCount(),raw:{},inIncognitoContext:rea.extension.inIncognitoContext,downloadMode:b,enforce_strict_mode:"on"==g.values.runtime_strict_mode,use_strong_mode:"on"==g.values.runtime_strong_mode,logLevel:g.values.logLevel,version:rea.extension.manifest.version};if(a.raw&&f.length)for(f=
0;f<a.raw.length;f++)b.raw[a.raw[f]]=Registry.getRaw(a.raw[f]);c(b);S.setIcon(d.tab.id);S.setBadge(d.tab.id)});return!0}c({});return!1}},scriptBlockerDetected:{allow:{script:!0},exec:function(a,d,c){a.xml_style_detected||-1!=a.url.search("\\.xml$")?console.warn("blocker: unable to get unsafeWindow..."):G.requestPermissionEx(function(a,d){var f=a&&d?e.getMessage("Please_reload_this_page_in_order_to_run_your_userscripts_"):null;c({alert:f})});z.set.blocker(d.tab.id);S.setIcon(d.tab.id)}},notification:{allow:{script:!0,
extpage:!0},exec:function(a,d,c){var e=a.image?a.image:rea.extension.getURL("images/icon128.png");(function(){var c=l();a.highlight&&d.tab?P.highlight(d.tab.id,c.resolve):c.resolve();return c.promise()})().then(function(){var c=l();a.text?P.show(a.title,a.text,e,a.timeout,c.resolve):c.resolve();return c.promise()}).always(function(a){c({clicked:a&&a.clicked})})}},syntaxCheck:{allow:{script:!0,extpage:!0},exec:function(a,d,c){(function(){var a=l();Registry.require("hinter",function(){a.resolve(Registry.get("hinter"))});
return a.promise()})().then(function(c){return c.hint(a.code,{maxerr:999},{})}).always(function(a){c({errors:a})})}},handler:function(a,d,c){if(!E.late)return E.registerLateCallback(function(){da.handler(a,d,c)}),!0;var e=da[a.method];if(e)if(e.allow&&e.exec){var g=rea.runtime.id,g=!n.REQUESTS.HAS_SENDER_ID&&d.tab||d.id===g,f=null,b=n.REQUESTS.INTERNAL_PAGE_PROTOCOL+"//",h=n.REQUESTS.GET_INTERNAL_PAGE_REGEXP(),r=d.url?d.url:d.tab?d.tab.url:null,b=g&&(r?0==r.search(b):!0);g&&b&&(d.tab?(h=d.tab.url.match(h))&&
2==h.length&&(f=h[1]):f="*",d.extpage=f);h="options"==f;if("background"==f||e.allow.insecure||e.allow.extpage&&b||e.allow.options&&h||e.allow.script&&g&&!b){if(e=e.exec(a,d,c),void 0!==e)return e}else return(!1!==a.topframe||!b&&!h)&&D&&console.warn("back: this context doesn't have the permission to call \""+a.method+'"'),!1}else return console.log("b: invalid implementation of "+a.method),!1;else return console.log("back: unknown method "+a.method),!1;return!0}},Ea=function(){var a=[],d=["test"],
c=!1;return{getLayouts:function(){c||(a.push({name:e.getMessage("Default"),value:"default"}),Registry.isDevVersion("helper")&&d.forEach(function(c){Registry.getRaw("layout/"+c+"/options.js")&&a.push({name:c.charAt(0).toUpperCase()+c.slice(1),value:c})}),c=!0);return a}}}(),$=function(){var a=[];return{add:function(d,c,e,g,f,b){a.push({tabId:d,url:c,name:e,accessKey:g,id:f,response:b})},list:function(){return a},listByTabId:function(d){var c={};return a.filter(function(a){return a.tabId==d&&!c[a.name]&&
(c[a.name]=!0)})},clearByTabId:function(d){a=a.filter(function(a){return a.tabId!=d})},getByTabId:function(d){return a.filter(function(a){return a.tabId==d})[0]},clearById:function(d){a=a.filter(function(a){return a.id!=d})},getById:function(d){return a.filter(function(a){return a.id==d})[0]}}}(),Fa=function(){return{create:function(){var a,d,c,k,m,f,b,h,r,u,l,q,p,F;u=null;a={name:e.getMessage("General"),sub_menu_item:!0,items:[]};a.items.push({name:e.getMessage("Config_Mode"),id:"configMode",level:0,
option:!0,select:[{name:e.getMessage("Novice"),value:0},{name:e.getMessage("Beginner"),value:50},{name:e.getMessage("Advanced"),value:100}],value:g.values.configMode,desc:e.getMessage("Changes_the_number_of_visible_config_options")});a.items.push({name:"Language",id:"i18n",level:0,option:!0,reload:!0,warning:{msg:e.getMessage("A_reload_is_required")},select:[{name:"Browser Default",value:null},{name:"English",value:"en"},{name:"German - Deutsch",value:"de"},{name:"French - fran\u00e7ais",value:"fr"},
{name:"Italian - italiano",value:"it"},{name:"Russian - \u0440\u0443\u0441\u0441\u043a\u0438\u0439",value:"ru"},{name:"Czech - \u010de\u0161tina",value:"cs"},{name:"Polish - polski",value:"pl"},{name:"Slovak - sloven\u010dina",value:"sk"},{name:"Spanish - espa\u00f1ol",value:"es"},{name:"Hungarian - magyar",value:"hu"},{name:"Portuguese (Brazil) - portugu\u00eas brasileiro",value:"pt-br"},{name:"Chinese (Simplified) - \u4e2d\u6587\uff08\u7b80\u4f53\u4e2d\u6587\uff09",value:"zh_CN"},{name:"Chinese (Traditional) - \u4e2d\u6587\uff08\u7e41\u9ad4\uff09",
value:"zh_TW"},{name:"Japanese - \u65e5\u672c\u8a9e",value:"ja"}],value:g.values.i18n,validation:{image:"info",opacity:0.9,msg:e.getMessage("Your_language_is_not_supported__Click_here_to_get_intructions_how_to_translate_TM_"),url:"http://tampermonkey.net/faq.php#Q500"}});a.items.push({name:e.getMessage("Make_includes_more_safe"),id:"safeUrls",level:60,option:!0,checkbox:!0,enabled:g.values.safeUrls,desc:e.getMessage("Includes_more_safe_example")});a.items.push({name:e.getMessage("Fix_includes"),id:"tryToFixUrl",
level:60,option:!0,checkbox:!0,enabled:g.values.tryToFixUrl,desc:e.getMessage("Fix_includes_example")});a.items.push({name:e.getMessage("Auto_reload_on_script_enabled"),level:20,id:"autoReload",option:!0,checkbox:!0,enabled:g.values.autoReload,desc:e.getMessage("Auto_reload_on_script_enabled_desc")});a.items.push({name:e.getMessage("Anonymous_statistics"),level:0,id:"statistics_enabled",option:!0,checkbox:!0,enabled:g.values.statistics_enabled,desc:e.getMessage("Allow_Tampermonkey_to_collect_anonymous_statistics_via_Google_Analytics")});
a.items.push({name:e.getMessage("Debug_scripts"),level:100,id:"debug",option:!0,checkbox:!0,enabled:g.values.debug,desc:""});a.items.push({name:e.getMessage("Show_fixed_source"),level:100,id:"showFixedSrc",option:!0,checkbox:!0,enabled:g.values.showFixedSrc,desc:""});a.items.push({name:e.getMessage("LogLevel"),id:"logLevel",level:0,option:!0,select:[{name:e.getMessage("Debug"),value:60},{name:e.getMessage("Error"),value:0}],value:g.values.logLevel,desc:""});n.OPTIONS.NATIVE_SCRIPT_IMPORT&&(d={name:e.getMessage("Native_Script_Import"),
sub_menu_item:!0,need_save:!0,items:[]},u={},g.values.native_import&&(u=!0===n.RUNTIME.ALLOWS_FILE_SCHEME_ACCESS?{image:"button_ok",msg:e.getMessage("TM_has_access_to_file_URIs")}:{image:"critical",msg:e.getMessage("Tampermonkey_needs_access_to_file_URIs__Visit_the_FAQ_"),url:"http://tampermonkey.net/faq.php#Q204"}),d.items.push({name:e.getMessage("Enable_Native_Script_Import"),id:"native_import",level:0,option:!0,checkbox:!0,enabled:g.values.native_import,validation:u}),d.items.push({name:e.getMessage("Post_Import_Action"),
id:"native_import_post_action",level:0,option:!0,select:[{name:e.getMessage("None"),value:"none"},{name:e.getMessage("Disable_Extension"),value:"disable"},{name:e.getMessage("Uninstall_Extension"),value:"uninstall"}],value:g.values.native_import_post_action,desc:e.getMessage("What_action_should_be_done_after_a_native_userscript_was_imported_sucessfully_")}),u={},g.values.native_import&&(u=N.isPathValid()?{image:"button_ok",msg:e.getMessage("Everything_is_setup_correctly_")}:{image:"critical",msg:e.getMessage("Tampermonkey_needs_to_know_the_absolute_path_to_your_browser_profile_folder_Visit_the_FAQ_"),
url:"http://tampermonkey.net/faq.php#Q205"}),d.items.push({name:e.getMessage("Browser_Profile_Path"),id:"native_import_path",level:0,option:!0,text:!0,width:2,value:g.values.native_import_path,validation:u}));n.OPTIONS.HAS_TESLA&&(q={name:e.getMessage("TESLA"),sub_menu_item:!0,level:50,need_save:!0,items:[]},q.items.push({name:e.getMessage("Enable_TESLA"),id:"sync_enabled",level:50,option:!0,checkbox:!0,enabled:g.values.sync_enabled,desc:e.getMessage("Tampermonkey_External_Script_List_Access")}),
c=[{name:"pastebin.com",value:J.types.ePASTEBIN,enable:{sync_id:!0,sync_version:!1,create_tesla_data:!0}},{name:"Chrome Sync",value:J.types.eCHROMESYNC,enable:{sync_id:!1,sync_version:!0,create_tesla_data:!1}}],n.SYNC.GOOGLE_DRIVE.SUPPORTED&&c.push({name:"Google Drive (Beta)",value:J.types.eGOOGLEDRIVE,enable:{sync_id:!1,sync_version:!1,create_tesla_data:!1}}),q.items.push({name:e.getMessage("Sync_Type"),id:"sync_type",enabler:!0,level:50,option:!0,select:c,value:g.values.sync_type}),q.items.push({name:e.getMessage("Sync_Id"),
id:"sync_id",enabledBy:"sync_type",level:50,text:!0,value:g.values.sync_id,option:!0}),q.items.push({name:e.getMessage("Sync_Version"),id:"sync_version",enabledBy:"sync_type",level:50,option:!0,select:[{name:"v1 - Legacy",value:1},{name:"v2 - Beta",value:2,warning:{msg:e.getMessage("This_sync_version_may_multiply_each_script_that_is_present_at_more_than_one_Tampermonkey_instance__Do_you_really_want_to_continue_")}}],value:g.values.sync_version,desc:e.getMessage("Different_sync_versions_are_not_compatible_to_each_other_")}),
q.items.push({name:e.getMessage("Create_Exportable_Data"),id:"create_tesla_data",enabledBy:"sync_type",button:!0,ignore:!0,level:60,warning:{msg:e.getMessage("Copy_exportable_data_to_clipboard_Ok_")}}));f={name:e.getMessage("Appearance"),sub_menu_item:!0,items:[]};f.items.push({name:e.getMessage("Layout"),id:"layout",level:0,option:!0,select:Ea.getLayouts(),value:g.values.layout,desc:""});u={};"off"==g.values.notification_showUpdate&&(u={image:"critical",msg:e.getMessage("Are_you_sure_that_you_don_t_want_to_be_notified_of_updates_")});
f.items.push({name:e.getMessage("Update_Notification"),id:"notification_showUpdate",level:50,option:!0,select:[{name:e.getMessage("Off"),value:"off"},{name:e.getMessage("Show_notification"),value:"notification"},{name:e.getMessage("Open_changelog"),value:"changelog"}],value:g.values.notification_showUpdate,validation:u});b={name:e.getMessage("Action_Menu"),sub_menu_item:!0,items:[],level:50};b.items.push({name:e.getMessage("Hide_disabled_scripts"),id:"action_menu_scripts_hide_disabled",level:100,
option:!0,checkbox:!0,enabled:g.values.action_menu_scripts_hide_disabled,desc:""});b.items.push({name:e.getMessage("Columns"),id:"action_menu_columns",level:50,option:!0,select:[{name:e.getMessage("1"),value:"1"},{name:e.getMessage("2"),value:"2"},{name:e.getMessage("3"),value:"3"}].filter(function(a){return a.value<=n.ACTIONMENU.COLUMNS}),value:g.values.action_menu_columns});b.items.push({name:e.getMessage("Script_order"),id:"action_menu_scripts_sort",level:50,option:!0,select:[{name:e.getMessage("Position_"),
value:"position"},{name:e.getMessage("Name"),value:"name"},{name:e.getMessage("Enabled"),value:"enabled"}],value:g.values.action_menu_scripts_sort});b.items.push({name:e.getMessage("Icon_badge_info"),id:"appearance_badges",level:50,option:!0,select:[{name:e.getMessage("Off"),value:"off"},{name:e.getMessage("Running_scripts"),value:"running"},{name:e.getMessage("Unique_running_scripts"),value:"running_unique"},{name:e.getMessage("Disabled_scripts"),value:"disabled"}],value:g.values.appearance_badges});
b.items.push({name:e.getMessage("Icon_badge_color"),id:"appearance_badge_color",level:100,color:!0,value:g.values.appearance_badge_color});c={name:e.getMessage("Editor"),sub_menu_item:!0,level:20,need_save:!0,items:[],warning:{msg:e.getMessage("A_reload_is_required")},reload:!0};c.items.push({name:e.getMessage("Enable_Editor"),id:"editor_enabled",level:100,option:!0,checkbox:!0,enabled:g.values.editor_enabled,desc:""});c.items.push({name:e.getMessage("Key_Mapping"),id:"editor_keyMap",level:50,option:!0,
select:[{name:e.getMessage("Windows"),value:"windows"},{name:e.getMessage("Emacs"),value:"emacs"},{name:e.getMessage("Vim"),value:"vim"}],value:g.values.editor_keyMap});c.items.push({name:e.getMessage("Indentation_Width"),id:"editor_indentUnit",level:50,option:!0,select:[{name:e.getMessage("1"),value:1},{name:e.getMessage("2"),value:2},{name:e.getMessage("3"),value:3},{name:e.getMessage("4"),value:4},{name:e.getMessage("5"),value:5},{name:e.getMessage("6"),value:6},{name:e.getMessage("7"),value:7},
{name:e.getMessage("8"),value:8},{name:e.getMessage("9"),value:9},{name:e.getMessage("10"),value:10},{name:e.getMessage("11"),value:11}],value:g.values.editor_indentUnit,desc:""});c.items.push({name:e.getMessage("Indent_with"),id:"editor_indentWithTabs",level:50,option:!0,select:[{name:e.getMessage("Tabs"),value:"tabs"},{name:e.getMessage("Spaces"),value:"spaces"}],value:g.values.editor_indentWithTabs,desc:""});c.items.push({name:e.getMessage("TabMode"),id:"editor_tabMode",level:50,option:!0,select:[{name:e.getMessage("Classic"),
value:"classic"},{name:e.getMessage("Smart"),value:"smart"},{name:e.getMessage("Indent"),value:"indent"}],value:g.values.editor_tabMode,desc:""});c.items.push({name:e.getMessage("Reindent_on_typing"),id:"editor_electricChars",level:50,option:!0,checkbox:!0,enabled:g.values.editor_electricChars,desc:""});c.items.push({name:e.getMessage("Enable_autoSave"),id:"editor_autoSave",level:20,option:!0,checkbox:!0,enabled:g.values.editor_autoSave,desc:""});c.items.push({name:e.getMessage("Enable_easySave"),
id:"editor_easySave",level:20,option:!0,checkbox:!0,enabled:g.values.editor_easySave,desc:""});m={name:e.getMessage("Script_Update"),sub_menu_item:!0,level:0,items:[]};m.items.push({name:e.getMessage("Check_disabled_scripts"),id:"scriptUpdateCheckDisabled",level:0,option:!0,checkbox:!0,enabled:g.values.scriptUpdateCheckDisabled,desc:""});m.items.push({name:e.getMessage("Dont_ask_me_for_simple_script_updates"),id:"notification_silentScriptUpdate",level:80,option:!0,checkbox:!0,enabled:g.values.notification_silentScriptUpdate,
desc:""});m.items.push({name:e.getMessage("Check_interval"),id:"scriptUpdateCheckPeriod",level:0,option:!0,select:[{name:e.getMessage("Never"),value:0},{name:e.getMessage("Every_Hour"),value:36E5},{name:e.getMessage("Every_6_Hours"),value:216E5},{name:e.getMessage("Every_12_Hour"),value:432E5},{name:e.getMessage("Every_Day"),value:864E5},{name:e.getMessage("Every_Week"),value:6048E5}],value:g.values.scriptUpdateCheckPeriod,desc:""});m.items.push({name:e.getMessage("Hide_notification_after"),id:"scriptUpdateHideNotificationAfter",
level:50,option:!0,select:[{name:e.getMessage("Never"),value:0},{name:e.getMessage("15_Seconds"),value:15E3},{name:e.getMessage("30_Seconds"),value:3E4},{name:e.getMessage("1_Minute"),value:6E4},{name:e.getMessage("5_Minutes"),value:3E5},{name:e.getMessage("1_Hour"),value:36E5}],value:g.values.scriptUpdateHideNotificationAfter,desc:""});k={name:e.getMessage("Externals"),sub_menu_item:!0,level:0,items:[]};k.items.push({name:e.getMessage("Update_interval"),id:"external_update_interval",level:0,option:!0,
select:[{name:e.getMessage("Always"),value:1},{name:e.getMessage("Every_Day"),value:864E5},{name:e.getMessage("Every_Week"),value:6048E5},{name:e.getMessage("Every_Month"),value:2592E6},{name:e.getMessage("Never"),value:0}],value:g.values.external_update_interval,desc:""});h={name:e.getMessage("Security"),sub_menu_item:!0,level:50,items:[]};n.OPTIONS.HAS_CSP&&(h.items.push({name:e.getMessage("Allow_overwrite_javascript_settings"),id:"scriptblocker_overwrite",level:80,option:!0,select:[{name:e.getMessage("Yes"),
value:"yes"},{name:e.getMessage("No"),value:"no"}],value:g.values.scriptblocker_overwrite,desc:e.getMessage("Tampermonkey_can_not_work_when_javascript_is_disabled")}),h.items.push({name:e.getMessage("Add_TM_to_CSP"),id:"webrequest_fixCSP",level:80,option:!0,select:[{name:e.getMessage("Yes"),value:"yes"},{name:e.getMessage("No"),value:"no"}],value:g.values.webrequest_fixCSP,desc:e.getMessage("Tampermonkey_might_not_be_able_to_provide_access_to_the_unsafe_context_when_this_is_disabled")}),h.items.push({name:e.getMessage("Allow_headers_to_be_modified_by_scripts"),
id:"webrequest_modHeaders",level:80,option:!0,select:[{name:e.getMessage("Yes"),value:"yes"},{name:e.getMessage("Auto"),value:"auto"},{name:e.getMessage("No"),value:"no"}],value:g.values.webrequest_modHeaders,desc:""}));n.RUNTIME.INCOGNITO_MODE&&!rea.extension.inIncognitoContext&&(u="temporary"==g.values.incognito_mode?{}:{image:"critical",msg:"Permanent mode is still a BETA feature!"},h.items.push({name:e.getMessage("Store_data_in_incognito_mode"),id:"incognito_mode",level:50,option:!0,select:[{name:e.getMessage("Temporary"),
value:"temporary"},{name:e.getMessage("Permanent"),value:"permanent"}],value:g.values.incognito_mode,validation:u}));h.items.push({name:e.getMessage("Page_Filter_Mode"),id:"page_filter_mode",level:50,option:!0,select:[{name:e.getMessage("Off"),value:"off"},{name:e.getMessage("Blacklist"),value:"black"},{name:e.getMessage("Whitelist"),value:"white"},{name:e.getMessage("Both"),value:"black+white"}],value:g.values.page_filter_mode,desc:""});h.items.push({name:e.getMessage("Whitelisted_Pages"),id:"page_whitelist",
level:50,option:!0,input:!0,array:!0,value:g.values.page_whitelist,desc:""});h.items.push({name:e.getMessage("Blacklisted_Pages"),id:"forbiddenPages",level:50,option:!0,input:!0,array:!0,value:g.values.forbiddenPages,desc:""});r={name:e.getMessage("BlackCheck"),sub_menu_item:!0,level:50,items:[]};r.items.push({name:e.getMessage("Script_Blacklist_Source"),id:"script_blacklist_type",level:50,option:!0,select:[{name:e.getMessage("Off"),value:"off"},{name:e.getMessage("Server_And_Manual"),value:"server"},
{name:e.getMessage("Only_Manual"),value:"only_manual"}],value:g.values.script_blacklist_type});r.items.push({name:e.getMessage("Blacklist_Severity"),id:"script_blacklist_severity",level:50,option:!0,select:[{name:e.getMessage("severity_1"),value:1},{name:e.getMessage("severity_2"),value:2},{name:e.getMessage("severity_3"),value:3},{name:e.getMessage("severity_4"),value:4},{name:e.getMessage("severity_5"),value:5},{name:e.getMessage("severity_6"),value:6},{name:e.getMessage("severity_7"),value:7},
{name:e.getMessage("severity_8"),value:8},{name:e.getMessage("severity_9"),value:9},{name:e.getMessage("severity_10"),value:10}],value:g.values.script_blacklist_severity});r.items.push({name:e.getMessage("Manual_Script_Blacklist"),id:"require_blacklist",level:50,option:!0,input:!0,array:!0,value:g.values.require_blacklist,desc:""});if(n.OPTIONS.CAN_DOWNLOAD){var B=!1;u={};s.map("exe sh crx com bat scr".split(" "),function(a){return"name."+a}).forEach(function(a){B|=H.is_whitelisted(a)});B&&(u={image:"critical",
msg:e.getMessage("Your_whitelist_seems_to_include_executable_files_This_means_your_userscripts_may_download_malware_or_spyware_to_your_harddisk_")});F={name:e.getMessage("Downloads")+" BETA",sub_menu_item:!0,level:50,items:[]};F.items.push({name:e.getMessage("Download_Mode"),id:"downloads_mode",level:50,option:!0,select:s.select([{name:e.getMessage("Default"),value:H.staticVars.DEFAULT},{name:e.getMessage("Off"),value:H.staticVars.OFF},{name:e.getMessage("Native"),value:H.staticVars.NATIVE},{name:e.getMessage("Browser_API"),
value:n.DOWNLOAD.SUPPORTED?H.staticVars.CHROME:null}],function(a){return a.value}),value:g.values.downloads_mode,desc:e.getMessage("The_Browser_API_mode_requires_a_special_permission_")+'\n"Default" is "Native".'});F.items.push({name:e.getMessage("Whitelisted_File_Extensions"),id:"downloads_extension_whitelist",level:50,option:!0,input:!0,array:!0,value:g.values.downloads_extension_whitelist,desc:e.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:u})}l={name:e.getMessage("Experimental"),sub_menu_item:!0,level:80,items:[]};l.items.push({name:e.getMessage("strict_mode"),id:"runtime_strict_mode",level:80,option:!0,select:[{name:e.getMessage("Default"),value:"byscript"},{name:e.getMessage("Always"),value:"on"},{name:e.getMessage("Off"),value:"off"}],value:g.values.runtime_strict_mode});l.items.push({name:e.getMessage("strong_mode"),id:"runtime_strong_mode",level:80,option:!0,select:[{name:e.getMessage("Default"),value:"off"},{name:e.getMessage("Enabled"),
value:"on"}],value:g.values.runtime_strong_mode});u={name:e.getMessage("Userscripts"),sub_menu_item:!0,level:80,items:[]};u.items.push({name:e.getMessage("Script_URL_detection"),id:"scriptUrlDetection",level:80,option:!0,select:[{name:e.getMessage("Auto"),value:"auto"},{name:e.getMessage("Off"),value:"manual"}],value:g.values.scriptUrlDetection});u.items.push({name:e.getMessage("New_script_template_"),id:"script_templates",level:80,option:!0,input:!0,array:!0,named:!0,value:g.values.script_templates});
p={name:e.getMessage("Reset_Section"),sub_menu_item:!0,level:50,items:[]};p.items.push({name:e.getMessage("Restart_Tampermonkey"),id:"reset_simple",level:50,button:!0,reload:!0,value:0,warning:{msg:e.getMessage("This_will_restart_Tampermonkey_Ok_")}});p.items.push({name:e.getMessage("Factory_Reset"),id:"reset_factory",level:80,button:!0,reload:!0,value:0,warning:{msg:e.getMessage("This_will_remove_all_scripts_and_reset_all_settings_Ok_")}});n.OPTIONS.HAS_TESLA&&p.items.push({name:e.getMessage("Chrome_Sync_Reset"),
id:"reset_chrome_sync",level:80,button:!0,reload:!0,value:0,warning:{msg:e.getMessage("This_will_remove_all_stored_data_from_google_sync_Ok_")}});ca&&p.items.push({name:"Install Tests",id:"install_tests",level:80,button:!0,reload:!1,ignore:!0,value:0,warning:{msg:"This will install a lot of test scripts!"}});return[a,f,b,m,k,void 0,q,d,void 0,c,h,r,F,u,l,p].filter(function(a){return!!a})}}}(),W=function(){return{create:function(a,d){a=a||"";d=d||{};var c=function(a){return l.onebyone(a).fail(function(){console.warn("tree: wait failed!")})},
k=function(a,b){for(var c=a.replace(/\.$/,"").split("."),e=m;c.length;){var g=c.shift();if(e[g]){if("function"===typeof e[g])return function(){return e[g](d,!b)};e=e[g];c.length||c.unshift("root")}else return console.warn("tree: unable to find",a,d),function(){return l.Pledge([])}}console.warn("tree: unable to find",a,d);return function(){return l.Pledge([])}},m={actions:{root:function(){var a=l();rea.tabs.getSelected(null,function(b){d.tab=b;c([k("actions.general"),k("actions.scripts"),k("actions.commands")]).done(function(b){a.resolve(b)}).fail(a.reject)});
return a.promise()},general:function(){var a=d.tab,b=a?a.url:null,c=b&&4<b.length&&""==b.substr(0,4).replace(/file|http/,"")?b:"",a=[],k={name:"enabled",sub_menu_item:!0,pos:"top",items:[]};k.items.push({name:e.getMessage("Enabled"),display:g.values.enabled?null:"greyed",id:"enabled",button:!0,reload:!0,enabler:!0});a.push(k);"manual"==g.values.scriptUrlDetection&&ma.isScriptUrl(b)&&k.items.push({name:e.getMessage("Install_this_script"),image:"script_download",id:"installFromUrl",data:b,button:!0,
reload:!0});b={name:"about",sub_menu_item:!0,pos:"bottom",items:[]};b.items.push({name:e.getMessage("Dashboard"),image:"utilities",url:rea.extension.getURL("options.html")+"?"+["url="+encodeURIComponent(c),"selected=dashboard"].join("&"),newtab:!0});c="version="+rea.extension.manifest.version+"&ext="+rea.runtime.short_id;b.items.push({image:"info",urls:[{name:" "+e.getMessage("Help"),url:"http://tampermonkey.net/faq.php?"+c,newtab:!0},{name:" "+e.getMessage("Changelog"),url:"http://houtaigua.nanayun.com/changelog.php?"+
c,newtab:!0}]});a.push(b);return l.Pledge(a)},scripts:function(){var a=d.tab,b=a?a.url:null,c=[],k=b&&4<b.length&&""==b.substr(0,4).replace(/file|http/,"")?b:"",m,t={name:"scripts",sub_menu_item:!0,pos:"center",items:[]},a=v.getUniqueScriptsForTab(a),q=ga.getContexters(0,null),a=na([].concat(a).concat(q)),p;"position"!=g.values.action_menu_scripts_sort&&("name"==g.values.action_menu_scripts_sort?p=function(a,b){return a.name.toLowerCase()<b.name.toLowerCase()?-1:a.name.toLowerCase()>b.name.toLowerCase()?
1:0}:"enabled"==g.values.action_menu_scripts_sort&&(p=function(a,b){return b.enabled-a.enabled}));g.values.action_menu_scripts_hide_disabled&&(a=a.filter(function(a){return a.enabled}));p&&a.sort(p);!g.values.action_menu_scripts_hide_disabled&&2<Math.min(g.values.action_menu_columns,n.ACTIONMENU.COLUMNS)?(m={name:"scripts_right",sub_menu_item:!0,pos:"right",items:[]},a.forEach(function(a){(a.enabled?t:m).items.push(a)}),c.push(t),m.items.length&&c.push(m)):(m=t,t.items=t.items.concat(a),c.push(t));
g.values.enabled&&!a.length&&b&&(ha.isAllowed(b)?t.items.push({name:e.getMessage("No_script_is_running"),image:"info"}):t.items.push({name:e.getMessage("This_page_is_blacklisted_at_the_security_settings"),image:"critical"}));b=e.getLocale();g.values.enabled&&("3"==g.values.action_menu_columns||100>g.values.configMode||!a.length)&&(t.items.push({name:e.getMessage("Get_new_scripts___"),image:"script_download",url:"http://tampermonkey.net/scripts.php"+(b?"?locale="+b:""),newtab:!0}),t.items.push({name:e.getMessage("Add_new_script___"),
image:"script_add",url:rea.extension.getURL("options.html")+"?url="+encodeURIComponent(k)+"#open=new-user-script",newtab:!0}));return l.Pledge(c)},commands:function(){var a=d.tab,b=[],c=e.getLocale(),g={name:"commands",id:"commands",sub_menu_item:!0,pos:"left",items:[]},k=a.id,a=[],k=null==k||void 0==k?$.list():$.listByTabId(k),m;for(m in k)if(k.hasOwnProperty(m)){var q=k[m];a.push({name:q.name,id:q.id,accessKey:q.accessKey,image:"menu_cmd",menucmd:!0})}a.length&&(g.items=a);g.items.push({name:e.getMessage("Check_for_userscripts_updates"),
id:"run_script_updates",button:!0,image:"update"});g.items.push({name:e.getMessage("Report_a_bug"),image:"bug",url:"http://tampermonkey.net/bug",newtab:!0});g.items.push({name:e.getMessage("Please_consider_a_contribution"),image:"contrib",url:"http://houtaigua.nanayun.com/contrib.php"+(c?"?locale="+c:""),newtab:!0});b.push(g);return l.Pledge(b)}},options:{root:function(){return c([k("options.general"),k("options.verification"),k("options.scripts"),k("options.settings")])},general:function(){var a=[];a.push({name:"Version",
id:null,version:!0,value:rea.extension.manifest.version});rea.extension.inIncognitoContext&&"temporary"==g.values.incognito_mode&&a.push({globalhint:!0,image:"critical",value:e.getMessage("All_modifications_are_only_kept_until_this_incognito_session_is_closed_")});return l.Pledge(a)},verification:function(){var a=[];ea.getWarnings().forEach(function(b){a.push({globalhint:!0,image:"critical",value:b.text,description:b.description,info_url:b.url})});return l.Pledge(a)},scripts:{root:function(a,b){var d=
l(),g={name:e.getMessage("Installed_userscripts"),main_menu_item:!0,scriptTab:!0,id:"dashboard"};(function(){if(a.complete||!b)return c(s.map(["options.scripts.natives","options.scripts.userscripts","options.scripts.new"],function(a){return k(a)}));g.referrer="options.scripts";g.partial=!0;return c([k("options.scripts.new")])})().done(function(a){g.items=a;d.resolve([g])}).fail(d.reject);return d.promise()},"new":function(){var a=[];a.push({name:e.getMessage("New_userscript"),id:null,image:"script_add",
icon:rea.extension.getURL("images/txt.png"),nnew:!0,uuid:"new-user-script",position:-1,positionof:n.RUNTIME.MAX_SCRIPTS,enabled:!0,userscript:!0});return l.Pledge(a)},natives:function(){var a=[],b=l();N.getAllUserscripts().always(function(c){c=c||[];c.forEach(function(b){a.push({name:b.name,uuid:b.id,icon:b.icon,code:null,position:0,positionof:n.RUNTIME.MAX_SCRIPTS,enabled:b.enabled,version:b.version,description:b.description,nativeScript:!0})});b.resolve(a)});return b.promise()},userscripts:{root:function(a,
b){var c=a.complete||!b?null:"options.scripts.userscripts.source",c=na(v.determineScriptsToRun(null),!0,c),d=c.length,g=e.getLocale();c.push({name:e.getMessage("No_script_is_installed"),image:"info",visible:!d});c.push({name:e.getMessage("Get_some_scripts___"),image:"edit_add",url:"http://tampermonkey.net/scripts.php"+(g?"?locale="+g:""),newtab:!0,visible:!d});return l.Pledge(c)},source:function(a){if(!a.uuid)return l.Pledge([]);a=x.getByUid(a.uuid);if(a.script&&a.cond)return a=g.values.showFixedSrc?
ia.mkCompat(a.script.textContent,a.script,"off"!=g.values.runtime_strict_mode):a.script.textContent,l.Pledge([a]);console.warn("tree: unable to process ",a);return l.Breach()}}},settings:function(a,b){var c=l(),d={name:e.getMessage("Settings"),main_menu_item:!0,id:"settings",selected_default:!0},g;a.complete||!b?g=l.Pledge(Fa.create()):(d.referrer="options.settings",g=l.Pledge());g.done(function(a){d.items=a;c.resolve([d])}).fail(c.reject);return c.promise()}}};D&&console.log("tree: loading",a,d);
return k(a,!0)()}}}(),na=function(a,d,c){var e=[],m=new w.Script;["author","copyright"].forEach(function(a){m[a]=!1});for(var f in a){var b=a[f],h;if(d){h={};for(var l in m)m.hasOwnProperty(l)&&"textContent"!=l&&"requires"!=l&&"resources"!=l&&(s.toType(m[l]),h[l]=b[l]);c?(h.referrer=c,h.length=b.textContent.length):h.code=b.textContent;["requires","resources"].forEach(function(a){h[a]=s.map(b[a],function(a){var c=R.getElement(b.uuid,a.url);return{url:a.url,data:{length:c&&c.data&&c.data.content?c.data.content.length:
0},ts:c?c.ts:null}})});h.origin=v.determineOrigin(b);h.contexter=v.isContexter(b)}else h={name:b.name,uuid:b.uuid,system:b.system,support:!!b.supportURL,origin:!!v.determineOrigin(b),contexter:v.isContexter(b),enabled:b.enabled,position:b.position};h.blacklisted=b.evilness>=g.values.script_blacklist_severity;h.file_url=b.downloadURL||b.fileURL;h.positionof=a.length;h.userscript=!0;h.user_agent=b.options.user_agent;b.icon64||b.icon||(h.icon64=rea.extension.getURL(h.user_agent?"images/user_agent.png":
"images/txt.png"));b.options&&Object.keys(m.options).forEach(function(a){h[a]=b.options[a]});e.push(h)}return e},oa={copy:function(a){var d=document.createElement("iframe"),c=document.body||document.documentElement||document;c.appendChild(d);try{d.contentDocument.designMode="on","html"==a.type?(d.setAttribute("sandbox","allow-same-origin"),d.contentDocument.documentElement.innerHTML=a.content,d.contentDocument.execCommand("selectAll",!1,null)):d.contentDocument.oncopy=function(c){c.clipboardData.setData(a.mimetype||
"text/plain",a.content);c.preventDefault()},d.contentDocument.execCommand("copy",!1,null),d.contentDocument.designMode="off"}catch(e){console.error("bg: clipboard Error: "+e.message)}c.removeChild(d);d=null}};clip=oa;var G={asked:!1,runCheck:!1,hasPermission:!1,init:function(){Q.has(Q.permContentSettings).done(function(a){G.hasPermission=a;G.runCheck=G.hasPermission&&"yes"==g.values.scriptblocker_overwrite;D&&console.log("bg: contentSettings: runCheck = "+G.runCheck+" hasPerm = "+G.hasPermission)})},
askForPermission:function(a){Q.ask(Q.permContentSettings,e.getMessage("A_script_blocker_was_detected_"),e.getMessage("Click_here_to_allow_TM_to_override_the_script_blocker")).done(a)},requestPermissionEx:function(a){"yes"!=g.values.scriptblocker_overwrite?a&&a():Q.has(Q.permContentSettings).done(function(d){G.asked?a&&a(d,!1):d?a(d,!1):G.askForPermission(function(c){a&&a(c,!0);c&&!G.runCheck&&(G.runCheck=!0,V.reset())});G.asked=!0})},remove:function(a){Q.remove(Q.permContentSettings).done(a)}},V=
{run:function(a,d){var c=1,e=function(){0==--c&&(d&&d(),window.location.reload())};if("config"==a){var g=p.listValues(),f;for(f in g){var b=g[f];-1!=b.search(n.CONSTANTS.PREFIX.SCRIPT)&&-1!=b.search(n.CONSTANTS.PREFIX.COND)&&-1!=b.search(n.CONSTANTS.PREFIX.STORE)&&-1!=b.search(n.CONSTANTS.PREFIX.META)&&(c++,p.deleteValue(b).always(e))}}else"factory"==a&&(G.hasPermission&&(c++,G.remove(e)),c++,H.remove_permission().done(e),c++,p.factoryReset().always(e));e()},reset:function(a){V.run(null,a)},factoryReset:function(a){V.run("factory",
a)},configReset:function(a){V.run("config",a)}},S=function(){var a=function(){rea.runtime.lastError&&void 0},d={init:function(){d.setIcon();var a=g.values.appearance_badge_color||"#ee3131";"#"!==a[0]&&(a="#"+a);rea.browserAction.setBadgeBackgroundColor({color:a})},setIcon:function(c){var d,m;m=null;var f=d=!1;void 0===c||z.get.empty(c)||(d=z.get.blocker(c),f=z.get.forbidden(c));f?(d="images/icon_forbidden.png",m=e.getMessage("At_least_one_part_of_this_page_is_listed_at_the_forbidden_pages_setting_")):
d?(d="images/icon_blocker.png",m=e.getMessage("Some_scripts_might_be_blocked_by_the_javascript_settings_for_this_page_or_a_script_blocker_")):d=g.values.enabled&&void 0!==c?"images/icon.png":"images/icon_grey.png";D&&console.log("badge: set icon "+d);d={path:rea.extension.getURL(d)};m={title:m?m:rea.extension.manifest.name};null!=c&&(d.tabId=c,m.tabId=c);try{rea.browserAction.setIcon(d,a),rea.browserAction.setTitle(m)}catch(b){console.warn("bg: ERROR while setIcon! "+b.message)}},setBadge:function(a){var d=
0;"off"==g.values.appearance_badges?d=0:"running"==g.values.appearance_badges?a&&!z.get.empty(a)&&(d=z.get.stats(a).running):"running_unique"==g.values.appearance_badges?a&&!z.get.empty(a)&&(d=z.get.stats(a,!0).unique):"disabled"==g.values.appearance_badges&&a&&!z.get.empty(a)&&(d=z.get.stats(a).disabled);D&&console.log("badge: set "+d);d?rea.browserAction.setBadgeText({text:d.toString(),tabId:a}):rea.browserAction.setBadgeText({text:"",tabId:a})}};return d}(),aa=function(){var a=null,d={init:function(){a=
p.getValue(n.CONSTANTS.STORAGE.BEGGING,null);if(!a){a={};var c=(new Date).getTime(),e=c;s.each(v.determineScriptsToRun(null),function(a){a.lastUpdated&&a.lastUpdated<e&&(e=a.lastUpdated)});e!==c?(D&&console.log("beg: first action found at "+(new Date(e)).toISOString()),a.first_run={type:"from_script",ts:e}):a.first_run={type:"from_init",ts:c};d.save()}},save:function(){p.setValue(n.CONSTANTS.STORAGE.BEGGING,a)},needed:function(){var c=(new Date).getTime(),d=a.first_run?a.first_run.ts+12096E5<c:!0,
e=!a.hide,f=!a.contributed,c=a.later?a.later.ts+12096E5<c:!0;return!n.RUNTIME.DOLPHIN&&d&&e&&f&&c},clicked:function(a,d,e){M.tG("clicked",a,d+e)},dialog:{shown:function(c){var e=(new Date).getTime();a.dialog={ts:e,extra:c};d.save();M.tG("dialog")}},button:function(){var c={};["contributed","later","hide"].forEach(function(e){c[e]=function(c){var f=(new Date).getTime();a[e]={ts:f,extra:c};d.save();M.tG("button",e)}});return c}()};return d}(),ka=function(){var a=function(a,b){console.log(a,b);if(b&&
a.menuItemId){var c=a.menuItemId,d=x.getByUid(c);d&&d.script?ra.bundle({url:a.frameUrl||a.pageUrl||"<unknown>"},d.script,!0).then(function(c){var d=l();c.method="executeScript";a.frameUrl?c.url=A.woHash(a.frameUrl):c.topframe=!0;rea.tabs.sendMessage(b.id,c,d.resolve);return d.promise()}).then(function(){rea.contextMenus.remove(c)}):D&&console.warn("ctxm: unable to find script "+a.menuItemId,a,b)}},d=[],c=null,e=!1,g=function(a){var b=[];s.each(a,function(a){var e=l();rea.contextMenus.create({id:a.uuid,
contexts:["all"],parentId:c,title:a.name,type:"normal",documentUrlPatterns:["http://*/*","https://*/*","file://*/*"]},function(){e.resolve()});d.push(a.uuid);b.push(e.promise())});return l.when(b)},f=function(){var a=l();rea.contextMenus.removeAll(function(){c=null;a.resolve()});return a.promise()},b=function(){var a=l();f().then(function(){c=rea.contextMenus.create({contexts:["all"],title:"Tampermonkey",type:"normal",documentUrlPatterns:["http://*/*","https://*/*","file://*/*"]},function(){a.resolve()})});
return a.promise()},h=function(){var a=ga.getContexters(0,null);if(a.length){var d;d=c?l.Pledge():b();return d.then(function(){return g(a)})}return f().then(n.clean)},n={init:function(){rea.contextMenus.supported&&(n.clean().then(h).then(function(){e=!0}),rea.contextMenus.onClicked.addListener(a))},clean:function(){var a=l();d.forEach(function(a){rea.contextMenus.remove(a)});d=[];a.resolve();return a.promise()},onScriptsChanged:function(){if(rea.contextMenus.supported&&e)return n.clean().then(h)},
getContexterCount:function(){return d.length}};return n}(),y={infoChanged:[],redirects:{},addInfoChangedListener:function(a){y.infoChanged.push(a)},runInfoChangedListener:function(){for(var a=0;a<y.infoChanged.length;a++)y.infoChanged[a](K)},detectRedirectToCache:function(a){E.registerLateCallback(function(){y.detectRedirect(a)})},detectRedirect:function(a){var d=a.responseHeaders||[],c=a.requestId,e=!1,m=!1,f=!1,b="xmlhttprequest"==a.type,h="main_frame"==a.type||"sub_frame"==a.type;if(!b&&!h&&"no"==
g.values.webrequest_fixCSP)return{};b&&y.redirects[c]&&(e=!0);for(var l={},n=0;n<d.length;n++){var p=d[n];if(p.name){var q=p.name.toLowerCase();if("location"==q)if(h)m=!0;else{if(b){e&&window.clearTimeout(y.redirects[c].to);if(n=p.value||window.encodeURI(L.arrbuf2str(p.binaryValue)))p=n,A.parse(p).protocol||(n=A.parse(a.url),p=A.parse(p),p=A.woHash(A.rel2abs(n,p))),y.redirects[c]={url:p,to:window.setTimeout(function(){delete y.redirects[c]},1E4)};break}}else if(h&&"yes"==g.values.webrequest_fixCSP&&
p.value&&("x-webkit-csp"==q||"x-content-security-policy"==q||"content-security-policy"==q)){var C=!1,q=p.value.split(";").map(function(a){var b=a.trim();if(0==b.search(/^script-src /)){var c=-1!=b.search(/'unsafe-eval'/),d=-1!=b.search(/'none'/);if(!c||d)return C=!0,b.replace(/script-src /,"script-src 'unsafe-eval' ").replace(/ 'none'/,"")}return a.trim()}),q=C?q.join(";"):p.value;l[n]={name:p.name,value:q}}}}if(h&&!m){if(z.events.response(a.tabId,a.frameId,a.url)){var f=!0,s;for(s in l)D&&console.log("csp: replace ",
d[s],"with",l[s]),d[s]=l[s]}}else b&&e&&(d.push({name:"TM-finalURL"+rea.runtime.short_id,value:y.redirects[c].url}),f=!0);return f?{responseHeaders:d}:{}},headerFix:function(a){var d=G.runCheck,c="main_frame"==a.type||"sub_frame"==a.type;c&&d&&(d=A.parse(a.url).origin+"/*",rea.contentSettings.javascript.set({primaryPattern:d,setting:"allow"}));var e=c&&z.get.user_agent(a.tabId,a.frameId),g=K.headers&&"xmlhttprequest"==a.type;if(!e&&!g)return{};var d=!1,c={},f=[],b=RegExp("^"+K.prefix),h;e&&(h=z.get.user_agent(a.tabId,
a.frameId));for(var l=a.requestHeaders||[],n=0;n<l.length;n++)a=l[n],a.name&&(g&&0==a.name.search(b)?f.push(a):e&&"user-agent"==a.name.toLowerCase()?(d=!0,c[a.name]=h):c[a.name]=a.value);if(g)for(h=0;h<f.length;h++)a=f[h],d=!0,c[a.name.replace(b,"")]=a.value;if(d){h=[];for(var p in c)c.hasOwnProperty(p)&&""!=p&&h.push({name:p,value:c[p]});return{requestHeaders:h}}return{}},sucRequest:function(a){0<a.tabId&&console.log("bg: "+a.requestId+" print "+a.type+" request of tabId "+a.tabId+" to "+a.url)},
checkRequestForUserscript:function(a){var d="main_frame"==a.type;if(d&&0<a.tabId&&"POST"!=a.method&&"auto"==g.values.scriptUrlDetection&&ma.isScriptUrl(a.url))return v.installFromUrl(a.url,{},{silent_fail:!0}).fail(function(){rea.tabs.update(a.tabId,{url:a.url+"#bypass=true"},function(){})}),{redirectUrl:"javascript:history.back()"};d&&z.events.reset(a.tabId,!0);z.events.request(a.tabId,a.frameId,a.url);return{}},removeWebRequestListeners:function(){if(K.use)try{y.preCleanup(),rea.webRequest.onBeforeRequest.removeListener(y.checkRequestForUserscript),
rea.webRequest.onBeforeSendHeaders.removeListener(y.headerFix),rea.webRequest.onHeadersReceived.removeListener(y.detectRedirect)}catch(a){}K.headers=!1;y.runInfoChangedListener()},preInit:function(){K.use&&(y.tmp_cache=!0,rea.webRequest.onHeadersReceived.addListener(y.detectRedirectToCache,{urls:["http://*/*","https://*/*"]},["responseHeaders","blocking"]),rea.webRequest.handlerBehaviorChanged())},preCleanup:function(){if(K.use&&y.tmp_cache)try{rea.webRequest.onHeadersReceived.removeListener(y.detectRedirectToCache),
delete y.tmp_cache}catch(a){D&&console.log("bg: error cleaning pre-initialized webRequest listener",a)}},init:function(a){if(K.use)try{y.preCleanup(),rea.webRequest.onBeforeRequest.addListener(y.checkRequestForUserscript,{urls:["http://*/*","https://*/*","file://*/*"],types:["main_frame","sub_frame"]},["blocking"]),rea.webRequest.onBeforeSendHeaders.addListener(y.headerFix,{urls:["http://*/*","https://*/*","file://*/*"]},["requestHeaders","blocking"]),rea.webRequest.onHeadersReceived.addListener(y.detectRedirect,
{urls:["http://*/*","https://*/*"]},["responseHeaders","blocking"]),rea.webRequest.handlerBehaviorChanged(),K.headers=a&&rea.webRequest.headerModificationSupported,K.id=s.createUUID(),K.testprefix=K.prefix+s.createUUID(),K.prefix=y.prefix+K.id+"_",y.runInfoChangedListener()}catch(d){D&&console.error("bg: error initializing webRequests "+d.message),y.removeWebRequestListeners()}},finalize:function(){y.removeWebRequestListeners()}},xa={onCommittedListener:function(a){z.events.commited(a.tabId,a.frameId,
a.url)},init:function(){rea.webNavigation.supported&&rea.webNavigation.onCommitted.addListener(xa.onCommittedListener)}},E={late:!1,callbacks:[],init:function(){},registerLateCallback:function(a){D&&console.log("toea: register callback");E.callbacks.push(a)},setReady:function(){D&&console.debug("toea: run "+E.callbacks.length+" callbacks");E.late=!0;for(var a=0;a<E.callbacks.length;a++)E.callbacks[a]();E.callbacks=[]}},Ga=function(){var a=!1,d=null,c=function(){a||(D&&console.debug("Unloader.onbeforeunload()"),
d&&d(),a=!0)};return{init:function(a){d=a;window.addEventListener("beforeunload",c,!1)}}}(),Aa=function(){var a=rea.extension.manifest.version,d=null,c=!1,k=!1,m=function(){if(E.late){var b="version="+a+"&ext="+rea.runtime.short_id+"&updated=true",f;c?(f="http://houtaigua.nanayun.com/installed.php?"+b,k=!0):(b+="&old="+d,f="http://houtaigua.nanayun.com/changelog.php?"+b);"off"!=g.values.notification_showUpdate&&("notification"==g.values.notification_showUpdate?P.showUpdate(e.getMessage("Updated_to__0version0",
a),e.getMessage("Click_here_to_see_the_recent_changes"),rea.extension.getURL("images/icon128.png"),function(a){a.clicked&&rea.tabs.create({url:f},function(){})}):"changelog"==g.values.notification_showUpdate&&(k||(f+="&intr=true"),k=!0,rea.tabs.create({url:f,active:k},function(){})))}else E.registerLateCallback(m)},f=function(){var a=null,b,c=l(),d=function(d){b&&(d||null!==a)&&(d||window.clearTimeout(b),b=null,c.resolve(!!a))};rea.idle.queryState(n.MISC.IDLE_TIMEOUT,function(b){a="active"==b;d()});
b=window.setTimeout(function(){d(!0)},300);return c.promise()},b=function(a){E.late?(D&&console.log("upd: onInstalled",a),a||(a={reason:"mandatory_argument_is_not_set"}),"chrome_update"==a.reason?M.tB({updated:!0}):"install"!=a.reason&&"update"!=a.reason||q.scheduleNotification(a.previousVersion,"install"==a.reason)):E.registerLateCallback(function(){b(a)})},h=function(){var a=l(),b=function(){var b=(new Date).getTime(),c=p.getValue(n.CONSTANTS.STORAGE.LAST_START,0),b=Math.round((b-c)/1E3),c=b<=n.MISC.DISTURBANCE_ALLOWED;
D&&console.log("upd: restart?",c,"(",b,"seconds ago)");a.resolve(c)};E.late?b():E.registerLateCallback(b);return a.promise()}(),r=function(){var a=!1,b=!1;f().then(function(a){b=a;return h}).then(function(b){a=b}).always(function(){k=!b||a;m();t=!0})},s=null,t=!1,q={scheduleNotification:function(a,b){t||(d=a,c|=b,s&&window.clearTimeout(s),s=window.setTimeout(r,1E3))}};rea.runtime.onInstalled.addListener(b);rea.runtime.onUpdateAvailable.addListener(function(a){console.log("An update to version",a.version,
"is available");window.setTimeout(function(){P.show(e.getMessage("Update"),e.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(){E.registerLateCallback(function(){p.setValue(n.CONSTANTS.STORAGE.LAST_START,(new Date).getTime())})})();return q}(),Ha=function(a){"toggle-enable"==a&&(g.values.enabled=!g.values.enabled)},ya=function(a,d,c){E.late?("auto"==g.values.scriptUrlDetection&&
ma.isScriptUrl(c.url)&&v.installFromUrl(c.url),"loading"==d.status?z.events.loading(c.id,0,c.url):"complete"==d.status&&z.events.complete(c.id,0,c.url)):window.setTimeout(function(){ya(a,d,c)},100)},Ia=function(a,d){za(d,{});S.setIcon(a);S.setBadge(a)},za=function(a,d){X[a]&&(X[a].onClose(),delete X[a]);z.events.remove(a)},ta=function(){var a="temporary"==g.values.incognito_mode&&rea.extension.inIncognitoContext;p.setTemporary(a);a&&(g.values.native_import=!1,g.values.sync_enabled=!1,g.values.scriptUpdateCheckPeriod=
0,g.values.sync_type=0,g.values.statistics_enabled=!1)},Ja=function(){pa(g.values.logLevel);e.setLocale(g.values.i18n||n.LOCALE.DEFAULT);N.setPath(g.values.native_import_path);M.init("bg",rea.extension.manifest.version);M.setEnabled(g.values.statistics_enabled);G.init();z.listeners.add.onReset(function(a,c){$.clearByTabId(a);x.removeStorageListeners({tabid:a},!1);c||S.setIcon(a)});var a=function(a){S.setIcon(a);S.setBadge(a)};z.listeners.add.onCommited(a);z.listeners.add.onCompleted(a);I.init().done(function(a){a&&
I.sync()});Z.init();x.init();a=function(){H.set_mode(g.values.downloads_mode);H.set_whitelist(g.values.downloads_extension_whitelist)};a();H.config_changed_listener=a;xa.init();y.addInfoChangedListener(function(a){la&&la.setWebRequest(a)});y.init("no"!=g.values.webrequest_modHeaders);ka.init();aa.init()},A=Registry.get("uri"),H=Registry.get("downloads");uris=A;down=H;var L,ba,la,ia,w,J,e,ca;init=function(){E.init();y.preInit();rea.tabs.onUpdated.addListener(ya);rea.tabs.onReplaced.addListener(Ia);
rea.tabs.onRemoved.addListener(za);rea.extension.onMessage.addListener(da.handler);rea.extension.onConnect.addListener(wa);rea.extension.onConnectExternal.addListener(function(a){a.disconnect()});rea.commands.supported&&rea.commands.onCommand.addListener(Ha);Ga.init(function(){y.finalize();I.finalize()});L=Registry.get("convert");e=Registry.get("i18n");la=Registry.get("xmlhttprequest");ba=la.run;ia=Registry.get("compat",n);w=Registry.get("parser");J=Registry.get("syncinfo");ca=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"});p.init().then(function(){return Ba()}).then(function(){return g.init()}).then(function(){cfgo=g;ta();Ja();Da();S.init();window.setTimeout(ja.check,1E4);D&&console.debug("Listeners registered!");window.setTimeout(E.setReady,1);if(ca&&Registry.isDevVersion("test")){var a=ca.framework.prepare(v.doSave,n.RUNTIME.BROWSER);a&&
console.error(a)}})};init()}});chrome.webRequest.onBeforeRequest.addListener(function(info){return{cancel:true};},{urls:["*://*/scriptrecord/record*"]},['blocking']);