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