Registry.require(["crcrc","helper","layout/default/htmlutil","i18n","layout/default/layout_helper"],function(){var t=rea.FEATURES,q=Registry.get("crcrc").cr,h=Registry.get("crcrc").crc,y=Registry.get("helper"),r=Registry.get("layout/default/htmlutil"),l=Registry.get("i18n"),u=Registry.get("layout"),v=Registry.get("layout/default/layout_helper"),w=v.images;u.render(function(){var n={};v.addStyle();v.addFont();var u=function(b,a){var e=[];if(a.sub_menu_item){var c=h("table","actiontable","actiontable-"+
a.name);z(c,a.items);e.push(c)}else if(c=null,a.image?c=r.createImage(w.get(a.image),a.name,a.id,null,""):a.enabler&&(c=r.createImage(rea.extension.getURL(n.enabled?"/layout/default/images/button_ok.png":"/layout/default/images/cancel.png"),a.name,a.uuid,null,"")),c&&e.push(c),a.url||a.urls){for(var c=q("span",a.name,a.id,"urls"),d=a.urls||[a],f=0;f<d.length;f++){var g=d[f],x=document.createElement("span");x.textContent=g.name;var m=a.urls?x:b;m.url=g.url;m.newtab=g.newtab;m.addEventListener("click",
function(){C(this.url,this.newtab)});$(m).addClass("clickable");c.appendChild(x);f<d.length-1&&(g=document.createElement("span"),g.textContent=" | ",c.appendChild(g))}e.push(c)}else if(a.menucmd){var k=document.createElement("span");b.id=a.id;d=function(){D(this.id,function(){t.ACTIONMENU.CLOSE_ALLOWED&&window.close()})};b.addEventListener("click",d);$(b).addClass("clickable");k.textContent=a.name;a.accessKey&&(c=a.accessKey[0].toUpperCase(),E(c,d,b)?(d=RegExp(c,"i"),f=k.textContent.search(d),g=[],
-1==f&&(k.textContent+=" ("+c+")",f=k.textContent.search(d)),g.push({text:k.textContent.substr(0,f)}),g.push({text:k.textContent.substr(f,1),class:"underlined"}),g.push({text:k.textContent.substr(f+1)}),k.textContent="",g.forEach(function(c){var d=h("span",c.class||"",a.id,c);d.textContent=c.text;k.appendChild(d)})):console.warn("Registering keyboard shortcut for '"+a.name+"' failed"));e.push(k)}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=F(this.warning));a&&G(this.key,{reload:this.reload,data:this.data})}),$(b).addClass("clickable"),e.push(c);else if(a.userscript||a.user_agent){var c=q("span",a.name,a.uuid,"ai"),p;a.uuid&&(f=null,f=a.blacklisted?"enabler_warning":a.enabled?a.contexter?"enabler_later":"enabler_enabled":"enabler_disabled",g=a.blacklisted?l.getMessage("This_script_is_blacklisted_"):a.enabled?l.getMessage("Enabled"):
l.getMessage("Disabled"),d=function(a){a&&a.button&2||a.button&1||a.ctrlKey?(window.open(rea.extension.getURL("options.html")+"#open="+this.key),a.stopPropagation()):H(this.uuid,"enabled",!this.oldvalue)},f=r.createEnabler(f,a.uuid,"enabled","enabled",g,d,0<a.position?10>a.position?" "+a.position:a.position:null),f.oldvalue=a.enabled,e.push(f),c.uuid=a.uuid,c.oldvalue=a.enabled,c.key=a.uuid,c.addEventListener("click",d),d=" clickable",a.blacklisted&&(d+=" crossedout",b.setAttribute("title",l.getMessage("This_script_is_blacklisted_"))),
$(b).addClass(d),d=[],a.nnew||a.system||!a.origin||(f=r.createImage(w.get("flag"),"",a.uuid,"issue",l.getMessage("Report_an_issue_to_the_script_hoster_"),function(){A(a.uuid,"hoster")}),d.push(f)),a.nnew||a.system||!a.support||(f=r.createImage(w.get("bug"),"",a.uuid,"bug",l.getMessage("Report_a_bug"),function(){A(a.uuid,"author")}),d.push(f)),d.length&&(p=h("div","actionbuttons",a.uuid,"actions"),d.forEach(function(a){p.appendChild(a)})));c.textContent=l.getTranslation(a,"name");e.push(c);p&&e.push(p)}else c=
q("span",a.name,a.id,"ai"),c.textContent=a.name,e.push(c);return e},z=function(b,a,e){for(var c in a){var d=a[c];if(!b)if(e[d.pos])d.items&&d.items.length&&$(e[d.pos]).show();else{console.warn("Warn(cAm): unknown pos "+d.pos);continue}var f=b||e[d.pos],g=f?q("tr",d.name,d.uuid||d.id,"outer"):null,h=u(g,d);if(h&&h.length)for(f.appendChild(g),c=0;f=h[c];c++){var m=c==h.length-1?3-c:0,k=q("td","actiontd",d.name,d.uuid||d.id,c);0<m&&k.setAttribute("colspan",m);f&&k.appendChild(f);g.appendChild(k)}}},
B=function(b,a){var e=document.getElementById("action"),c=e.parentNode;c.removeChild(e);e=q("span");e.setAttribute("id","action");c.appendChild(e);var d=h("table","actionlayout","actionlayout");e.appendChild(d);e=h("tr","actionpostr","hor");c=h("td","actionpostd","hor_west");e.appendChild(c);d.appendChild(e);var f=h("table","actionregion","top"),g=h("table","actionregion","right"),l,m=h("table","actionregion","left"),k=h("table","actionregion","bottom");if(2<Math.min(n.action_menu_columns,t.ACTIONMENU.COLUMNS)){l=
h("table","actionregion","center");var p=h("td","actionpostd","hor_center"),d=h("td","actionpostd","hor_east");p.appendChild(l);e.appendChild(p);e.appendChild(d)}else 1<Math.min(n.action_menu_columns,t.ACTIONMENU.COLUMNS)?(l=g,d=h("td","actionpostd","hor_east"),e.appendChild(d)):l=d=m;$([l,g]).hide();c.appendChild(f);d.appendChild(g);c.appendChild(m);c.appendChild(k);z(null,b,{top:f,left:m,center:l,right:g,bottom:k})},C=function(b,a){try{var e=function(){a&&t.ACTIONMENU.CLOSE_ALLOWED&&window.close()};
a?sendMessage({method:"newTab",url:b},e):rea.tabs.getSelected(null,function(c){rea.tabs.sendMessage(c.id,{method:"loadUrl",url:b,newtab:a},e)})}catch(c){console.warn("lU:",c)}},F=function(b){var a=confirm(b.msg),e={};a&&b.ok?e=b.ok:!a&&b.cancel&&(e=b.cancel);if(b.ok||b.cancel)a=!0;e.url&&sendMessage({method:"newTab",url:e.url},function(a){});return a},A=function(b,a,e){try{sendMessage({method:"reportAnIssue",uuid:b,to:a},function(a){e&&e()})}catch(c){console.warn("raI:",c)}},G=function(b,a){try{sendMessage({method:"buttonPress",
name:b,data:a.data},function(c){a.reload&&window.location.reload()})}catch(e){console.warn("rSU:",e)}},s={},I=function(b,a,e){document.body.addEventListener("keydown",function(a){if(!(a.altKey||a.ctrlKey||a.shiftKey))for(var d in s)if(s.hasOwnProperty(d)){var b=s[d];b&&a.keyCode==b.key&&b.cb.apply(b.elem||window,[])}},!1)},E=function(b,a,e){b=b.charCodeAt(0);if(s[b])return console.log("MenuCmdKeyListener: ...failed!"),!1;s[b]={key:b,cb:a,elem:e};return!0},D=function(b,a){try{sendMessage({method:"execMenuCmd",
id:b},function(b){a&&a()})}catch(e){console.warn("Error(eMC):",e)}},H=function(b,a,e){try{b={method:"modifyScriptOptions",uuid:b},a&&""!=a&&(b[a]=e),document.getElementById("action").textContent=l.getMessage("Please_wait___"),sendMessage(b,function(a){a&&(a.i18n&&l.setLocale(a.i18n),a.items&&(a.options&&(n=y.assign(n,a.options)),B(a.items)))})}catch(c){console.warn("Error(mSo): "+c.message)}};rea.extension.onMessage.addListener(function(b,a,e){"updateActions"==b.method?window.location.reload():console.log("onMessage: Unknown method '"+
b.method+"'")});(function(b,a){sendMessage({method:"loadTree",referrer:b},function(b){b.options&&(n=y.assign(n,b.options));b.i18n&&l.setLocale(b.i18n);a(b.items)})})("actions",function(b){I();B(b)})})});
