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