User:Andorin Kato/uncyclopedia.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
//<nowiki>
if (wgUserName != "Thekillerfroggy")
{
    // [[Wikipedia:Wikipedia:WikiProject_User_scripts/Scripts/Six_tabs]]
    document.write('<script type="text/javascript" src="' +
                   'http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_User_scripts/Scripts/Six_tabs' +
                   '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
}

var disableDeletionReasons = true;
var disableUsernameReplace = true;
var enableOldForumEdit = true;

document.write('<script type="text/javascript" src="'
  + 'http://en.uncyclopedia.co/w/index.php?title=User:Spang/autodelete.js' 
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

document.write('<script type="text/javascript" src="'
  + 'http://en.uncyclopedia.co/w/index.php?title=User:Spang/autowatch.js' 
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

document.write('<script type="text/javascript" src="'
  + 'http://en.uncyclopedia.co/w/index.php?title=User:Spang/searchbox.js' 
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

document.write('<script type="text/javascript" src="'
  + 'http://en.uncyclopedia.co/w/index.php?title=User:Spang/quickedit.js' 
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

document.write('<script type="text/javascript" src="'
  + 'http://en.uncyclopedia.co/w/index.php?title=User:Mitch_1_2/TaggedNewPages.js' 
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

function main() {
    setEditForm();
    var newbox = initNewBox();
    addLinks(newbox);
    srInit();
    addEditButtons();
    extraTabs();
    addRevert();
    addDeadEndLinks();
    highlightShortNewpages();
    deletionPresets();
    recentChangesHighlights();
    addbotcontrib();
};

document.addEventListener('DOMContentLoaded', main, false);

function highlightShortNewpages () {
   if (wgPageName == 'Special:Newpages') { 
      var targetContent = document.getElementById('bodyContent');
      var links = targetContent.getElementsByTagName ("li");
      for (var l = 0; l < links.length; l++) {
         liContent = links[l].textContent;
         sizeText = liContent.substring(liContent.indexOf('[')+1,liContent.indexOf('bytes]'));
         sizeBytes = sizeText.replace(',', '');
         if (sizeBytes > 10000) {
            links[l].className = 'new-long';
         }
         if (sizeBytes < 1500) {
            links[l].className = 'new-shortish';
         }
         if (sizeBytes < 1000) {
            links[l].className = 'new-short';
         }
         if (sizeBytes < 100) {
            links[l].className = 'new-shortest';
         }
      }
   }
}

function recentChangesHighlights() {
   if (wgPageName == 'Special:RecentChanges') { 
      var targetContent = document.getElementById('bodyContent');
      var rows = targetContent.getElementsByTagName ("li");
      for (var l = 0; l < rows.length; l++) {
         liHTML = rows[l].innerHTML
         liText = rows[l].textContent;
         if (liHTML.indexOf('/wiki/Special:Log/') != -1) {
            rows[l].style.backgroundColor = '#DDF';
         }
         if (liHTML.indexOf('/wiki/Special:Log/block') != -1 || liHTML.indexOf('/wiki/Special:Log/delete') != -1) {
            rows[l].style.backgroundColor = '#FEE';
         }
         if (liHTML.indexOf('class="newpage"') != -1) {
            rows[l].style.backgroundColor = '#DFD';
         }
         if (liText.indexOf('Blanked the page') != -1 || liHTML.indexOf('<strong class="mw-plusminus-neg">') != -1) {
            rows[l].style.backgroundColor = '#FAA';
         }
      }
   }
}

function addDeadEndLinks () {
   if (wgPageName == 'Special:Deadendpages') {
      var targetContent = document.getElementById('bodyContent');
      var links = targetContent.getElementsByTagName ("li");
      for (var l = 0; l < links.length; l++) {
       liContent = links[l].innerHTML;
       pageName = liContent.substring(liContent.indexOf('/wiki/')+6,liContent.indexOf('title=')-2);
       links[l].innerHTML = '(<span class="plainlinks"><a href="http://en.uncyclopedia.co/w/index.php?title=' + pageName + '&action=history">hist</a>) (<a href="http://en.uncyclopedia.co/w/index.php?title=' + pageName + '&diff=cur&last=prev">diff</a>) . . ' + liContent;
      };
   };
}

function deletionPresets () {
   if (window.location.href.indexOf("&action=delete") != -1 && window.location.href.indexOf("&setdelconfirm=wpConfirmB") == -1 ) {
    if (!document.getElementById('deleteconfirm')) return;
    var targetContent = document.getElementById('deleteconfirm');
    var insertSummary = targetContent.getElementsByTagName('td')[1];
    var combohtml = ' ';
    combohtml += '<select id="summaries" style="height: 1.5em; padding: 0; margin: 0; position: relative; right: 5px; vertical-align: baseline; z-index: 0; max-width: 21px;"  onChange="javascript:changeDelSummary();">';
    combohtml += '<option value="" selected="selected">None</option>';
    combohtml += '<option value="Fails QA. Read [[BGBU|The beginner\'s guide]] and [[UN:HTBFANJS]]">Sucks</option>';
    combohtml += '<option value="Vanity/nnp. [[UN:CM|Codeine\'s mum]] has never heard of you. Read [[UN:VAIN]]">Vanity</option>';
    combohtml += '<option value="[[NRV]] expired">NRV expired</option>';
    combohtml += '<option value="Duplicate of ">Duplicate</option>';
    combohtml += '<option value="Construction/WIP expired">Construction expired</option>';
    combohtml += '<option value="Orphan talk page">Orphan talk page</option>';
    combohtml += '<option value="Entirely factual. Read [[UN:HTBFANJS]]">Factual</option>';
    combohtml += '<option value="Qua?">Qua?</option>';
    combohtml += '<option value="Spam">Spam</option>';
    combohtml += '<option value="Requested by creator">Requested</option>';
    combohtml += '<option value="Blanked by author">Blanked by author</option>';
    combohtml += '</select>';
    insertSummary.innerHTML += combohtml;
   };
};

function changeDelSummary(){
   var targetContent = document.getElementById('deleteconfirm');
   var inputBoxTD = targetContent.getElementsByTagName('td')[1];
   var box = inputBoxTD.getElementsByTagName('input')[0];
   inputBoxTD.removeChild(box);
   var boxhtml = '';
   boxhtml += '<input type="text" size="60" name="wpReason" id="wpReason" value="';
   boxhtml += document.getElementById('summaries').value;
   boxhtml += '" />';
   inputBoxTD.innerHTML = boxhtml + inputBoxTD.innerHTML;
   targetContent.wpConfirmB.focus();
};

function initNewBox() {
    var sidebar = document.getElementById('column-one');
    var outer = document.createElement('div');
    var heading = document.createElement('h5');
    var newbox = document.createElement('div');
    var list = document.createElement('ul');

    outer.setAttribute('class', 'portlet');
    newbox.setAttribute('class', 'pBody');
    list.id = 'linkbox';

    heading.textContent = 'linkbox';
    outer.appendChild(heading);
    outer.appendChild(newbox);
    newbox.appendChild(list);
    sidebar.appendChild(outer);

    return list;
}
function addLinks(newbox) {
    addToolboxLink('VFH', '/wiki/Uncyclopedia:VFH/summary', newbox);
    addToolboxLink('FQ', '/wiki/Uncyclopedia:VFH/queue', newbox);
    addToolboxLink('VFP', '/wiki/Uncyclopedia:VFP', newbox);
    addToolboxLink('New pages', '/wiki/Special:Newpages', newbox);
    addToolboxLink('Maintenance', '/wiki/Uncyclopedia:Maintenance', newbox);
    addToolboxLink('VFD', '/wiki/Uncyclopedia:Votes for deletion', newbox);
    addToolboxLink('QVFD', '/wiki/Uncyclopedia:QuickVFD', newbox);
    addToolboxLink('Ban Patrol', '/wiki/Uncyclopedia:Ban Patrol', newbox);
    addToolboxLink('JavaScript Edit', '/index.php?title=User:' + wgUserName + '/uncyclopedia.js&action=edit', newbox); // I'm a dirty js-stealing whore
    addToolboxLink('CSS Edit', '/index.php?title=User:' + wgUserName + '/uncyclopedia.css&action=edit', newbox); // I'm a dirty js-stealing whore
}

function addToolboxLink(text, url, parent) {
    var newLink = document.createElement("li");

    newLink.innerHTML = '<a href="' + url + '">' + text + '</a>';
    parent.appendChild(newLink);

    return newLink;
};

function extraTabs() {
// Only work on pages with an edit link
   if (!document.getElementById('ca-edit')) return;

// Latest diff
      addTab('diff', 'http://en.uncyclopedia.co/w/index.php?title=' + escape(wgPageName) + '&diff=cur&last=prev', 'tab-diff');

// Edit section 0
      addTab('edit 0', 'http://en.uncyclopedia.co/w/index.php?title=' + escape(wgPageName) + '&action=edit&section=0', 'tab-edit-0');

// Purge
      addTab('purge', 'http://en.uncyclopedia.co/w/index.php?title=' + escape(wgPageName) + '&action=purge', 'tab-purge');


// Search tabs - google, wp, uncyc
      addTab('g', 'http://www.google.com/search?hl=en&lr=&safe=off&q=' + escape(wgPageName).replace(/_/g,'+'), 'tab-search-google');
      addTab('wp', 'http://www.google.com/search?q=site:wikipedia.org&q=' + escape(wgPageName).replace(/_/g,'+'), 'tab-search-wikipedia');
      addTab('un', 'http://en.uncyclopedia.co/wiki/Special:Search?search=' + escape(wgPageName).replace(/_/g,'+') + '&fulltext=Search', 'tab-search-uncyc');
};

function addTab(text, url, id) {
    var tabs = document.getElementById('ca-edit').parentNode;
    if (!tabs) return false;
    var newTab = document.createElement("li");

    newTab.innerHTML = '<a " href="' + url + '">' + text + '</a>';
    tabs.appendChild(newTab);
    newTab.id = id;

    return newTab;
}

function addbotcontrib() {
    if(!document.getElementById) return;
    if(document.title.indexOf("User contributions - ") != 0) return;
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(document.location.href.indexOf('?') == -1) {
      var linky = document.location.href + '?bot=1';
    } else {
      var linky = document.location.href + '&bot=1';
    }
    addlilink(tabs, linky, 'bot rollback', 'ca-botcontribs'); 
}


function tag(text, summary) { 
    document.editform.wpSummary.value = summary;
    document.editform.wpMinoredit.checked = true;
    document.editform.wpWatchthis.checked = false;
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += text;
    document.editform.wpSave.click();
}

function icu() {
    var fix = prompt('Enter fix message, or leave blank');
       if (fix == null) return;
    var sub = prompt('Enter sub template name, or leave blank\nOptions: format, short, notfunny, random, encyclopedic, list, and original');
       if (sub == null) return;
    document.editform.wpSummary.value = '+ICU. This article needs some help, stat!';
    document.editform.wpMinoredit.checked = true;
    document.editform.wpWatchthis.checked = false;
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{ICU|~~~~~|fix=' + fix + '|sub=' + sub + '}}';
    document.editform.wpSave.focus();
}

function getTemplate() {
  if (document.getElementById('toolbar')) {
   var toolbarDiv = document.getElementById('toolbar');
   var getTemplateButton = document.createElement('A');
   toolbarDiv.appendChild(getTemplateButton);
   getTemplateButton.innerHTML = '<a href="javascript:getTemplateOpenPage();"><img src="http://en.uncyclopedia.co/images/0/0f/Button_get_template.png" alt="Get the code of a template"></a>';
  };
}

function getTemplateOpenPage() {
   var templateName = prompt('Name of page to get?', 'Template:');
      if (templateName == null) return;
   var templatePage = 'http://en.uncyclopedia.co/w/index.php?title=' + templateName + '&action=raw&ctype=text/javascript&dontcountme=s';
   window.open(templatePage,"templateWindow","toolbar=no, scrollbars=yes, resizable=yes, width=700, height= 350");
}

function setEditForm() {
    var editform = document.getElementById("editform");
    if (!editform) return;
    
    var summaryText = queryString('setsummary');
    if (summaryText) {
        var summary = document.getElementsByName("wpSummary")[0];
        if (summary) summary.value = summaryText;
    }
    
    var setMinor = queryString('setminor');
    if (setMinor) {
    var minor = document.getElementById("wpMinoredit");
    if (minor) minor.checked = (setMinor == '1');
    }
    
    var setWatch = queryString('setwatch');
    if (setWatch) {
        var watch = document.getElementById("wpWatchthis");
        if (watch) watch.checked = (setWatch == '1');
    }
    
    var setSubmit = queryString('setsubmit');
    if (setSubmit) {
        var btn = document.getElementById(setSubmit);
        
        if (document.getElementById("editform") && btn) {
            btn.textContent += " (auto clicking...)";
            btn.click();
        }
    }
};

function addRevert() {
    if(!queryString("diff")) return;
 
    var xp_link = document.evaluate("//a[starts-with(., 'Revision')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    if (!xp_link) return;
 
    var link = xp_link.singleNodeValue;
    
    var xp_name1 = document.evaluate("/descendant::a[.='Talk'][1]/preceding-sibling::a", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    if (!xp_name1) return;
    
    var xp_name2 = document.evaluate("/descendant::a[.='Talk'][2]/preceding-sibling::a", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    if (!xp_name2) return;
    
    var name1 = xp_name1.singleNodeValue;
    var name2 = xp_name2.singleNodeValue;

    var linkSpan = document.createElement("span");
    var revertLink = document.createElement("a");
    var summaryText = "Reverted edit(s) of [[Special:Contributions/" + name2.textContent + "|" + name2.textContent + "]] to previous one by " + name1.textContent

    linkSpan.innerHTML = "&nbsp;&nbsp;";

    revertLink.innerHTML = "[Auto-Revert]";
    revertLink.href = link.href + "&action=edit&setsubmit=wpSave&setsummary=" + summaryText + "&setwatch=0";

    insertAfter(link.parentNode, linkSpan, link);
    insertAfter(link.parentNode, revertLink, linkSpan);
};

function insertAfter(parent, node, referenceNode) {
    if(referenceNode.nextSibling) {
        return parent.insertBefore(node, referenceNode.nextSibling);
    } else {
        return parent.appendChild(node);
    }
};

function queryString(p) {
        var re = RegExp('[&?]' + p + '=([^&]*)');
        var matches;

        if (matches = re.exec(document.location)) {
            try { 
                return decodeURI(matches[1]);
            } catch (e) {
        }
    }
  
    return null;
};

// function to add buttons/tabs/links

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 addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
    if(!(speedTip=="Bold text")) return;
    addButtonReally('/skins/common/images/button_bold.png','Bold text','\'\'\'','\'\'\'','Bold text');
    addButtonReally('/skins/common/images/button_italic.png','Italic text','\'\'','\'\'','Italic text');
    addButtonReally('/skins/common/images/button_link.png','Internal link','[[',']]','Link title');
    addButtonReally('/skins/common/images/button_extlink.png','External link (remember http://     prefix)','[',']','http://www.example.com link title');
    addButtonReally('/skins/common/images/button_headline.png','Level 2 headline','\n== ',' ==\n','Headline text');
    addButtonReally('/skins/common/images/button_image.png','Embedded image','[[Image:',']]','Example.jpg');
    addButtonReally('/skins/common/images/button_nowiki.png','Ignore wiki formatting','\<nowiki\>','\</nowiki\>','');
    addButtonReally('http://images.wikia.com/uncyclopedia/images/2/23/Button_code.png','Code formatting','\<code\>','\</code\>','');
    getTemplate();
    addButtonReally('/skins/common/images/button_sig.png','Your signature with timestamp','--~~~~','','');
}

// this is the sub-called function that the other addButton() calls

function addButtonReally(imageFile, speedTip, tagOpen, tagClose, sampleText) {
    speedTip=escapeQuotes(speedTip);
    tagOpen=escapeQuotes(tagOpen);
    tagClose=escapeQuotes(tagClose);
    sampleText=escapeQuotes(sampleText);
    var mouseOver="";

    if(!document.selection && !is_gecko) {
        // filter backslashes so it can be shown in the infobox
        var re=new RegExp("\\\\n","g");
        tagOpen=tagOpen.replace(re,"");
        tagClose=tagClose.replace(re,"");
        mouseOver = "onmouseover=\"if(!noOverwrite){document.infoform.infobox.value='"+tagOpen+sampleText+tagClose+"'};\"";
    }

        document.write("<a href=\"javascript:insertTags");
        document.write("('"+tagOpen+"','"+tagClose+"','"+sampleText+"');\">");

        document.write("<img width=\"23\" height=\"22\" src=\""+imageFile+"\" border=\"0\" alt=\""+speedTip+"\" title=\""+speedTip+"\""+mouseOver+" />");
        document.write("</a>");
        return;
}

// For faster loading of addOnloadHook
function addOnloadHook(hookFunct) {
   document.addEventListener('DOMContentLoaded', hookFunct, false);
}

function mwWikiaUploadButton(namespace, tooltip) { /* die */ }
//</nowiki>


if (wgNamespaceNumber != -1) addOnloadHook(function() { addPortletLink('p-cactions','/wiki/Special:Prefixindex/' + wgPageName + '/','subpages','ca-subpages'); });

// To disable Flash on all pages, submit this form.
// To auto-enable Flash on all pages, change the below value to true.
var displayFlashOverride = true;


//becoming a cyborg
document.write('<script type="text/javascript" src="'
 + 'http://en.uncyclopedia.co/w/index.php?title=User:SckrTrckrBot/uncyclopedia.js'
 + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');