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