User:CBM/simple.js
Appearance
< User:CBM
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:CBM/simple. This user script seems to have an accompanying .css page at User:CBM/simple.css. |
/** CBM
*
* Features:
* Edit count via Interiot
* Add link to edit first section of an article like any other section
* Add "Block log" link to toolbox on any user or user talk page
* Replace "edit this page" tab text with "edit" to make space for tabs
* Bypass ISBN links to go straight to Amazon
* Add an "unwatch" link to each entry in the watchlist
* Sort the watchlist by namespace
*/
importScript('User:CBM/csd.js');
//Interiot's javascript edit counter
if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) {
importScript('User:Interiot/Tool2/code.js'); }
//AzaThoth's twinkle script
//importScript('User:AzaToth/twinkle.js');
importScript('User:AzaToth/morebits.js');
//importScript('User:AzaToth/twinklefluff.js');
importScript('User:AzaToth/twinklewarn.js');
//importScript('User:AzaToth/twinklearv.js');
importScript('User:AzaToth/twinklespeedy.js');
importScript('User:AzaToth/twinklediff.js');
importScript('User:AzaToth/twinkleprotect.js');
importScript('User:AzaToth/twinkleprod.js');
importScript('User:AzaToth/twinklexfd.js');
importScript('User:AzaToth/twinkleimage.js');
importScript('User:AzaToth/twinkleunlink.js');
importScript('User:AzaToth/twinkledelimages.js');
importScript('User:AzaToth/twinkledeprod.js');
importScript('User:AzaToth/twinklebatchdelete.js');
importScript('User:AzaToth/twinklebatchprotect.js');
importScript('User:AzaToth/twinkleimagetraverse.js');
importScript('User:AzaToth/twinklesalt.js');
importScript('User:Ioeth/friendlytag.js');
importScript('User:CBM/tag.js');
// importScript('User:CBM/resolve.js');
importScript('User:CBM/ratemath.js');
importScript('User:Ais523/stubtagtab.js');
importScript('User:CBM/quickpreview.js');
//VoiceOfAlls' script
// Admin tools
//importScript('User:Voice_of_All/Addtabs/monobook.js');
//importScript('User:Voice_of_All/adminnolupin/monobook.js');
TwinkleConfig = {
toolboxButtons: ["tw-prod", "tw-csd", "tw-csd-reason", "tw-rpp", "tw-since", "tw-sincemine","tw-lastdiff"],
userTalkPageMode : 'tab',
openUserTalkPageOnSpeedyDelete : ['g1','g2','g10','g11','g12','a1','a7','u3','t1']
};
/* Enable cleanup tab if appropriate */
addOnloadHook(function() {
addOnloadHook(shortenEdit);
// addOnloadHook(shortenLinks);
addOnloadHook(addTools);
});
/* This will add an [edit] link for the first section
* of all pages except preview pages and the main page
* by User:Pile0nades
*/
// Add an [edit] link to pages
addOnloadHook(function () {
// if this is preview page or generated page, stop
if(
document.getElementById("wikiPreview") ||
document.getElementById("histlegend") ||
document.getElementById("difference") ||
document.getElementById("watchdetails") ||
document.getElementById("ca-viewsource") ||
window.location.href.indexOf("/wiki/Special:") != -1
) {
if(window.location.href.indexOf("&action=edit§ion=0") != -1) {
document.getElementById("wpSummary").value = "/* [[WP:LEAD|Lede]] */ ";
}
return;
};
// get the page title
var pageTitle = wgPageName;
// create div and set innerHTML to link
var divContainer = document.createElement("div");
divContainer.innerHTML = '<div class="editsection">[<a href="/w/index.php?title='+pageTitle+'&action=edit§ion=0" title="Edit section: '+pageTitle+'">edit lede</a>]</div>';
// insert divContainer into the DOM below the h1
if(window.location.href.indexOf("&action=edit") == -1) {
document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
}
});
/* Add link to toolbar for block log */
function addContribs(username) {
addTool("http://en.wikipedia.org/w/index.php?title=Special:Log&type=block&page=" + username, "Block log", "Foo3", "Foo4", "Foo5");
}
function addTools() {
addPersonal("http://en.wikipedia.org/w/index.php?title=Special:Recentchangeslinked&target=User:CBM/Watched_articles&hideminor=0&days=2&limit=100", "Watched articles", "Tools3", "Tools4", "Tools5");
}
addOnloadHook(function() {
if (document.title.indexOf("User:") != -1 )
{
var UNindex = document.title.indexOf("- Wikipedia, the free encyclopedia");
var username = document.title.substring(0,UNindex);
if ( username.indexOf("/") != -1)
{ username = username.substring(0,username.indexOf("/")); }
addOnloadHook(addContribs(username));}
if (document.title.indexOf("User talk:") != -1 )
{
var UNindex = document.title.indexOf("- Wikipedia, the free encyclopedia");
var username = "User:" + document.title.substring(10,UNindex);
if ( username.indexOf("/") != -1)
{ username = username.substring(0,username.indexOf("/")); }
addOnloadHook(addContribs(username));}
});
function shortenLinks() {
var linkno = 0;
var artlinks = document.getElementsByTagName('a');
for(linkno = 0; linkno < artlinks.length; ++linkno) {
alert(artlinks[linkno].href);
if(artlinks[linkno].firstChild) {
alert(artlinks[linkno].firstChild);
artlinks[linkno].replaceChild(document.createTextNode("Long link"),
artlinks[linkno].firstChild);
}
}
}
function shortenEdit() {
var tab = document.getElementById('ca-edit');
if ( typeof(tab) != 'undefined') {
var tab = document.getElementById('ca-edit').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("Edit"), tab.firstChild);
tab = document.getElementById('ca-talk').getElementsByTagName('a')[0];
tab.replaceChild(document.createTextNode("Talk"), tab.firstChild);
}
// var tab = document.getElementById('ca-history');
// if ( typeof(tab) != 'undefined') {
// var tab = document.getElementById('ca-history').getElementsByTagName('a')[0];
// tab.replaceChild(document.createTextNode("hist"), tab.firstChild);
// }
// var tab = document.getElementById('ca-protect');
// if ( typeof(tab) != 'undefined') {
// var tab = document.getElementById('ca-protect').getElementsByTagName('a')[0];
// tab.replaceChild(document.createTextNode("prot"), tab.firstChild);
// }
// var tab = document.getElementById('ca-delete');
// if ( typeof(tab) != 'undefined') {
// var tab = document.getElementById('ca-delete').getElementsByTagName('a')[0];
// tab.replaceChild(document.createTextNode("rm"), tab.firstChild);
// }
// var tab = document.getElementById('ca-move');
// if ( typeof(tab) != 'undefined') {
// var tab = document.getElementById('ca-move').getElementsByTagName('a')[0];
// tab.replaceChild(document.createTextNode("mv"), tab.firstChild);
// }
}
/* Add link to toolbox*/
function addTool(url, name, id, title, key){
var tabs = document.getElementById('p-tb').getElementsByTagName('ul')[0];
return addlilink(tabs, url, name, id, title, key);
}
/* Add Tab */
function addTab(url, name, id, title, key){
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
return addlilink(tabs, url, name, id, title, key);
}
/* Add Personal */
function addPersonal(url, name, id, title, key){
var tabs = document.getElementById('p-personal').getElementsByTagName('ul')[0];
return addlilink(tabs, url, name, id, title, key);
}
/* Add LI to a UL */
function addlilink(tabs, url, name, id, title, key){
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
if(id) li.id = id;
li.appendChild(na);
tabs.appendChild(li);
if(id)
{
if(key && title)
{
ta[id] = [key, title];
}
else if(key)
{
ta[id] = [key, ''];
}
else if(title)
{
ta[id] = ['', title];
}
}
// re-render the title and accesskeys from existing code in wikibits.js
akeytt();
return li;
}
/* Bypass ISBN page to go straight to amazon */
function externISBN() {
for (var i = 0; i < document.links.length; i++)
{
if( document.links[i].href.match(/isbn=(.*)/) ) {
document.links[i].href='http://www.amazon.com/gp/search/ref=sr_adv_b/?search-alias=stripbooks&field-isbn='+RegExp.$1;
}
}
}
addOnloadHook(externISBN);
/* add unwatch links to watchlist */
addOnloadHook(function () {
// Check if we're on the watchlist
if (!wgCanonicalSpecialPageName || wgCanonicalSpecialPageName != "Watchlist")
return;
if (!document.forms[0] || !document.forms[0].namespace) return;
// Unwatch links go back to watchlist with "Removing requested items
// from watchlist..." message
// var query_prefix = "title="+encodeURIComponent(wgPageName)+"&action=submit&remove=1&id[]=";
// ...or...
// Unwatch links go to "Removed from watchlist" page
var query_prefix = "action=unwatch&title=";
// get list of all links in content:
var links = document.getElementById('content').getElementsByTagName('a');
// make a static copy of the nodelist and lose the original for speed
// while we're at it, prune the uninteresting links from the list
var linksCopy = new Array ();
for (var i = 0; i < links.length; i++) {
if (/[?&]action=history([&#]|$)/.test(links[i].href)) linksCopy.push(links[i]);
}
links = linksCopy;
for (var i = 0; i < links.length; i++) {
// create unwatch link and append it after history link
var unwatch = document.createElement('a');
unwatch.href = wgServer + wgScriptPath + "/index.php?" + query_prefix + encodeURIComponent(links[i].title);
unwatch.title = "Unwatch "+links[i].title;
unwatch.appendChild(document.createTextNode("unwatch"));
links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);
// insert a delimiter between the two links
var delim = links[i].previousSibling;
delimText = (delim.nodeType == 3 ? delim.nodeValue : ""); // kluge to handle case where "diff" is unlinked
delim = document.createTextNode(delimText.replace(/^.*diff/, ""));
links[i].parentNode.insertBefore(delim, unwatch);
}
});
//
// WATCHLIST SORTER
// Taken from User:Misza13 and edited by me to work with unwatch links
// Also fixed sorting of namespaces and made the ul's have class=special
function addNamespaceWL(newday, namespace) {
hdr = document.createElement('h5');
hdr.innerHTML = namespace;
newday.appendChild(hdr);
namespacesub = document.createElement('ul');
namespacesub.setAttribute("class", "special");
newday.appendChild(namespacesub);
return hdr;
}
addOnloadHook(function (){
if (location.href.indexOf('Special:Watchlist') == -1) return; //Are we on a watchlist?
//days = document.getElementById('bodyContent').getElementsByTagName('ul');
//Hell knows how it works - found in "Dive into Greasemonkey"
// - from original coder
days = document.evaluate( "//ul[@class='special']", document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (d = 0; d < days.snapshotLength; d++) {
//For each day
day = days.snapshotItem(d);
newday = document.createElement('div'); //This will replace the old listing
//add the main namespaces in order so they are sorted correctly
//additional namespaces will be created at the bottom when they are encountered
//change the order here to whatever you like
addNamespaceWL(newday, "Main");
addNamespaceWL(newday, "Talk");
addNamespaceWL(newday, "Wikipedia talk");
addNamespaceWL(newday, "User talk");
addNamespaceWL(newday, "User");
while ((diffs = day.getElementsByTagName('li')).length > 0) {
//Are there any diffs left?
//Try to extract the namespace
As = diffs[0].getElementsByTagName('a');
// if you don't have the unwatch links, replace As[3] with As[2], etc.
if (As[0].innerHTML == 'diff') {
pagename = As[3].innerHTML;
} else {
pagename = As[2].innerHTML;
}
if (pagename.indexOf(':') == -1)
namespace = 'Main';
else
namespace = pagename.split(':')[0];
//This will fail for articles which contain ":" in name
hdrs = newday.getElementsByTagName('h5'); //Get the list of namespace headers
hdr = null;
for (j=0; j<hdrs.length; j++) //Find the header
if (hdrs[j].innerHTML==namespace) {
hdr = hdrs[j]; break;
}
if (hdr==null) { //Not found? Make a new one!
hdr = addNamespaceWL(newday, namespace);
}
hdr.nextSibling.appendChild(diffs[0]); //Move the diff
}
newday.appendChild(document.createElement('hr')); //For readablility
day.parentNode.replaceChild(newday,day);
}
});
// Edit counter
// Script from [[User:ais523/editcount.js]]
importScript('User:ais523/editcount.js'); //[[User:ais523/editcount.js]]
importScript('User:ais523/watchlistei.js');
//
// Script to footnote text to the tooltips on footnote links
addOnloadHook(function refTooltips() {
var linkElem, linkHref, noteElem;
// Get list of footnote links (they all have class: 'reference')
var refElems = getElementsByClassName(document.body, "SUP", "reference");
for(var i = 0; i < refElems.length; i++)
{
if(linkElem = refElems[i].getElementsByTagName("a")[0])
{
linkHref = linkElem.href;
// Get footnote id from link href and add text content to link tooltip
if(noteElem = document.getElementById(linkHref.substr(linkHref.indexOf("#") + 1)))
linkElem.title = noteElem.innerText || noteElem.textContent || "";
}
}
});
addOnloadHook(function() {
var contentSub = document.getElementById("contentSub");
if(!contentSub) return;
var elem = contentSub.nextSibling;
while(elem.nodeType != 1) elem = elem.nextSibling;
if(elem.className != 'usermessage') return;
elem.getElementsByTagName('A')[1].href = elem.getElementsByTagName('A')[1].href.replace("diff=cur","action=history")
elem.getElementsByTagName('A')[1].textContent = "history";
});
addOnloadHook(function delete_dropdown() {
var list = document.getElementById('wpDeleteReasonList');
if(!list) return;
list.options[0] = new Option("Blank","");
list.selectedIndex = 0;
});