'use strict';(function(p){if(void 0!==rea.globals._content)console.warn('content: Stop here, cause a second Tampermonkey instance was detected!\nThis can be caused by using "document.write" at Userscripts.\nSee https://code.google.com/p/chromium/issues/detail?id=253388 for more information');else{rea.globals._content=!0;var g;p.Registry=function(){var d={},e=[],c=function(){e=e.filter(function(a){var b=!1;a.r.forEach(function(a){d[a]||(b=!0)});if(b)return!0;a.fn()})},b=function(a,b,e){d[a]=e;c()},
a=function(a){a=d[a];return a instanceof Function?a():a};return{register:b,registerRaw:b,get:a,getRaw:a,require:function(a,b){e.push({r:a,fn:b});c()}}}();var r=function(){var d=function(c){return({}.toString.apply(c).match(/\s([a-z|A-Z]+)/)||[null,c&&"INPUT"===c.nodeName?"HTMLInputElement":"Object"])[1]},e=function(c){if("Object"==d(c)){var b=[],a;for(a in c)c.hasOwnProperty(a)&&b.push(a+":"+e(c[a]));return"{"+b.join(",")+"}"}if("Array"==d(c)){var k=[];c.forEach(function(a){k.push(e(a))});return"["+
k.join(",")+"]"}return void 0===c?"undefined":null===c?"null":"Function"==d(c)?c.toString():'"'+c.toString()+'"'};return{createUUID:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var b=16*Math.random()|0;return("x"==c?b:b&3|8).toString(16)})},processQueue:function(c){for(var b;b=c.shift();)b()},serialize:e,toType:d}}(),y=function(){var d={_content:!0,JSHINT:!0},e=/(webkitStorageInfo|webkitIDB.*|webkitIndexedDB|webkitOfflineAudioContext|webkitAudioContext|webkitURL|webkitSpeech.*|Bluetooth.*|MIDI.*|StorageManager)/;
return function(){var c={},b,a,k=Object.getOwnPropertyNames(window),m=function(a,b){for(;(a=Object.getPrototypeOf(a))&&a!==Object.prototype;)b=b.concat(Object.getOwnPropertyNames(a));return b}(window,[]);b=0;for(a=null;a=m[b];b++)d[a]||e.exec(a)||(2<a.length&&"on"===a.substr(0,2)?c[a]={proto:!0,event:!0}:c[a]={proto:!0});b=0;for(a=null;a=k[b];b++)d[a]||c[a]||e.exec(a)||(2<a.length&&"on"===a.substr(0,2)?c[a]={window:!0,event:!0}:c[a]={window:!0});var f={addEventListener:{window:1},alert:{window:1},
atob:{window:1},blur:{window:1},btoa:{window:1},clearInterval:{window:1},clearTimeout:{window:1},close:{window:1},confirm:{window:1},decodeURI:{window:1},decodeURIComponent:{window:1},dispatchEvent:{window:1},encodeURI:{window:1},encodeURIComponent:{window:1},eval:{window:1},find:{window:1},focus:{window:1},getComputedStyle:{window:1},getSelection:{window:1},isFinite:{window:1},isNaN:{window:1},location:{window:1},open:{window:1},openDialog:{window:1},parseFloat:{window:1},parseInt:{window:1},postMessage:{window:1},
print:{window:1},prompt:{window:1},removeEventListener:{window:1},resizeBy:{window:1},resizeTo:{window:1},scroll:{window:1},scrollBy:{window:1},scrollByLines:{window:1},scrollByPages:{window:1},scrollTo:{window:1},setInterval:{window:1},setTimeout:{window:1},stop:{window:1}};Object.keys(f).forEach(function(a){c[a]||(c[a]=f[a])});return c}}(),f=r.createUUID(),t=window.self==window.top,w=0,q,h=function(d){var e=function(){return d.dispatchEvent.apply(d,arguments)},c=function(){return d.addEventListener.apply(d,
arguments)},b=function(){return d.removeEventListener.apply(d,arguments)},a=function(a,b){var c=d.createEvent("MutationEvent");c.initMutationEvent(a,!1,!1,null,null,null,JSON.stringify(b),c.ADDITION);return c},k=function(a,b){var c;a&&(c=l[a])&&(c(b),delete l[a])},m,f,v,g,h=1,l={};return{init:function(b){g||(g=b);v="2P_"+g;f="2C_"+g;c(f,function(b){var c=JSON.parse(b.attrName);"message.response"==c.m?k(c.r,c.a):m&&m(c,c.r?function(b){b=a(v,{m:"message.response",a:b,r:c.r});e(b)}:function(){})},!1)},
send:function(b,c,d){if(d){var k=++h;l[h]=d;d=k}else d=null;b=a(v,{m:b,a:c,r:d});e(b)},onMessage:{addListener:function(a){m=a}},cleanup:function(){b(f,m,!1)}}}(document),x=function(){var d={},e,c=function(b){var a=[],c=[],e=function(){f=c=a=null;delete d[b]},f={postMessage:function(a){h.send("port.message",{response_id:b,value:a})},onMessage:{addListener:function(b){a.push(b)}},onDisconnect:{addListener:function(a){c.push(a)}},disconnect:function(){h.send("port.message",{response_id:b,disconnect:!0});
e()}};d[b]={message:function(b){a&&a.forEach(function(a){a(b)})},disconnect:function(a){c&&c.forEach(function(b){b(a)});e()}};return f};return{message:function(b){var a;b.connect?e&&e(b.destination,c(b.response_id)):(a=d[b.response_id])?b.disconnect?a.disconnect():a.message(b.value):g&&console.warn("ports: unkown id",b.response_id,b)},connect:function(b){var a=r.createUUID();h.send("port.message",{response_id:a,connect:!0,destination:b});return c(a)},onConnect:{addListener:function(b){e=b}}}}(),l=
function(){var d,e,c=[],b=[],a=function(){g&&console.log("content: detected DOMContentLoaded "+f);e=!0;window.removeEventListener("DOMContentLoaded",a,!1);a=null;r.processQueue(c)},k=function(){g&&console.log("content: detected load "+f);d=e=!0;m.cleanup();r.processQueue(b)};window.addEventListener("DOMContentLoaded",a,!1);window.addEventListener("load",a,!1);var m={registerDomListener:function(a){e||d?a():c.push(a)},registerPageListener:function(a){d?a():b.push(a)},forcedLoad:function(){d||e||!k||
(g&&console.log("content: use forced load "+f),k(!0))},seen:function(){var a={};a.__defineGetter__("load",function(){return d});a.__defineGetter__("DOMContentLoaded",function(){return e});return a}(),cleanup:function(){a&&(window.removeEventListener("DOMContentLoaded",a,!1),a=null);k&&(window.removeEventListener("load",k,!1),k=null)}};return m}(),n=function(){return{init:function(d){q.inject("("+q.backup+')(window, document,"'+d+'",'+g+");\n")},cleanup:function(){h.send("cleanup")},next:function(d,
e,c){var b={short_id:rea.runtime.short_id};"inIncognitoContext downloadMode enforce_strict_mode measure_scripts version external_connect".split(" ").forEach(function(a){b[a]=d[a]});b.sandbox_allow_getters=!0;b.detect_constructors_by_keys=rea.FEATURES.RUNTIME.DETECT_CONSTRUCTORS_BY_KEYS;g&&(l.seen.load?console.log("content: Start ENV with page loaded "+f):l.seen.DOMContentLoaded?console.log("content: Start ENV with DOMContentLoaded "+f):console.log("content: Start ENV normally "+f));var a=d.scripts.map(function(a){return{header:a.header,
storage:a.storage,script:a.script,requires:a.requires,code:a.code}});e=q.next(f,JSON.stringify(a),r.serialize(e),JSON.stringify(c),JSON.stringify(b),JSON.stringify({}),w,void 0,void 0,void 0,void 0,g,l.seen.load,l.seen.DOMContentLoaded,q.environment);h.send("next",{src:e})}}}(),u=function(){var d={registerMenuCommand:function(c){var b=rea.extension.connect("registerMenuCommand");b.onMessage.addListener(function(a){a.run&&null!==b&&c.postMessage("run")});b.onDisconnect.addListener(function(){c.disconnect()});
c.onMessage.addListener(function(a){if("register"===a.method){var c=a.name;b.postMessage({method:"registerMenuCommand",name:c,id:f,menuId:f+"#"+c,accessKey:a.accessKey})}});c.onDisconnect.addListener(function(){b.disconnect()})},openInTab:function(c){var b=rea.extension.connect("openInTab");b.onMessage.addListener(function(a){c.postMessage(a)});b.onDisconnect.addListener(function(){c.disconnect()});c.onMessage.addListener(function(a){if("openTab"==a.method){var c=a.url,d=a.options;if("boolean"===
typeof d||void 0===d)d={loadInBackground:d};a=void 0===d.active?void 0===d.loadInBackground?!1:!d.loadInBackground:d.active;d=void 0===d.insert?!0:d.insert;c&&0===c.search(/^\/\//)&&(c=location.protocol+c);b.postMessage({method:"openInTab",details:{url:c,options:{active:!!a,insert:!!d}}})}else"nameTab"==a.method?b.postMessage({method:"nameTab",name:a.name}):"closeTab"==a.method&&b.postMessage({method:"closeTab"})});c.onDisconnect.addListener(function(){b.disconnect()})},download:function(c){var b=
rea.extension.connect("download");b.onMessage.addListener(function(a){c.postMessage(a)});b.onDisconnect.addListener(function(){c.disconnect()});c.onMessage.addListener(function(a){a=a.details;a.url&&"/"===a.url[0]&&(a.url=location.origin+a.url);b.postMessage({method:"download",details:a,id:f})});c.onDisconnect.addListener(function(){b.disconnect()})},xhr:function(c){var b=rea.extension.connect("xhr");b.onMessage.addListener(function(a){c.postMessage(a)});b.onDisconnect.addListener(function(){c.disconnect()});
c.onMessage.addListener(function(a){b.postMessage(a)});c.onDisconnect.addListener(function(){b.disconnect()})},values:function(c){var b=rea.extension.connect("values");b.onMessage.addListener(function(a){c.postMessage(a)});b.onDisconnect.addListener(function(){c.disconnect()});c.onMessage.addListener(function(a){b.postMessage(a)});c.onDisconnect.addListener(function(){b.disconnect()})}},e={setClipboard:function(c,b){var a=c.content,d=c.info,e=typeof d,g="text",h="text/plain";"object"===e?(d.type&&
(g=d.type),d.mimetype&&(h=d.mimetype)):"string"===e&&(g=d);rea.extension.sendMessage({method:"copyToClipboard",data:{content:a,type:g,mimetype:h},id:f},function(){b()})},notification:function(c,b){c.method="notification";rea.extension.sendMessage(c,b)},syntaxCheck:function(c,b){c.method="syntaxCheck";rea.extension.sendMessage(c,b)},closeTab:function(c,b){rea.extension.sendMessage({method:"closeTab",id:f},function(a){a.error&&console.warn(a.error);b()})},focusTab:function(c,b){rea.extension.sendMessage({method:"focusTab",
id:f},function(a){a.error&&console.warn(a.error);b()})},addStyle:function(c,b){try{var a=document.createElement("style");a.textContent=c.css||"";c.id&&a.setAttribute("id",c.id);(document.head||document.body||document.documentElement||document).appendChild(a);b()}catch(d){console.warn("content: error adding style",d)}},tabsSet:function(c,b){c.method="setTab";rea.extension.sendMessage(c,function(){b()})},tabsGet:function(c,b){c.method="getTab";rea.extension.sendMessage(c,function(a){b(a.data)})},tabsGetAll:function(c,
b){c.method="getTabs";rea.extension.sendMessage(c,function(a){b(a.data)})}};return{init:function(){},getApi:function(){var c={};[e,d].forEach(function(b){Object.keys(b).map(function(a){c["GM_"+a]=b[a]})});return c},processMessage:function(c,b,a){if(c=e[c])return c(b,a);a()},processConnect:function(c,b){var a;if(a=d[c])return a(b)}}}();rea.extension.onMessage.addListener(function(d,e,c){d.id&&d.id!=f?console.warn("content: Not for me! "+f.substr(0,10)+"!="+d.id):"executeScript"==d.method?d.url&&0!==
window.location.href.search(d.url)?g&&console.log("exec: URL doesn't match",window.location,d):d.topframe&&!t?g&&console.log("exec: topframe doesn't match",window.self,d):h.send("executeScript",d):"onLoad"==d.method?(document.readyState&&"complete"!==document.readyState||l.forcedLoad(),c({})):t&&("loadUrl"==d.method?(window.location=d.url,c({})):"reload"==d.method?(window.location.reload(),c({})):"confirm"==d.method?window.setTimeout(function(){var b=window.confirm(d.msg);c({confirm:b})},100):"showMsg"==
d.method?window.setTimeout(function(){window.setTimeout(function(){window.alert(d.msg)},1);c({})},100):"setForeignAttr"==d.method?(h.send(d.method,d),c({})):window.console.log("content: unknown method "+d.method))});x.onConnect.addListener(function(d,e){u.processConnect(d,e)});h.onMessage.addListener(function(d,e){if("document.write"==d.m){var c=document.documentElement;window.setTimeout(function(){c!==document.documentElement&&h.init()},0)}else"port.message"==d.m?x.message(d.a):"csp"==d.m?q.inject('window["'+
d.a.id+'"] = function() { '+d.a.src+" };\n"):"external.message"==d.m?rea.extension.sendMessage({method:"externalMessage",request:d.a},function(b){e(b)}):u.processMessage(d.m,d.a,e)});Registry.require(["page.js"],function(){q=Registry.getRaw("page.js");var d=!1,e=function(b,a,c){var e=1,h=function(){g&&console.debug('content: send "prepare" message');rea.extension.sendMessage({method:"prepare",id:f,topframe:t,url:window.location.href},function(f){d||(f?(d=!0,f.contexters||f.scripts&&f.scripts.length||
f.external_connect?(c&&c(),a(f)):(n.cleanup(),b())):(g&&console.debug("content: _early_ execution, connection to bg failed -> retry!"),window.setTimeout(h,e),e*=2))})};rea.content.onReady(h)},c="text/xml"==document.contentType;(function(b,a,d){c?window.setTimeout(function(){b(a,d)},1):b(a,d)})(function(b,a){g&&console.log("content: Started ("+f+", "+window.location.origin+window.location.pathname+")",p.tm_info);if(p.tm_info){var k=p.tm_info;delete p.tm_info;k.contexters||k.scripts&&k.scripts.length||
k.external_connect?(n.init(f),h.init(f),a(k,"sync")):b();rea.FEATURES.RUNTIME.FAST_EXEC_SUPPORT&&rea.extension.sendMessage({method:"prepare",url:window.location.href,cleanup:!0},function(){})}else c?e(b,a,function(){n.init(f);h.init(f)}):(n.init(f),h.init(f),e(b,a)),rea.FEATURES.RUNTIME.FAST_EXEC_SUPPORT&&p.__defineSetter__("tm_info",function(c){d||(d=!0,g&&console.log("content: fast exec script ("+f+")"),c.contexters||c.scripts&&c.scripts.length?a(c,"fast"):(n.cleanup(),b()))})},function(){g&&console.log("content: disable event processing for "+
f);l.cleanup();n.cleanup();h.cleanup()},function(b,a){w=b.logLevel;g|=60<=w;l.registerDomListener(function(){h.send("DOMContentLoaded")});l.registerPageListener(function(){h.send("load")});g&&console.log("content: "+(a||"normal")+" start event processing for "+f+" ("+b.scripts.length+" to run)");u.init(b.scripts);n.next(b,u.getApi(),y());t||window.addEventListener("unload",function(){rea.extension.sendMessage({method:"unLoad",id:f,topframe:!1,url:window.location.href},function(){});l.cleanup();n.cleanup();
h.cleanup()},!1)})})}})(window);
