Protected page

User:Olipro/tabscontrol.js

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

Note: After saving, you have to bypass your browser's cache to see the changes.

  • Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
  • Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
  • Opera, Konqueror and Safari users can just click the Reload button.
  • Chrome: press Ctrl+F5 or Shift+F5
//<pre><nowiki>
//Olipro's Add & Edit Links 'n' Tabs

function editLoader()
{
    cPanelink();
    initTab();
    tabEditor();
    saveTabs();
    loadTabs();
}

addOnloadHook(editLoader);

function cPanelink() {
    var tabs = document.getElementById('pt-userpage').parentNode;
    addlilink(tabs, 'javascript:addaTab()', 'add Tab', 'pt-addtab');
    addlilink(tabs, '/wiki/Tab_Editor', 'edit Tabs', 'pt-edittab');
}
function tabEditor()
{
    if(document.title.indexOf("Tab Editor") != -1)
    {
        pcact = document.getElementById('p-cactions');
        pcact.parentNode.removeChild(pcact);
        var ddown = document.getElementById('contentSub');
        var mainer = document.getElementById('bodyContent');
        mainer.removeChild(ddown);
        document.getElementById('bodyContent').innerHTML = '<h3>These are your current Tabs:</h3><br>';
        for(i in tabs)
        {
            if(tabs[i] != null && tabs[i].indexOf('undefined') != 0 && i != 'fishbgdisbg' && i != 'toJSONString')
                document.getElementById('bodyContent').innerHTML += '<ul><li><a href="'+tabs[i]+'">'+i+'</a> (<a href="javascript:deltab(\''+i+'\',1)">delete</a>) (<a href="javascript:renametab(\''+i+'\',1)">rename</a>)</ul></li>';
        }
        document.getElementById('bodyContent').innerHTML +='<br><h3>These are your current Links:</h3><br>';
         for(i in links)
        {
            if(links[i] != null && links[i].indexOf('undefined') != 0 && i != 'fishbgdisbg' && i != 'toJSONString')
                document.getElementById('bodyContent').innerHTML += '<ul><li><a href="'+links[i]+'">'+i+'</a> (<a href="javascript:deltab(\''+i+'\',0)">delete</a>) (<a href="javascript:renametab(\''+i+'\',0)">rename</a>)</ul></li>';
        }
    document.getElementById('bodyContent').innerHTML += '<br><br><a href="javascript:cleanTabs()" onClick="cleanTabs()">Reset All Custom Links and Clean data</a><br><br><a href="/index.php?title=User:'+
wgUserName + '/TabSave&amp;action=edit">Save Tabs to Wiki</a><br><a href="/wiki/User:' +
wgUserName + '/TabSave">Restore Tabs</a>';
    }
}
function cleanTabs()
{
    cookie_date = new Date();
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = "linksdata=; expires=" + cookie_date.toGMTString();
    document.cookie = "tabsdata=; expires=" + cookie_date.toGMTString();
}
function renametab(arrk,what)
{
    var renameto = prompt("What would you like to rename to?");
    if(renameto != null)
    {
        if(what==1)
        {
            tabs[renameto] = tabs[arrk];
            delete tabs[arrk];
        } else {
            links[renameto] = links[arrk];
            delete links[arrk];
        }
    implodeCookie('tabsdata', tabs);
    implodeCookie('linksdata',links);
    window.location.reload(false);
     }
}
function deltab(arrkey, what)
{
    if(what==1)
        delete tabs[arrkey];
    else
        delete links[arrkey];

    implodeCookie('tabsdata', tabs);
    implodeCookie('linksdata',links);
    window.location.reload(false);
}
var tabs = new Array();
var links= new Array();
function addaTab()
{
    var prompter = prompt('Would you like this to be a tab, or a navigation menu link?, Click OK for a tab, or cancel for a nav link', 'Click OK or Cancel');
    var title = prompt('Please enter the title of this link in the box');
    if(title == null || title == '')
        return;
    var url = prompt('now enter a URL *OR* a javascript function you wish to execute preceded with javascript: - please remember to use /wiki/The_Page to link a page','/wiki/');
    if(title != null && url != null)
    {
        if(prompter != null)
        {
            tabs[title] = url;
            implodeCookie('tabsdata',tabs);
        } else {
            links[title] = url;
            implodeCookie('linksdata',links);
        }
        window.location.reload(false);
    }
}
function initTab()
{
    tabs = explodeCookie('tabsdata');
    links= explodeCookie('linksdata');
    tabs['fishbgdisbg'] = 'fishbgdisbg';
    links['fishbgdisbg'] = 'fishbgdisbg';
    implodeCookie('tabsdata', tabs);
    implodeCookie('linksdata',links);
    var thetabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    var thelink = document.getElementById('p-navigation').getElementsByTagName('ul')[0];
    for(i in tabs)
    {
        if(tabs[i] != null && tabs[i].indexOf('undefined') != 0 && i != 'fishbgdisbg' && i != 'toJSONString')
            addlilink(thetabs,tabs[i],i);
    }
    for(i in links)
    {
        if(links[i] != null && links[i].indexOf('undefined') != 0 && i != 'fishbgdisbg' && i != 'toJSONString')
            addlilink(thelink,links[i],i);
    }
}
function explodeCookie(cookiename)
{
    var cEntry = document.cookie.indexOf(cookiename) + cookiename.length;
    var cEnd   = document.cookie.indexOf(';', cEntry);
    if(cEnd = -1)
         cEnd = document.cookie.length;
    var cActual = unescape(document.cookie.substring(cEntry, cEnd));
    var cReturn = cActual.split('=');
    var cRetorn = cReturn[1].split(';');
    var cRetorn = cRetorn[0].split('$A3');
    var retval = new Array();
    if(cReturn[1].indexOf('$A3') == -1)
    {
        cRetorn = cReturn[1].split('$A4');
        retval[cRetorn[0]] = cRetorn[1];
    } else {        
    for(var i = 0; i < cRetorn.length; i++)
    {
        var cTemp = cRetorn[i];
        var cTemq = cTemp.split('$A4');
        retval[cTemq[0]] = cTemq[1];
    } }
    return retval;
}
function implodeCookie(cookiename, data)
{
    var thecookie = cookiename + '=';
    var i;
    for(i in data)
    {
        if(data[i] != 'undefined' && data[i] != null)    
        thecookie += escape(i) + '$A4' + escape(data[i]) + '$A3';
    }
    thecookie = thecookie.substring(0,thecookie.length-3);
    thecookie += '; expires=Thu, 2 Aug 2201 20:47:11 UTC; path=/;';
    document.cookie = thecookie;
}
function implodeCookieandReturn(cookiename, data)
{
    var thecookie = cookiename + '=';
    var i;
    for(i in data)
    {
        if(data[i] != 'undefined' && data[i] != null)    
        thecookie += escape(i) + '$A4' + escape(data[i]) + '$A3';
    }
    thecookie = thecookie.substring(0,thecookie.length-3);
    thecookie += '; expires=Thu, 2 Aug 2201 20:47:11 UTC; path=/;';
    return thecookie;
}
function addlilink(tabs, url, name, id) {
    var na = document.createElement('a');
    na.href = url;
    na.id = id;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}
function saveTabs()
{
    if(document.title.indexOf("Editing User:"+ wgUserName + "/TabSave") == -1)
        return;
    tabs = implodeCookieandReturn('tabsdata', tabs);
    links = implodeCookieandReturn('linksdata', links);
    textarea = document.getElementById('wpTextbox1');
    textarea.innerHTML = tabs+'$$%A4023!!' + links;
}
function loadTabs()
{
    if(document.title.indexOf("User:"+ wgUserName + "/TabSave") != 0)
        return;
    contentarea = document.getElementById('bodyContent');
    maincontent = contentarea.getElementsByTagName('p')[0].innerHTML;
    var prompter = prompt('Would you like to load saved tabs and links?, OK for Yes, Cancel for No', 'Click OK or Cancel');
    if(prompter == null)
        return;
    var cookies = maincontent.split('$$%A4023!!');
    document.cookie = cookies[0];
    document.cookie = cookies[1];
    window.location.reload(false);
}
//</nowiki></pre>