Registry.require(["crcrc","helper","layout/default/htmlutil","i18n","layout/default/layout_helper"],function(){var u=rea.FEATURES,r=Registry.get("crcrc").cr,g=Registry.get("crcrc").crc,y=Registry.get("helper"),v=Registry.get("layout/default/htmlutil"),m=Registry.get("i18n"),x=Registry.get("layout"),z=Registry.get("layout/default/layout_helper"),w=z.images;x.render(function(){var q={};z.addStyle();var x=function(b,a){var d=[];if(a.sub_menu_item){if(a.items.length){var c=g("table","actiontable","actiontable-"+
a.name);A(c,a.items);d.push(c)}}else if(c=null,a.image?c=v.createImage(w.get(a.image),a.name,a.id,null,""):a.enabler&&(c=v.createImage(rea.extension.getURL(q.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=r("span",a.name,a.id,"urls"),e=a.urls||[a],f=0;f<e.length;f++){var n=e[f],h=document.createElement("span");h.textContent=n.name;var l=a.urls?h:b;l.url=n.url;l.newtab=n.newtab;n=function(){D(this.url,
this.newtab)};l.addEventListener("click",n);l.addEventListener("auxclick",n);$(l).addClass("clickable");c.appendChild(h);f<e.length-1&&(h=document.createElement("span"),h.textContent=" | ",c.appendChild(h))}d.push(c)}else if(a.menucmd){var k=document.createElement("span");b.id=a.id;e=function(){E(this.id,function(){u.ACTIONMENU.CLOSE_ALLOWED&&window.close()})};b.addEventListener("click",e);$(b).addClass("clickable");k.textContent=a.name;a.accessKey&&(c=a.accessKey[0].toUpperCase(),F(c,e,b)?(e=new RegExp(c,
"i"),f=k.textContent.search(e),h=[],-1==f&&(k.textContent+=" ("+c+")",f=k.textContent.search(e)),h.push({text:k.textContent.substr(0,f)}),h.push({text:k.textContent.substr(f,1),class:"underlined"}),h.push({text:k.textContent.substr(f+1)}),k.textContent="",h.forEach(function(c){var b=g("span",c.class||"",a.id,c);b.textContent=c.text;k.appendChild(b)})):console.warn("Registering keyboard shortcut for '"+a.name+"' failed"));d.push(k)}else if(a.button)c=g("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=G(this.warning));a&&H(this.key,{reload:this.reload,data:this.data})}),$(b).addClass("clickable"),d.push(c);else if(a.userscript){var c=g("div","clickable",a.name,a.uuid,"ai"),t;if(a.uuid&&(f=null,f=a.blacklisted?"enabler_warning":a.enabled?a.contexter?"enabler_enabled enabler_later":"enabler_enabled":"enabler_disabled",h=a.blacklisted?m.getMessage("This_script_is_blacklisted_"):
a.enabled?m.getMessage("Enabled"):m.getMessage("Disabled"),e=function(a){a&&(0!=a.button||a.ctrlKey||a.metaKey)?(window.open(rea.extension.getURL("options.html")+"#nav="+this.key),a.stopPropagation()):I(this.uuid,"enabled",!this.oldvalue)},f=v.createEnabler(f,a.uuid,"enabled",{append:"enabled",disabled:a.blacklisted,title:h},e),f.oldvalue=a.enabled,d.push(f),f=r("div",a.name,a.uuid,"name"),f.textContent=m.getTranslation(a,"name"),c.appendChild(f),c.uuid=a.uuid,c.oldvalue=a.enabled,c.key=a.uuid,c.addEventListener("click",
e),c.addEventListener("auxclick",e),a.blacklisted&&(b.setAttribute("title",m.getMessage("This_script_is_blacklisted_")),$(c).addClass("crossedout")),e=[],a.nnew||a.system||!a.origin||(f=g("div","action_issue",a.name,a.uuid,"action_issue"),l=v.createImage(w.get("flag"),"",a.uuid,"issue",m.getMessage("Report_an_issue_to_the_script_hoster_")),h=g("span","",a.name,a.uuid,"action_issue_expl"),h.textContent=m.getMessage("Report_an_issue_to_the_script_hoster_").split(/[\.\(]+/)[0],f.appendChild([l,h]),$(f).click(function(){B(a.uuid,
"hoster")}),e.push(f)),a.nnew||a.system||!a.support||(f=g("div","action_issue",a.name,a.uuid,"action_bug"),l=v.createImage(w.get("bug"),"",a.uuid,"bug",m.getMessage("Report_a_bug")),h=g("span","",a.name,a.uuid,"action_issue_expl"),h.textContent=m.getMessage("Report_a_bug"),f.appendChild([l,h]),$(f).click(function(){B(a.uuid,"author")}),e.push(f)),e.length)){t=g("div","actionenablercol",a.name,a.uuid,"actionenablercol");f=g("img","actionenabler clickable",a.name,a.uuid,"actionenabler");f.src=w.get("enabler");
$("body").click(function(){$(".action_issues").hide()});$(f).click(function(a){var c=$(t).find(".action_issues");$(c).is(":visible")||$(".action_issues").hide();c.toggle();a.stopPropagation()});var p=g("div","action_issues",a.name,a.uuid,"action_bug");e.forEach(function(a){p.appendChild(a)});p.setAttribute("style","display:none;");t.appendChild(p);t.appendChild(f)}d.push(c);t&&d.push(t)}else c=r("span",a.name,a.id,"ai"),c.textContent=a.name,d.push(c);return d},A=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])?r("tr",e.name,e.uuid||e.id,"outer"):null,g=x(f,e);if(g&&g.length){c.appendChild(f);var h;for(c=0;h=g[c];c++){var l=c==g.length-1?3-c:0,k=r("td","actiontd",e.name,e.uuid||e.id,c);0<l&&k.setAttribute("colspan",l);h&&k.appendChild(h);f.appendChild(k)}}})},C=function(b,a){var d=$("#action"),c=r("div");c.setAttribute("id","action");d.replaceWith(c);var e=g("table",
"actionlayout","actionlayout");c.appendChild(e);c=g("tr","actionpostr","hor");d=g("td","actionpostd","hor_west");c.appendChild(d);e.appendChild(c);var f=g("table","actionregion","top"),n=g("table","actionregion","right"),h,l=g("table","actionregion","left"),k=g("table","actionregion","bottom");if(2<Math.min(q.action_menu_columns,u.ACTIONMENU.COLUMNS)){h=g("table","actionregion","center");var m=g("td","actionpostd","hor_center"),e=g("td","actionpostd","hor_east");m.appendChild(h);c.appendChild(m);
c.appendChild(e)}else 1<Math.min(q.action_menu_columns,u.ACTIONMENU.COLUMNS)?(h=n,e=g("td","actionpostd","hor_east"),c.appendChild(e)):h=e=l;$([h,n]).hide();d.appendChild(f);e.appendChild(n);d.appendChild(l);d.appendChild(k);A(null,b,{top:f,left:l,center:h,right:n,bottom:k})},D=function(b,a){try{var d=function(){a&&u.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)}},G=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},B=function(b,a,d){try{sendMessage({method:"reportAnIssue",uuid:b,to:a},function(a){d&&d()})}catch(c){console.warn("raI:",c)}},H=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)}},p={},J=function(b,a,d){document.body.addEventListener("keydown",
function(a){a.altKey||a.ctrlKey||a.shiftKey||Object.keys(p).forEach(function(b){(b=p[b])&&a.keyCode==b.key&&b.cb.apply(b.elem||window,[])})},!1)},F=function(b,a,d){b=b.charCodeAt(0);if(p[b])return console.log("MenuCmdKeyListener: ...failed!"),!1;p[b]={key:b,cb:a,elem:d};return!0},E=function(b,a){try{sendMessage({method:"execMenuCmd",id:b},function(b){a&&a()})}catch(d){console.warn("Error(eMC):",d)}},I=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&&m.setLocale(a.i18n),a.items&&(a.options&&(q=y.assign(q,a.options)),C(a.items)))})}catch(c){console.warn("Error(mSo): "+c.message)}};rea.extension.onMessage.addListener(function(b,a,d){"updateActions"==b.method?rea.page.reload():console.log("onMessage: Unknown method '"+b.method+"'")});(function(b,a,d){var c=Date.now();sendMessage({method:"loadTree",referrer:b},function(b){b.options&&(q=y.assign(q,b.options));b.i18n&&m.setLocale(b.i18n);var f=Date.now()-c,g=function(){a(b)};!d||f>=d?
g():window.setTimeout(g,d-f)})})("actions",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)}J();C(b.items)},u.ACTIONMENU.MIN_DELAY)})});
