Benutzer:ASM/WIP

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

/*

  • /

/*

*/

// script name | script path | exec if enabled | exec if disabled | load by default | description

var ScriptList = [
   ['PDD',                 'w:de:Benutzer:ASM/PDD.js', '', '', true,
                           'PDD`s Monobook, umfangreiches Script mit etlichen Tools'],

   ['Dropdown-Menüs',      '', 'usedropdown = true', 'usedropdown = false', true,
                           'Aktiviert Dropdown-Menüs in der Quickbar von PDD`s Monobook (nur relevant, wenn PDD`s Monobook aktiviert ist)'],

   ['QuickEdit',           'w:de:Benutzer:ASM/quickedit.js', '', '', true,
                           'Erlaubt schnelles Bearbeiten von Absätzen per AJAX'],

   ['Lupins Popups',       'w:en:User:Lupin/popups.js', '', '', false,
                           ''],

   ['Picture Popups',      'w:en:User:Zocky/PicturePopups.js', '', '', true,
                           'Öffnet Bilder in einem Popup'],

   ['wikEd',               'w:en:User:Cacycle/wikEd.js', '', '', false,
                           ''],

   ['Rechtschreibprüfung', 'w:de:Benutzer:APPER/RP/js', '', '', false,
                           ''],

   ['IP-Patrol',           'w:de:Benutzer:APPER/IP-Patrol/js', '', '', false,
                           ''],

   ['Redundante Links',    'w:de:Benutzer:PDD/showRedundantLinks.js', '', '', false,
                           ''],

   ['Auto-Signatur',       'w:de:Benutzer:Olliminatore/signing.js', '', '', false,
                           'Fügt auf Diskussionsseiten automatisch die eigene Signatur ein'],

   ['Unsignierte Beiträge','w:de:Benutzer:Olliminatore/unsigned.js', '', '', false,
                           'Zeigt unsignierte Beiträge auf Diskussionsseiten'],

   ['Edit-Suchbox',        'w:en:User:Zocky/SearchBox.js', '', '', false,
                           'Erstellt eine Suchleiste auf der Bearbeitungsseite zum Suchen im Bearbeitungsfeld'],

   ['Syntax-Highlight',    'w:en:User:Olliminatore/shCore.js', '', '', false,
                           ''],

   ['Mini-Atlas',          'w:de:Benutzer:Dschwen/wikiminiatlas2.js', '', '', false,
                           ''],

   ['Koordinaten',         'w:de:Benutzer:Dschwen/coordinates.js', '', '', false,
                           ''],

   ['Reftoggle',           'w:de:Benutzer:Malte_Schierholz/reftoggle.js', '', '', false,
                           'Blendet die Einzelnachweisliste in Artikeln standardmäßig aus'],

   ['ß in SS ändern',      'w:de:Benutzer:PDD/changeSZtoSS.js', '', '', false,
                           ''],

   ['Neue Galerie',        'w:de:Benutzer:Olliminatore/newgallery.js', '', '', false,
                           ''],

   ['Custom Toolbar',      'w:de:Benutzer:Olliminatore/customToolbar.js', '', '', false,
                           '']
];

/*
*/

var smEnabled = true;
var smInit    = false;
var smLoaded  = false;
var smActive  = false;
var smCookie  = /ScriptManager=([^;]+)/;

LoadScripts();

addOnloadHook(InitScriptManager);

function InitScriptManager()
{
   if (!smEnabled || smInit) return;
   smInit = true;

   var navi = smGet('p-navigation').getElementsByTagName('ul')[0];
   AddLink(AddChildNode(navi, 'li'), 'javascript:ScriptManager()', 'Script Manager');
}

function LoadScripts()
{
   if (smLoaded) return;
   smLoaded = true;

   var cookie = smCookie.exec(document.cookie);
   for (var i = 0; i < ScriptList.length; i++)
   {
      if (cookie) // look at cookies to find out if the script is to be loaded
      {
         var id = ScriptList[i][0];
         var re = eval('/' + id + ':(0|1)/');
         var m = re.exec(cookie[1]);

         if (m) ScriptList[i][4] = (m[1] == '1');
      }

      if (ScriptList[i][4]) // load script
      {
         smImportScriptPlain(smResource(ScriptList[i][1]));
         eval(ScriptList[i][2]);
      }

      else eval(ScriptList[i][3]); // dont load it
   }
}

function ScriptManager()
{
   if (!smActive) smChangePage();
   else           smSaveChanges();

   smActive = !smActive;
}

function smChangePage()
{
   if (smActive) return;

   var sm = smGet('ScriptManager');
   if (sm)
   {
      sm.parentNode.style.display = 'block';
      return;
   }
  
   var navi = smGet('p-navigation').cloneNode(false);
   AddNodeText(navi, 'h5', 'Script Manager');
   navi.id       = 'p-scriptmanager';

   var div       = AddChildNode(navi, 'div');
   div.id        = 'ScriptManager';
   div.className = 'pBody';

   smGet('column-one').insertBefore(navi, smGet('p-navigation').nextSibling);

   var table = AddChildNode(div, 'table');
   table.style.marginTop   = '3px';
   table.style.border      = 'none';
   table.style.width       = '98%';
   table.style.fontSize    = '11.3px';
   table.style.cursor      = 'default';
   table.setAttribute('cellspacing', '0');
   table.setAttribute('cellpadding', '0');

   AddChildNodes(table, 'tr', ScriptList.length+1);
  
   for (var i = 0; i < ScriptList.length; i++)
   {
      var tr = table.childNodes[i];
      var s  = ScriptList[i];

      var td1 = AddNodeText(tr, 'td', s[4]?'On':'Off');
      var td2 = AddNodeText(tr, 'td', s[0]);

      td1.style.color      = td2.style.color = s[4]?'#002bb8':'#aaa';
      td1.style.padding    = td1.style.padding = '2px';
      td1.style.fontWeight = 'bold';
      td1.style.cursor     = 'pointer';
      td1.style.width      = '15%';

      td2.title            = s[5];

      td1.setAttribute('onclick', 'eval("ChangeStatus(' + i + ')")');
      td2.setAttribute('onclick', 'eval("ChangeStatus(' + i + ')")');
   }

   var td = AddChildNode(table.lastChild, 'td');
   td.colSpan         = 2;
   td.style.borderTop = '1px dotted #aaa';
   td.style.marginTop = '3px';
   td.style.padding   = '2px';

   AddLink(td, 'javascript:ScriptManager(1)', 'Speichern');
}

function ChangeStatus(n)
{
   var s = ScriptList[n];
   var c = smGet('ScriptManager').firstChild.childNodes[n];

   if (s[4])
   {
      AttribAllChildNodes(c, 'style.color', '#aaa');
      c.firstChild.firstChild.nodeValue = 'Off';
      s[4] = false;
   }
   else
   {
      AttribAllChildNodes(c, 'style.color', '#002bb8');
      c.firstChild.firstChild.nodeValue = 'On';
      s[4] = true;
   }
}

function smSaveChanges()
{
   if (!smActive) return;

   var str = '';
   for (var i = 0; i < ScriptList.length; i++)
      str += ',' + ScriptList[i][0] + ':' + (ScriptList[i][4]?'1':'0');

   document.cookie = 'ScriptManager=' + str.substr(1) + ';expires=January 1, 2010';

   smGet('ScriptManager').parentNode.style.display = 'none';
}


// Helper Functions

function smGet(id)
{
   return document.getElementById(id);
}

function GetNodeContent(node)
{
   return (node.nodeType == 3)?node.nodeValue:node.innerHTML;
}

function AddText(node, text)
{
   return node.appendChild(document.createTextNode(text));
}

function AddChildNode(parent, element)
{
   return parent.appendChild(document.createElement(element));
}

function AddChildNodes(parent, element, num)
{
   while (num--) parent.appendChild(document.createElement(element));
}

function AttribAllChildNodes(parent, attrib, value)
{
   for (var i = 0; i < parent.childNodes.length; i++)
      eval('parent.childNodes[i].' + attrib + ' = "' + value + '";');
}

function AddNodeText(parent, element, text)
{
   var node = AddChildNode(parent, element);
   AddText(node, text);
   return node;
}

function AddLink(parent, link, text)
{
   var node = AddNodeText(parent, 'a', text);
   node.href = link;
   return node;
}

function RemoveNode(node)
{
   node.parentNode.removeChild(node);
}

function GetElementsByClassName(tagname, classname)
{
   var ret = new Array();
   var tags = document.getElementsByTagName(tagname);
   for (i = 0; i < tags.length; i++)
      if (tags[i].className == classname)
         ret.push(tags[i]);

   return ret;
}


// Resources

function smImportScriptPlain(script)
{
   if (!script.length) return;

   var head = document.getElementsByTagName('head').item(0);

   var js   = document.createElement('script');
   js.setAttribute('type', 'text/javascript');
   js.setAttribute('src', script);
   js.setAttribute('charset', 'utf-8');

   head.appendChild(js);
}

// from QuickEdit
function smResource(res)
{
   var commonsurl = 'http://upload.wikimedia.org/wikipedia/commons/';
   var wikiurl    = 'http://XX.wikipedia.org/w/index.php?title=TT&action=raw&ctype=text/javascript';

   if (res.indexOf('c:') == 0)
      return commonsurl + res.substr(2);

   if (res.indexOf('w:') == 0)
   {
      wikiurl = wikiurl.replace(/XX/, res.substring(res.indexOf(':') + 1, res.indexOf(':',2)));
      wikiurl = wikiurl.replace(/TT/, res.substring(res.indexOf(':',2) + 1));

      return wikiurl;
   }

   return res;
}



/*

*/