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