User:Spang/javascript

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

I've wrote some javascripts. Here are them. Use them if you want by copying the code into your uncyclopedia.js

If you ask me I'll probably help you.

Note: these will probably only work in firefox, and almost definitely not in IE. (They may work in others if you change all occurances of 'DOMContentLoaded' to 'load')

Auto delete[edit | edit source]

For admins only, obviously

Delete pages from the page itself with automatic or custom summaries without using the delete page. The "auto delete" option deletes the page with the standard deletion summary with 1 click. You can add in your own summaries, it's not extremely hard to work out how.

Now available in easy-to-include form! Just add these 3 lines -

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

Or, if you want to change the options and stuff, just go to User:Spang/autodelete.js, copy the content to anywhere in your user javascript, and change whatever you see fit.

Note: If this script doesn't work for you, you can try the one modified by user:Olipro to be more compatible with other browsers. It is at http://uncyclopedia.wikia.com/index.php?title=User:Spang/autodelete_alt.js - replace the above address with this one to use this one instead.

Recent changes highlighting[edit | edit source]

Highlights log actions, new pages, and large content removals/page blankings with pretty colours. In theory if you know what you're doing you could make it highlight anything. Or nothing.

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';
         }
      }
   }
}
YAHOO.util.Event.onDOMReady(recentChangesHighlights);

Highlight short new pages[edit | edit source]

This function highlights all pages under 1500, 1000 bytes and 100 bytes varying degrees of red and pages over 10,000 bytes in yellow (or you can change the levels and the colours if you want) on special:newpages. Good for finding new pages to tag/qvfd/delete, and wikipedia copy/pastes or spam.

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].style.backgroundColor = 'yellow';
         }
         if (sizeBytes < 1500) {
            links[l].style.backgroundColor = '#fdd';
         }
         if (sizeBytes < 1000) {
            links[l].style.backgroundColor = '#fbb';
         }
         if (sizeBytes < 100) {
            links[l].style.backgroundColor = '#f44';
         }
      }
   }
}
YAHOO.util.Event.onDOMReady(recentChangesHighlights);

It shouldn't be too hard to see how to change the colours here.

Mark already-tagged pages on Special:Newpages[edit | edit source]

This script adds a link for you to click on on Special:Newpages which shows you which pages have been already tagged as either {{ICU}} or {{construction}}. Useful when going through tagging stuff so you can ignore stuff which doesn't need tagging before opening the page.

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

Extra tabs[edit | edit source]

Adds tabs to see the latest diff, edit section 0, and search google, wikipedia and uncyc with the page title.

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

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

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

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

};
YAHOO.util.Event.onDOMReady(recentChangesHighlights);

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;
}

Tagging buttons[edit | edit source]

Some neater buttons for 1-click auto-tagging with ICU, etc. You may want to change the default summaries if you know how.

function addEditButtons() {
  if (document.title.indexOf("Editing ") == 0) {
   var toolbarhtml = ' — ';
   toolbarhtml += '<span class="new" style="background-color:#EEE; border: 1px solid gray; padding: 3px; font-family: courier;">';
   toolbarhtml += '<a href="javascript:icu();" title="Add ICU tag">icu</a> — ';
   toolbarhtml += '<a href="javascript:tag(\'{{ICU|~~~~~|sub=short}}\',\'+ICU. Needs more work\');" title="Add ICU (short) tag">icu-s</a> — ';
   toolbarhtml += '<a href="javascript:tag(\'{{deadend}}\',\'+deadend. Please add wikilinks\');" title="Add Dead End tag">dead</a> — ';
   toolbarhtml += '<a href="javascript:tag(\'{{MTUsign|~~~~~}}\',\'+MTU. Please move/expand/delete\');" title="Add Move To Undictionary tag">mtu</a> — ';
   toolbarhtml += '<a href="javascript:tag(\'{{rewrite}}\',\'+rewrite\');" title="Add Rewrite tag">rw</a> — ';
   toolbarhtml += '<a href="javascript:tag(\'{{expansion}}\',\'+expansion. Please expand this into a full article\');" title="Add Expand tag">exp</a> — ';
   toolbarhtml += '<a href="javascript:tag(\'{{ugly}}\',\'+ugly. Please make this more presentable\');" title="Add Ugly tag">ugly</a> — ';
   toolbarhtml += '<a href="javascript:tag(\'{{stub}}\',\'+stub\');" title="Add Stub tag">stub</a>';
   toolbarhtml += '</span>';

   var newToolbarSpan = document.createElement('SPAN');
   var toolbarDiv = document.getElementById('toolbar');
     if (toolbarDiv) {
        toolbarDiv.appendChild(newToolbarSpan);
        newToolbarSpan.innerHTML = toolbarhtml;
     }
  };
};
YAHOO.util.Event.onDOMReady(addEditButtons);

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();
}

Auto watch (inline watch/unwatch)[edit | edit source]

Lets you watch and unwatch a page without leaving that page. There's no confirmation other than the text changing, but it should work as soon as you click watch/unwatch. May even work in all browsers.

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

Delete links on recent changes and newpages[edit | edit source]

Exactly what it says on the tin.

function deleteLinks() {
   if (wgPageName == 'Special:Recentchanges') { 
      var targetContent = document.getElementById('bodyContent');
      var links = targetContent.getElementsByTagName ("li");
      for (var l = 0; l < links.length; l++) {
         var liContent = links[l];
         var liLinks = liContent.getElementsByTagName ('a');
         if (liLinks[0].innerHTML.indexOf('Special:Log = -1')) {
            pageName = liLinks[0].getAttribute('title');
            var liSplit = liContent.innerHTML.split(') . . ');
            liContent.innerHTML = liSplit[0] + ') (<a href="/index.php?title=' + pageName + '&action=delete" title="delete ' + pageName + '">del</a>) . . ' + liSplit[1];
         }
      }
   }
   if (wgPageName == 'Special:Newpages') { 
      var targetContent = document.getElementById('bodyContent');
      var links = targetContent.getElementsByTagName ("li");
      for (var l = 0; l < links.length; l++) {
         var liContent = links[l];
         var liLinks = liContent.getElementsByTagName ('a');
         pageName = liLinks[0].innerHTML;
         var liSplit = liContent.innerHTML.split('[');
         liContent.innerHTML = liSplit[0] + '(<a href="/index.php?title=' + pageName + '&action=delete" title="delete ' + pageName + '">del</a>) [' + liSplit[1]
      }
   }
}
YAHOO.util.Event.onDOMReady(deleteLinks);

Dead end pages history & diff links[edit | edit source]

The Dead end pages list is a good way of finding blanked or vandalised articles. This adds history and diff links to the list, like in recent changes.

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://uncyclopedia.wikia.com/index.php?title=' + pageName + '&action=history">hist</a>) (<a href="http://uncyclopedia.wikia.com/index.php?title=' + pageName + '&diff=cur&last=prev">diff</a>) . . ' + liContent;
      };
   };
}
YAHOO.util.Event.onDOMReady(addDeadEndLinks);

Get template code[edit | edit source]

This function opens the code of any template or other page you select in a new window without having to go to that page and press edit, or subst it and edit again.

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://uncyclopedia.wikia.com/images/0/0f/Button_get_template.png" alt="Get the code of a template"></a>';
  };
}
YAHOO.util.Event.onDOMReady(getTemplate);

function getTemplateOpenPage() {
   var templateName = prompt('Name of page to get?', 'Template:');
      if (templateName == null) return;
   var templatePage = 'http://uncyclopedia.wikia.com/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");
}

Preset deletion summaries (obsolete)[edit | edit source]

This changes the deletion summary box into a combo box with a list of preset deletion summaries to use. Not really needed any more between the autodelete function above and sikon's presets that appear on the page anyway. You can still use it if you like it better that the others though, or want to use your own custom presets you don't want to add to the main list.

function deletionPresets () {
   if (window.location.href.indexOf("&action=delete") != -1) {
    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;
   };
};
addOnloadHook(deletionPresets);

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();
};