Копипаста:Лурк:Участник:Anotubus/Edittools2.js

Материал из Неолурк, народный Lurkmore
Перейти к навигации Перейти к поиску


// ==UserScript== // @include http://lurkmore.ru/* // ==/UserScript== window.opera.addEventListener( 'BeforeScript', function (e) { var t = e.element.text; t = t.replace(/\/\/importScript\("MediaWiki:Common.js\/edit.js"\)/,'addOnloadHook(MyEditTools.init);'); e.element.text=t; }, false );

function appendCSS(text) { var s = document.createElement('style'); s.type = 'text/css'; s.rel = 'stylesheet'; if (s.styleSheet) s.styleSheet.cssText = text //IE else s.appendChild(document.createTextNode(text + )) //Safari sometimes borks on null document.getElementsByTagName('head')[0].appendChild(s); return s; };

//

// Powered by [[User:Tachikoma|СделаноНаКоленке™]]
// Everything is preliminary and is subject to change without notice

var TabSwitchTimer=null;
var TabSwitchFixed=[];
var TabSwitchShowAll=false;

var MyEditTools = {
extraCSS : '\
    #switcher { font-family: sans-serif; }\
    #switcher div { padding: 0px 5px; display: inline-block;}\
    #switcher div.selected { border-color: #fabd23; padding: 0 0 .2em 0; font-weight: bold; border: 1px solid; border-bottom: none; top: 1px; padding-top: 2px; margin-right: -3px; }\
    #switcher div u { text-decoration:none; }\
    #editpage-specialchars tr { height: 65px; }\
    #editpage-specialchars table { width: 100%; border:solid thin #aaa; }\
  ',
show : function(t) {
var table=document.getElementById("editpage-specialchars").getElementsByTagName("table")[0];
var rows=table.getElementsByTagName("tr");
var sw=document.getElementById("switcher").getElementsByTagName("div");
for(i=0;i<rows.length;i++) {
var row_selected=TabSwitchShowAll||(t==i)||TabSwitchFixed[i];
rows[i].style.display=row_selected?"table-row":"none";
sw[i].className=row_selected?"selected":"";
};
document.getElementById("pageShowAll").className=TabSwitchShowAll?"selected":"";
},
clearTimer : function(){
if(TabSwitchTimer)window.clearTimeout(TabSwitchTimer); TabSwitchTimer=null;
},
init : function() {
var switcher=document.createElement("div");
switcher.setAttribute("id","switcher");

var edittools_div=document.getElementById("editpage-specialchars");
var table=edittools_div.getElementsByTagName("table")[0];
var rows=table.getElementsByTagName("tr")
for(i=0;i<rows.length;i++) {
function createHoverCallback(i) {
return function() {
if(TabSwitchTimer) window.clearTimeout(TabSwitchTimer);
TabSwitchTimer=window.setTimeout(MyEditTools.show,150,i);
};
};
function createClickCallback(i) {
return function() {
TabSwitchFixed[i]=!TabSwitchFixed[i];
};
};

var d=document.createElement("div");
var td=rows[i].getElementsByTagName("td")[0];
d.innerHTML=td.innerHTML.replace(/:/,'');
d.onmouseover=createHoverCallback(i);
d.onmouseout=MyEditTools.clearTimer;
d.onclick=createClickCallback(i);
d.setAttribute("id","page"+i);
switcher.appendChild(d);
if(i!=0)rows[i].style.display='none';
if(i==0)d.className="selected"
};
var d=document.createElement("div");
d.setAttribute("id","pageShowAll");
d.onclick=function() {MyEditTools.clearTimer();TabSwitchShowAll=!TabSwitchShowAll;MyEditTools.show(0);};
d.innerText="Show All";
switcher.appendChild(d);

edittools_div.style.border="none";

table.parentNode.insertBefore(switcher, table);
appendCSS(MyEditTools.extraCSS);
}
};

MyEditTools.init();

//