window.requestFileSystem||(window.requestFileSystem=window.webkitRequestFileSystem);window.BlobBuilder||(window.BlobBuilder=window.WebKitBlobBuilder);
Registry.require("promise layout xmlhttprequest convert crcrc curtain layout/default/tabview layout/default/htmlutil helper i18n parser statistics layout/default/layout_helper".split(" "),function(){var J=rea.FEATURES,K=Registry.get("promise"),n=Registry.get("crcrc").cr,c=Registry.get("crcrc").crc,l=Registry.get("i18n"),x=Registry.get("curtain"),v=Registry.get("helper"),L=Registry.get("layout/default/tabview"),t=Registry.get("layout/default/htmlutil"),M=Registry.get("statistics"),B=Registry.get("layout"),
C=Registry.get("layout/default/layout_helper"),D=C.images;B.render(function(){C.addStyle();C.addFont();var m=null,F="???",y=null,G="0.0.0",z=function(){var a=document.getElementById("ask"),d=c("div","main_container p100100","ask","main");if(a){var b=a.parentNode;b.removeChild(a);b.appendChild(d);document.body.setAttribute("class","main")}var a=c("div","head_container","ask","head_container"),b=c("div","tv_container","ask","tv_container"),g=n("a","head_link","ask","head_link");g.href="http://tampermonkey.net";
g.target="_blank";var e=c("div","float margin4","ask","head1"),f=c("img","banner","ask");f.src=rea.extension.getURL("images/icon128.png");var l=c("div","float head margin4","ask","head2"),p=n("div","heading"),w=c("div","version","version","version");w.textContent=" by Jan Biniok";var k=n("div","search","box","");p.textContent="Tampermonkey";e.appendChild(f);l.appendChild(p);l.appendChild(w);g.appendChild(e);g.appendChild(l);a.appendChild(g);a.appendChild(k);d.appendChild(a);d.appendChild(b);d=L.create("_main",
b);a=n("div","main","main","tab_content_h");a.textContent=F;b=n("div","main","main","tab_content");d.appendTab(v.createUniqueId("main","main"),a,b).select();x.hide();return b},B=function(a){var d=a.script,b=c("div","viewer_bottom","bottom","");a=c("div","editor_400p_outer","editor",d.name);var g=c("div","editor_400p editor_border","editor",d.name);b.appendChild(a);a.appendChild(g);m.nocm?(a=c("textarea","editorta","editor",d.name),a.setAttribute("wrap","off"),g.appendChild(a),a.value=d.textContent):
window.setTimeout(function(){b.editor=new MirrorFrame(g,{value:d.textContent,noButtons:!0,matchBrackets:!0})},1);return b},N=function(){var a={};window.addEventListener("keydown",function(c){var b=!1;if("keydown"==c.type&&(a[c.keyCode]&&(b=a[c.keyCode](c)),b))return c.stopPropagation(),c.preventDefault(),!1},!0);return{registerListener:function(c,b){a[c]=b}}}(),A=function(a,d,b){v.select(b,function(a){return a.label}).forEach(function(b){var e=c("input",d,"tm",b.label);e.type="button";e.value=b.label;
e.addEventListener("click",b.fn);a.appendChild(e);b.focus&&window.setTimeout(function(){$(e).focus()},300);b.keyDown&&N.registerListener(b.keyDown.keyCode?b.keyDown.keyCode:b.keyDown,b.keyDown.cb?b.keyDown.cb:b.fn)})},Q=function(a){var d=a.script,b=c("div","viewer_last","install"),g=c("div","viewer_content","install_content"),e=c("div","ask_action_buttons","install_buttons"),f=[];f.push({label:a.messages.action,fn:O,focus:!0});J.RUNTIME.CHROME&&f.push({label:a.messages.flags.install?l.getMessage("Process_with_Chrome"):
null,fn:function(){P(d.fileURL);$(b).hide()}});f.push({label:l.getMessage("Cancel"),fn:u,keyDown:27});A(e,"install",f);g.appendChild(e);b.appendChild(g);return b},R=function(a){var d=c("div","viewer_last","import"),b=c("div","viewer_content","import_content"),g=c("div","ask_action_buttons","import_buttons");A(g,"import",[{label:l.getMessage("Import"),fn:function(){var b=Object.keys(a.scripts);q(m.aid,"import",{data:{import_ids:b,global_settings:a.global_settings}})},focus:!0},{label:l.getMessage("Cancel"),
fn:u,keyDown:27}]);b.appendChild(g);d.appendChild(b);return d},S=function(a){a=c("div","viewer_last","ok");var d=c("div","viewer_content","ok_content"),b=c("div","ask_action_buttons","ok_buttons");A(b,"import",[{label:l.getMessage("Ok"),fn:u,focus:!0}]);d.appendChild(b);a.appendChild(d);return a},T=function(a,d){var b=c("div","viewer_last","ok"),g=c("div","viewer_content","ok_content"),e=c("div","ask_action_buttons","ok_buttons");A(e,"permission",[{label:l.getMessage("Ok"),fn:function(){rea.permissions.request({permissions:[d.permission]},
function(a){rea.runtime.lastError&&console.warn("notify: error on getting permission",d.permission+"!","reason:",rea.runtime.lastError.message);q(m.aid,"permission",{data:{granted:a,permission:d.permission}})})},focus:!0},{label:l.getMessage("Cancel"),fn:u,keyDown:27}]);g.appendChild(e);b.appendChild(g);var g=c("div","viewer_upper","permission"),e=c("div","viewer_info","general","permission"),f=c("div","viewer_content","general_content","permission"),r=n("h3","install","heading","permission"),p=c("span",
"message","heading","permission");r.textContent=d.title;p.textContent=d.message;f.appendChild(p);e.appendChild(r);e.appendChild(f);g.appendChild(e);a.appendChild(g);a.appendChild(b)},E=function(a,d){var b=a.preparat,g=a.content,e=b.script||{},f=e.uuid||e.id||e.name;b.short_info||(b.short_info=[]);var r=c("div","viewer_upper",f),p=c("div","viewer_info","general",f),w=c("div","viewer_content","general_content",f),k=n("h3","install","heading",f);if(e.icon||e.icon64){var h=n("img","version","heading",
f);h.src=e.icon||e.icon64;k.appendChild(h)}h=n("span","name","heading",f);h.textContent=b.heading||e.name||"";k.appendChild(h);e.version&&(h=c("span","view_version","heading",f),h.textContent="v"==e.version[0]?"":"v",h.textContent+=e.version,k.appendChild(h));p.appendChild(k);d&&b.short_info.unshift({prop:"heading",value:b.messages.heading,label:l.getMessage("Action")});var m=c("table","script_desc",f);b.short_info.forEach(function(a){var b=e[a.prop]||a.value;if(b||!d){var g=c("tr","script_desc",
a.prop,f),k=c("td","script_desc",a.prop,f+"dt"),h=c("td","script_desc",a.prop,f+"dd");k.textContent=a.label?a.label:"";h.textContent=b||l.getMessage("_not_set_");g.appendChild(k);g.appendChild(h);m.appendChild(g)}});w.appendChild(m);var k=c("div","viewer_info","info",f),s;d?s=w:(s=c("div","viewer_content","info_content",f),h=n("h4","action","heading",f),h.textContent=b.messages.heading,s.appendChild(h));["errors","warnings","info"].forEach(function(a){var c=n("table",a,f);(b.messages[a]||[]).forEach(function(b){var e=
n("tr",a,f),d=n("td",a,f+"dt"),g=n("td",a,f+"dd");"info"==a?(d.textContent=b.label,g.textContent=b.value):"warnings"==a?(d.innerHTML='<img src="'+D.get("critical")+'"></img>&nbsp;',g.innerHTML=t.safeTagsReplace(b).replace(/\n/,"<br />")):"errors"==a&&(d.innerHTML='<img src="'+D.get("error")+'"></img>&nbsp;',g.innerHTML=t.safeTagsReplace(b).replace(/\n/,"<br />"));e.appendChild(d);e.appendChild(g);c.appendChild(e)});s.appendChild(c)});h=function(a,b,d,g){var k=n("table",a,f),h=0,r={};b.forEach(function(b){if(!(h>
g||r[b])){r[b]=!0;var e=c("tr",a+"desc",b,f+h),l=c("td",a+"desc",b,f+h+"dt"),n=c("td",a+"desc",b,f+h+"dd");l.innerHTML=0==h?t.safeTagsReplace(d.label):"&nbsp;";n.innerHTML=h==g?'<span title="'+t.safeTagsReplace(d.warning)+'">...!</span>':t.safeTagsReplace(b);e.appendChild(l);e.appendChild(n);k.appendChild(e);h++}});if(e.options&&(b=e.options.override&&e.options.override["use_"+a])&&b.length){b=c("tr",a+"desc","ovverride",f+h);var p=c("td",a+"desc","ovverride",f+h+"dt"),m=c("td",a+"desc","ovverride",
f+h+"dd");p.innerHTML=0==h?t.safeTagsReplace(d.label):"&nbsp;";m.innerHTML=t.safeTagsReplace(" ("+l.getMessage("overwritten_by_user")+")");b.appendChild(p);b.appendChild(m);k.appendChild(b)}s.appendChild(k)};h("includes",(e.includes||[]).concat(e.matches||[]),{label:l.getMessage("Include_s__"),warning:l.getMessage("Attention_Can_not_display_all_includes_")},5);h("excludes",e.excludes||[],{label:l.getMessage("Exclude_s__"),warning:l.getMessage("Attention_Can_not_display_all_excludes_")},3);p.appendChild(w);
k.appendChild(s);r.appendChild(p);r.appendChild(k);g.appendChild(r);a.install&&g.appendChild(a.install(b));a.editor&&g.appendChild(a.editor(b))},P=function(a){q(m.aid,"abort");window.setTimeout(function(){window.location=a+"#bypass=true"},10)},u=function(a,c){q(m.aid,"abort");window.setTimeout(function(){window.close()},100)},H=function(a,c){q(m.aid,"unload");y&&(window.clearInterval(y),y=null);window.removeEventListener("unload",H)};window.addEventListener("unload",H);var I=function(){window.location.search||
window.location.hash?(m=v.getUrlArgs(),m.aid?(q(m.aid,"preparat").done(function(a){a.ext&&a.ext.version&&(G=a.ext.version);a.i18n&&l.setLocale(a.i18n);a.options&&a.options.statistics_enabled&&M.init("ask",G);F=l.getMessage("Install");var d=null;a.preparat&&("install"==a.type?d=function(){E({content:z(),preparat:a.preparat,install:Q,editor:B})}:"install_error"==a.type?d=function(){E({content:z(),preparat:a.preparat,install:S},!0)}:"import"==a.type?d=function(){var b=z(),d=a.preparat;b.appendChild(R(d));
if(d.global_settings){var e=c("div","viewer_upper",s),f=c("div","viewer_upper","global_settings"),r=c("div","viewer_info","general","global_settings"),p=c("div","viewer_content","general_content","global_settings"),m=n("h3","install","heading","global_settings"),k=n("img","version","heading","global_settings");k.src=rea.extension.getURL("images/icon48.png");m.appendChild(k);k=n("span","name","heading","global_settings");k.textContent=l.getMessage("Global_Settings");m.appendChild(k);r.appendChild(m);
var m=c("table","script_desc","global_settings"),k=c("tr","settings_desc","action","global_settings"),h=c("td","settings_desc","action","global_settingsdt"),q=c("td","settings_desc","action","global_settingsdd");h.textContent=l.getMessage("Action");q.textContent=l.getMessage("Global_settings_import");k.appendChild(h);k.appendChild(q);m.appendChild(k);k=c("tr","settings_desc","warning","global_settings");h=c("td","settings_desc","warning","global_settingsdt");q=c("td","settings_desc","warning","global_settingsdd");
h.innerHTML='<img src="'+D.get("critical")+'"></img>&nbsp;';q.textContent=l.getMessage("This_will_overwrite_your_global_settings_");k.appendChild(h);k.appendChild(q);m.appendChild(k);p.appendChild(m);r.appendChild(p);f.appendChild(r);e.appendChild(f);b.appendChild(e)}if(d.scripts)for(var s in d.scripts)e=d.scripts[s],f=c("div","viewer_upper",s),E({content:f,preparat:e},!0),b.appendChild(f)}:"permission"==a.type&&(d=function(){T(z(),a.preparat)}),y=window.setInterval(U,6E4),d&&window.setTimeout(d,
1))}).fail(function(){u()}),x.wait(l.getMessage("Please_wait___"))):u()):window.onhashchange=function(){I()}},U=function(){return q(m.aid,"ping",{bg:!0})},O=function(){return q(m.aid,"install")},q=function(a,c,b){b=b||{};var g=K();try{var e={aid:a,method:c};b.data&&v.each(b.data,function(a,c){e[c]=b.data[c]});sendMessage({method:"askCom",data:e},function(a){b.bg||x.hide();a.error?("close"==a.action&&u(),g.reject(a)):g.resolve(a)});b.bg||x.wait(l.getMessage("Please_wait___"))}catch(f){console.warn("sS: "+
f.message),g.reject()}return g.promise()};rea.extension.onMessage.addListener(function(a,c,b){if("confirm"==a.method)v.confirm(a.msg,function(a){b({confirm:a})});else if("showMsg"==a.method)v.alert(a.msg),b({});else return!1;return!0});I()})});
