Registry.require("crcrc helper uri layout/default/htmlutil i18n layout/default/layout_helper".split(" "),function(){var w=rea.FEATURES,n=Registry.get("crcrc").cr,h=Registry.get("crcrc").crc,x=Registry.get("helper"),q=Registry.get("layout/default/htmlutil"),A=Registry.get("uri"),k=Registry.get("i18n"),B=Registry.get("layout"),C=Registry.get("layout/default/layout_helper"),t=C.images,r=3;if(w.RUNTIME.MOBILE)try{window.matchMedia("(orientation: portrait)").matches&&(r=1)}catch(p){}B.render(function(){var p=
{},D;C.addStyle();var Q=function(b,a){var d=[];if(a.sub_menu_item){if(a.tabId&&(D=a.tabId),a.items.length){var c=h("table","actiontable","actiontable-"+a.name);E(c,a.items);d.push(c)}}else if(c=null,a.image?c=q.createIcon(t.get(a.image),a.name,a.id,null,""):a.enabler&&(c=q.createIcon(t.get(p.enabled?"button_ok":"cancel"),a.name,a.uuid,null,"")),c&&d.push(c),a.url||a.urls){for(var c=n("span",a.name,a.id,"urls"),e=a.urls||[a],f=0;f<e.length;f++){var g=e[f],y=document.createElement("span");y.textContent=
g.name;var z=a.urls?y:b;z.url=g.url;z.newtab=g.newtab;$(z).addClass("clickable").on("click auxclick",function(a){F(this.url,this.newtab);a.preventDefault()});c.appendChild(y);f<e.length-1&&(g=document.createElement("span"),g.textContent=" | ",c.appendChild(g))}d.push(c)}else if(a.menucmd){var l=document.createElement("span");b.id=a.id;e=function(){M(this.id,function(){w.ACTIONMENU.CLOSE_ALLOWED&&window.close()})};b.addEventListener("click",e);$(b).addClass("clickable");l.textContent=a.name;a.accessKey&&
(c=a.accessKey[0].toUpperCase(),N(c,e,b)?(e=new RegExp(c,"i"),f=l.textContent.search(e),g=[],-1==f&&(l.textContent+=" ("+c+")",f=l.textContent.search(e)),g.push({text:l.textContent.substr(0,f)}),g.push({text:l.textContent.substr(f,1),class:"underlined"}),g.push({text:l.textContent.substr(f+1)}),l.textContent="",g.forEach(function(c){var b=h("span",c.class||"",a.id,c);b.textContent=c.text;l.appendChild(b)})):console.warn("Registering keyboard shortcut for '"+a.name+"' failed"));d.push(l)}else if(a.globalhint)G(a.options);
else if(a.button)c=h("span",a.display||"",a.name,a.id,"bu",!0),c.textContent=a.name,b.key=a.id,b.warning=a.warning,b.reload=a.reload,b.data=a.data,b.addEventListener("click",function(){var a=!0;this.warning&&(a=O(this.warning));a&&P(this.key,{reload:this.reload,data:this.data})}),$(b).addClass("clickable"),d.push(c);else if(a.userscript){var c=h("div","clickable"+(a.active_count?"":" not_executed")+(a.deleted?" was_deleted":""),a.name,a.uuid,"ai"),u;if(a.uuid){f=null;f=a.blacklisted?"enabler_warning":
a.enabled?a.contexter?"enabler_enabled enabler_later":"enabler_enabled":"enabler_disabled";g=a.blacklisted?k.getMessage("This_script_is_blacklisted_"):a.enabled?k.getMessage("Enabled"):k.getMessage("Disabled");e=function(a){if(a&&(0!=a.button||a.ctrlKey||a.metaKey))return F(rea.extension.getURL("options.html")+"#nav="+this.key,!0),a.stopPropagation(),a.preventDefault(),!1;H(this.uuid,"enabled",!this.oldvalue)};f=q.createEnabler(f,a.uuid,"enabled",{append:"enabled",disabled:a.blacklisted||a.deleted,
title:g},e);f.oldvalue=a.enabled;d.push(f);f=h("div","script_name",a.name,a.uuid,"name");f.textContent=k.getTranslation(a,"name");c.appendChild(f);c.uuid=a.uuid;c.oldvalue=a.enabled;c.key=a.uuid;if(a.blacklisted)b.setAttribute("title",k.getMessage("This_script_is_blacklisted_")),$(c).addClass("crossedout");else{if(!a.deleted)$(c).on("click auxclick",e);f.title=a.active_count?k.getMessage("This_script_was_executed_0count0_times",a.active_count):k.getMessage("This_script_was_not_executed_yet")}var v=
[];a.nnew||a.system||!a.abuse||(e=h("div","context_entry",a.name,a.uuid,"action_issue"),g=q.createIcon(t.get("flag"),"",a.uuid,"issue",k.getMessage("Report_an_issue_to_the_script_hoster_")),f=n("span",a.name,a.uuid,"action_issue_expl"),f.textContent=k.getMessage("Report_an_issue_to_the_script_hoster_").split(/[\.\(]+/)[0],e.appendChild([g,f]),$(e).click(function(){I(a.uuid,"hoster")}),v.push(e));a.nnew||a.system||!a.support||(e=h("div","context_entry",a.name,a.uuid,"action_bug"),g=q.createIcon(t.get("bug"),
"",a.uuid,"bug",k.getMessage("Report_a_bug")),f=n("span",a.name,a.uuid,"action_issue_expl"),f.textContent=k.getMessage("Report_a_bug"),e.appendChild([g,f]),$(e).click(function(){I(a.uuid,"author")}),v.push(e));var r={};a.active_urls&&a.active_urls.forEach(function(c){var b=A.parse(c).hostname;if(!r[b]){r[b]=!0;var e="/"+A.getRegExpFromMatch("*://*."+b+"/*")+"/";if(!a.override||-1==a.override.use_excludes.indexOf(e)){var d=h("div","context_entry",a.name,a.uuid,"action_domain"),b=k.getMessage("Exclude_0domain0",
b);c=q.createIcon(t.get("no"),"",a.uuid,"domain"+c,b);var f=n("span",a.name,a.uuid,"action_domain");f.textContent=b;d.appendChild([c,f]);$(d).click(function(c){H(a.uuid,"add_excludes",[e])});v.push(d)}}});if(!a.deleted&&v.length){u=h("div","actionenablercol",a.name,a.uuid,"actionenablercol");e=h("i","actionenabler clickable far fa-"+t.get("enabler"),a.name,a.uuid,"actionenabler");$("body").click(function(){$(".script_context_menu").hide()});$(e).click(function(a){var c=$(u).find(".script_context_menu");
c.is(":visible")||$(".script_context_menu").hide();c.toggle();a.stopPropagation()});var m=h("div","script_context_menu",a.name,a.uuid,"action_bug",!0);v.forEach(function(a){m.appendChild(a)});m.setAttribute("style","display:none;");u.appendChild(m);u.appendChild(e)}}d.push(c);u&&d.push(u)}else c=n("span",a.name,a.id,"ai"),c.textContent=a.name,d.push(c);return d},E=function(b,a,d){Object.keys(a).forEach(function(c){var e=a[c];if(!b)if(d[e.pos])e.items&&e.items.length&&$(d[e.pos]).show();else{console.warn("Warn(cAm): unknown pos "+
e.pos);return}var f=(c=b||d[e.pos])?n("tr",e.name,e.uuid||e.id,"outer"):null,g=Q(f,e);if(g&&g.length){c.appendChild(f);var h;for(c=0;h=g[c];c++){var k=c==g.length-1?3-c:0,l=n("td","actiontd",e.name,e.uuid||e.id,c);0<k&&l.setAttribute("colspan",k);h&&l.appendChild(h);f.appendChild(l)}}})},J=function(b){var a=$("#action"),d=n("div");d.setAttribute("id","action");a.replaceWith(d);var c=h("table","actionlayout","actionlayout");d.appendChild(c);d=h("tr","actionpostr","hor");a=h("td","actionpostd","hor_west");
d.appendChild(a);c.appendChild(d);var e=h("table","actionregion","top"),f=h("table","actionregion","right"),g,k=h("table","actionregion","left"),m=h("table","actionregion","bottom");if(2<Math.min(p.action_menu_columns,r)){g=h("table","actionregion","center");var l=h("td","actionpostd","hor_center"),c=h("td","actionpostd","hor_east");l.appendChild(g);d.appendChild(l);d.appendChild(c)}else 1<Math.min(p.action_menu_columns,r)?(g=f,c=h("td","actionpostd","hor_east"),d.appendChild(c)):g=c=k;$([g,f]).hide();
a.appendChild(e);c.appendChild(f);a.appendChild(k);a.appendChild(m);E(null,b,{top:e,left:k,center:g,right:f,bottom:m})},F=function(b,a){try{var d=function(){a&&w.ACTIONMENU.CLOSE_ALLOWED&&window.close()};a?sendMessage({method:"newTab",url:b},d):rea.tabs.getSelected(null,function(c){rea.tabs.sendMessage(c.id,{method:"loadUrl",url:b,newtab:a},d)})}catch(c){console.warn("lU:",c)}},O=function(b){var a=confirm(b.msg),d={};a&&b.ok?d=b.ok:!a&&b.cancel&&(d=b.cancel);if(b.ok||b.cancel)a=!0;d.url&&sendMessage({method:"newTab",
url:d.url},function(a){});return a},G=function(b){var a,d=b.key||"general";(a=K[d])&&$(a).remove();K[d]=q.createGobalHint(x.copy(b,{instant:!0}),$("body > div.status")[0])},I=function(b,a,d){try{sendMessage({method:"reportAnIssue",uuid:b,to:a},function(a){d&&d()})}catch(c){console.warn("raI:",c)}},P=function(b,a){try{sendMessage({method:"buttonPress",name:b,data:a.data},function(b){a.reload&&rea.page.reload()})}catch(d){console.warn("rSU:",d)}},m={},R=function(b,a,d){document.body.addEventListener("keydown",
function(a){a.altKey||a.ctrlKey||a.shiftKey||Object.keys(m).forEach(function(b){(b=m[b])&&a.keyCode==b.key&&b.cb.apply(b.elem||window,[])})},!1)},N=function(b,a,d){b=b.charCodeAt(0);if(m[b])return console.log("MenuCmdKeyListener: ...failed!"),!1;m[b]={key:b,cb:a,elem:d};return!0},M=function(b,a){try{sendMessage({method:"execMenuCmd",id:b},function(b){a&&a()})}catch(d){console.warn("Error(eMC):",d)}},H=function(b,a,d){try{b={method:"modifyScriptOptions",uuid:b},a&&""!=a&&(b[a]=d),sendMessage(b,function(a){document.getElementById("action").innerHTML=
"";a&&(a.i18n&&k.setLocale(a.i18n),a.items&&(a.options&&(p=x.assign(p,a.options)),J(a.items)))})}catch(c){console.warn("Error(mSo): "+c.message)}},S=function(b,a){var d=Date.now(),c=b.min_delay;sendMessage({method:"loadTree",referrer:b.referrer,layout:b.layout,available_columns:r,uuid:b.uuid,tabId:b.tabId},function(b){b.options&&(p=x.assign(p,b.options));b.layout&&B.applyTheme(b.layout);b.i18n&&k.setLocale(b.i18n);var f=Date.now()-d,g=function(){a(b)};!c||f>=c?g():window.setTimeout(g,c-f)})},K={};
rea.extension.onMessage.addListener(function(b,a,d){"update"==b.method?L():"status"==b.method?(G(b.options),d({})):console.log('onMessage: Unknown method "'+b.method+'"')});var L=window.main=function(){S({referrer:"actions",min_delay:w.ACTIONMENU.MIN_DELAY,layout:!0,tabId:D},function(b){if(b.options&&b.options.layout_user_css){var a=document.createElement("style");a.innerHTML=b.options.layout_user_css;(document.head||document.body||document.documentElement||document).appendChild(a)}R();J(b.items)})};
L()})});
