User:Wadewitz/monobook.js
// User:Henrik/sandbox/google-search (please include this line)
function install_search()
{
document.getElementById('searchBody').innerHTML='
'
}
addOnloadHook(install_search);
function winc(s) {
s = s.replace(/^\[\[/, ).replace(/\]\]$/, );
document.write('');
}
// User:Outriggr/metadatatest.js
importScript('User:Outriggr/metadatatest.js');
assessmentMyTemplateCode = ["{{TemplateName|class=|importance=}}"];
assessmentWPBiography = "TemplateA";
assessmentMarkAsMinor = false;
assessmentOverrideWatchPref = true;
//
// install User:Cacycle/wikEd in-browser text editor
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript');
// skip talk page on categories when assessing - time saver
function catSwapButton() {
if(document.title.indexOf('Category:' == 0)) {
mw.util.addPortletLink('p-cactions','javascript:catSwap();','De-Talkify','ca-catswap','change category links from talk pages to article pages');
}
}
addOnloadHook(catSwapButton)
function catSwap() {
var cat = document.getElementById('mw-pages');
cat.innerHTML = cat.innerHTML.replace(/Talk\:/g,'').replace(/[_\s]talk\:/g,':');
}
function externISBN() {
var magicURL = "http://www.amazon.com/exec/obidos/ASIN/MAGICNUMBER/wikipedia08-20";
var magicRegex = /MAGICNUMBER/ig;
if(wgPageName != "Special:Booksources" && wgPageName != "Wikipedia:Book_sources"){
for (var i = 0; i < document.links.length; i++)
{
if( document.links[i].href.match(/isbn=(.*)/) ) {
document.links[i].href=magicURL.replace(magicRegex, RegExp.$1);
}
}
}
}
addOnloadHook(externISBN);
addOnloadHook(function () {
var x;
if (!(x = document.getElementById('ca-edit') )) return;
var url;
if (!(url = x.getElementsByTagName('a')[0] )) return;
if (!(url = url.href )) return;
var y = mw.util.addPortletLink('p-cactions', url+"§ion=0", '0', 'ca-edit-0',
'Edit the lead section of this page', '0', x.nextSibling);
y.className = x.className; // steal classes from the the edit tab...
x.className = 'istalk'; // ...and make the edit tab have no right margin
// exception: don't steal the "selected" class unless actually editing section 0:
if (/(^| )selected( |$)/.test(y.className)) {
if (!document.editform || !document.editform.wpSection
|| document.editform.wpSection.value != "0") {
y.className = y.className.replace(/(^| )selected( |$)/g, "$1");
x.className += ' selected';
}
}
//
});
addOnloadHook(function () {
var tabs = document.getElementById('p-cactions').cloneNode(true);
tabs.id = 'mytabs';
var listitems = tabs.getElementsByTagName('LI');
for (i=0;i if(listitems[i].id) listitems[i].id = 'mytabs-' + listitems[i].id; } content = document.getElementById("content"); // Find the content div content.parentNode.insertBefore(tabs, content.nextSibling); // Place tab list right after content div }); // User:Dschwen/highlightredirects.js - please include this line mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Dschwen/highlightredirects.js' + '&action=raw&ctype=text/javascript'); // Stub tag tab. By User:ais523, on a request by User:thesublime514. // (User:ais523/stubtagtab.js) // addOnloadHook(function(){ if(wgNamespaceNumber==0&&wgAction=="view") { if(document.getElementById("ca-edit")) mw.util.addPortletLink('p-cactions', 'javascript:stubtagtab()', 'stub', 'ca-stubtag', 'Add a stub tag to this page', ''); } if(location.href.indexOf("&autoaddstubtag=")!=-1&&document.getElementById('wpTextbox1')!=null) { var x=decodeURIComponent(location.href.split("&autoaddstubtag=")[1]); if(x=="") x="stub"; else x+="-stub"; document.getElementById('wpTextbox1').value+="\n{"+"{"+x+"}}"; //add to the end of the article document.getElementById('wpSummary').value= "Tagging with {"+"{"+x+"}} using user scripts"; document.getElementById('wpPreview').click(); } }); function stubtagtab() { var x=prompt("Which stub tag? (Leave blank for {"+ "{stub}}; otherwise -stub will be added to the name)"); if(x==null) return; location.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+ "&action=edit&autoaddstubtag="+encodeURIComponent(x); } //
//This function adds a link to the toolbox which, when clicked, searches the talk page history
//to find events which might be relevant to the {{ArticleHistory}} template. See the talk page for more details.
//
//To use this function add {{subst:js|User:Dr pda/articlehistory.js}} to your monobook.js
//
function loadXMLDoc(url,handler,id)
{
url=url+id;
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();
}
// branch for IE/Windows ActiveX version
else if (window.ActiveXObject) {
var req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
req.onreadystatechange = function () {handler(req,id)};
req.open("GET", url, true);
req.send("");
}
}
function getArticleOldid(req,id) {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
var response = req.responseXML.documentElement;
var rv = response.getElementsByTagName('rv');
var spannode = document.getElementById('oldid-'+id);
spannode.innerHTML = rv[0].getAttribute('revid');
var linode = document.getElementById(id);
linode.onclick='';
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
}
}
}
function getArticleOldidManual(req,id) {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
var response = req.responseXML.documentElement;
var rv = response.getElementsByTagName('rv');
var spannode = document.getElementById('oldid-'+id);
var timestamp = rv[0].getAttribute('timestamp');
timestamp = timestamp.replace(/Z/g,'');
var prettytimestamp = timestamp.replace(/T/,', ');
timestamp = timestamp.replace(/[-T:]/g,'');
var idtime = id.substr(0,4)+'-'+id.substr(4,2)+'-'+id.substr(6,2)+', '+id.substr(8,2)+':'+id.substr(10,2)+':'+id.substr(12,2);
var revid = rv[0].getAttribute('revid');
spannode.innerHTML = 'The last version before '+idtime+' was at '+prettytimestamp+', with an oldid of '+revid+'. Click on the links to jump to the article history or talk page history at this point.';
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
}
}
}
function getHistoryMilestones(req) {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
var response = req.responseXML.documentElement;
var revList = response.getElementsByTagName('rv');
var prettylastcomment = '';
var lasttimestamp = '';
var prettylasttimestamp = '';
if(revList.length > 0){
for(var i=0; i var comment = revList[i].getAttribute('comment'); //strip out headers i.e. /*...*/ prettycomment=comment.replace(/\/\*.*\*\//,''); comment=prettycomment.toLowerCase(); var timestamp = revList[i].getAttribute('timestamp'); timestamp = timestamp.replace(/Z/g,''); var prettytimestamp = timestamp.replace(/T/,', '); timestamp = timestamp.replace(/[-T:]/g,''); var output = document.getElementById("article-milestones"); if(comment.match('{{') || comment.match('featured') || comment.match('fac.?failed') || comment.match('review')|| comment.match(/\bfa\b/) || comment.match(/\bfac\b/) || comment.match(/\bga\b/) || comment.match(/\bgac\b/) || comment.match(/\bgafailed\b/) || comment.match(/\bga.?nominee\b/)|| comment.match('good article') || comment.match(/\bfar\b/) || comment.match(/\bfarc\b/) || comment.match(/\bfl\b/) || comment.match(/\bflrc\b/) || comment.match(/main.?page/) || comment.match('dyk') ){ var milestone = document.createElement("li"); spanid='oldid-'+timestamp; milestone.innerHTML=''+prettytimestamp+' '+prettycomment+' (oldid)'; milestone.id=timestamp; milestone.onclick=getArticleOldidWrapper; output.appendChild(milestone); } prettylastcomment = prettycomment; lasttimestamp = timestamp; prettylasttimestamp = prettytimestamp; } var getmore = document.getElementById("getmore"); getmore.innerHTML='(last entry read: '+prettylasttimestamp+' '+prettylastcomment+')'; //Get more milestones, if any (if not, the program won't get here again) loadXMLDoc(talkQueryURL,getHistoryMilestones,'&rvend='+(parseInt(lasttimestamp)-1)) } } else { alert("There was a problem retrieving the XML data:\n" + req.statusText); } } } function getArticleOldidWrapper(event) { loadXMLDoc(articleQueryURL,getArticleOldid,this.id) } function manualDate(event) { var mydate=prompt("Enter the date for which you want the oldid","") if (mydate!=null && mydate!=""){ var utc = Date.parse(mydate+' UTC'); var d = new Date(); d.setTime(utc); if((d.getUTCHours()+d.getUTCMinutes()) == 0){ d.setUTCHours(23); d.setUTCMinutes(59); d.setUTCSeconds(59); } var timestamp =''; timestamp += d.getUTCFullYear(); timestamp += (d.getUTCMonth()<10) ? '0'+(d.getUTCMonth()+1) : (d.getUTCMonth()+1); timestamp += (d.getUTCDate()<10) ? '0'+ d.getUTCDate() : d.getUTCDate(); timestamp += (d.getUTCHours()<10) ? '0'+ d.getUTCHours() : d.getUTCHours(); timestamp += (d.getUTCMinutes()<10) ? '0'+ d.getUTCMinutes() : d.getUTCMinutes(); timestamp += (d.getUTCSeconds()<10) ? '0'+ d.getUTCSeconds() : d.getUTCSeconds(); var dateoldid = document.createElement("p"); dateoldid.id = 'oldid-'+timestamp; output.parentNode.insertBefore(dateoldid,enterdate.nextSibling); loadXMLDoc(articleQueryURL,getArticleOldidManual,timestamp) } } //Javascript URL encode function from http://cass-hacks.com/articles/code/js_url_encode_decode/ //(CC-BY-NC 2.5 Licence) function URLEncode (clearString) { var output = ''; var x = 0; clearString = clearString.toString(); var regex = /(^[a-zA-Z0-9_.]*)/; while (x < clearString.length) { var match = regex.exec(clearString.substr(x)); if (match != null && match.length > 1 && match[1] != '') { output += match[1]; x += match[1].length; } else { if (clearString[x] == ' ') output += '+'; else { var charCode = clearString.charCodeAt(x); var hexVal = charCode.toString(16); output += '%' + hexVal.toUpperCase(); } x++; } } return output; } function getArticleHistory(){ output = document.createElement("ul"); output.id = "article-milestones"; var dummy = document.getElementById("siteSub"); dummy.parentNode.insertBefore(output, dummy.nextSibling); var getmore = document.createElement("p"); getmore.id = 'getmore'; output.parentNode.insertBefore(getmore,output.nextSibling); enterdate = document.createElement("p"); enterdate.id = 'enterdate'; enterdate.innerHTML='Click here to enter a date manually'; enterdate.onclick = manualDate; output.parentNode.insertBefore(enterdate,getmore.nextSibling); var pageName = wgPageName; articleName = (wgNamespaceNumber == 1) ? pageName.substr(5) : pageName; //Handle encoded characters, i.e. \x26 in wgPageName = %26 in URL articleName = URLEncode(articleName); talkName = 'Talk:'+articleName; //correctly handle article name when on a Talk page archive var archiveIndex = articleName.toLowerCase().indexOf("/archive"); articleName = (archiveIndex == -1) ? articleName : articleName.substring(0,archiveIndex); //Use query.php instead of api.php since it has a limit of 200 instead of 50 //var apiHistoryQuery = '/w/api.php?action=query&prop=revisions&titles='+talkName+'&rvlimit=50&rvprop=timestamp|comment&format=xml'; talkQueryURL = '/w/query.php?what=revisions&titles='+talkName+'&rvlimit=200&rvcomments&format=xml'; articleQueryURL = '/w/query.php?what=revisions&titles='+articleName+'&rvlimit=200&rvcomments&format=xml&rvend='; loadXMLDoc(talkQueryURL,getHistoryMilestones,''); } addOnloadHook(function () { if(!document.forms.editform){ mw.util.addPortletLink('p-tb', 'javascript:getArticleHistory()', 'Article history', 't-article-history', 'Search Talk page history for events relevant to ArticleHistory template', , ); } }); // //
// Strip document hyperlinks (esp. wikilinks), leaving only their text; useful for FireVox screen reader
// Also fix bug 11555 (order of section title and edit link) and double caption
function stripHyperlinks() {
var alert_string = "";
var on_main_page = false;
var eliminate_edit_section_links = true;
var delete_line_breaks_in_mp_topbanner = false;
var strip_hyperlinks = true; // turn off to control stripping in some sections
var within_closing_section = false; // determine when we near the end of the article
var force_hyperlink_deletion = false;
var temp_hyperlink;
var temp_hyperlink_text;
var temp_anchor_name;
var hyperlinks;
var num_hyperlinks = 0;
var hyperlink_index = 0;
var hyperlink_counter = 0;
var num_hyperlinks_removed = 0;
var num_redlinks = 0;
var redlink_index = 0;
var num_redlinks_removed = 0;
var redlink_names = new Array();
var parent_node;
var element_node;
var replacement_node;
var grandparent_node;
var next_sibling_node;
var prev_sibling_node;
var greatgrandparent_node;
var greatgreatgrandparent_node;
var prev_element_node;
var child_node;
var num_child_nodes = 0;
var child_node_index = 0;
var headers;
var temp_header;
var num_headers = 0;
var header_index = 0;
var mw_headline_node;
var editsection_node;
var num_header_swaps = 0;
var total_num_header_swaps = 0;
var num_header_tag_strings = 0;
var header_tag_string_index = 0;
var header_tag_strings = [ "H2", "H3", "H4", "H5" ];
var temp_image;
var num_images = 0;
var num_pixels = 0;
var alt_string = "";
var src_string = "";
var image_index = 0;
var image_counter = 0;
var num_significant_images = 0;
var num_uncaptioned_images = 0;
var temp_list;
var list_index = 0;
var max_list_index = 0;
var num_list_mergers = 0;
var ordered_lists;
var num_ordered_lists = 0;
var unordered_lists;
var num_unordered_lists = 0;
var discursive_lists;
var num_discursive_lists = 0;
// Check whether we're on the Main Page
on_main_page = false;
if (document.getElementById("mp-topbanner")) {
on_main_page = true;
// window.alert("We're reading the Main Page.");
// Try to remove two annoying linebeaks, per Graham87
if (delete_line_breaks_in_mp_topbanner == true) {
next_sibling_node = document.getElementById('articlecount');
element_node = next_sibling_node.previousSibling;
prev_sibling_node = element_node.previousSibling;
parent_node = next_sibling_code.parentNode;
//There no document subtree, just the text in two subsequent DIV's
child_node = document.createTextNode(element_node.innerHTML);
prev_sibling_node.appendChild(child_node);
child_node = document.createTextNode(next_sibling_node.innerHTML);
prev_sibling_node.appendChild(child_node);
parent_node.removeChild(element_node);
parent_node.removeChild(next_sibling_node);
}
} // closes check whether we're on the Main Page
// Merge adjacent lists of the same type
num_list_mergers = 0;
diagnostic_string = "";
unordered_lists = document.getElementById("bodyContent").getElementsByTagName("UL");
num_unordered_lists = unordered_lists.length;
max_list_index = num_unordered_lists - 1;
diagnostic_string += "There are " + num_unordered_lists + " unordered lists in this document.\n\n";
for (list_index=max_list_index; list_index>=0; list_index--) { // merge upwards
temp_list = unordered_lists[list_index];
prev_element_node = temp_list.previousSibling;
while ((prev_element_node) && (prev_element_node.nodeType != 1)) { // look for previous Element node
if (prev_element_node.nodeType == 3) {
text_length = prev_element_node.data.replace(/\s/ig, "").length;
if (text_length > 0 ) { break; } // break off loop if a non-empty text area is encountered
}
prev_element_node = prev_element_node.previousSibling;
} // closes search for the previous sibling Element node
if (!prev_element_node) { continue; }
diagnostic_string += "Previous element of UL " + list_index + " is of type " + prev_element_node.nodeType + " and tagName " + prev_element_node.nodeName + ".\n";
// if (prev_element_node.nodeType == 3) { diagnostic_string += " text = " + prev_element_node.data.replace(/\s/ig, "") + " length = " + prev_element_node.data.replace(/\s/ig, "").length + "\n"; }
if (prev_element_node.nodeName == "UL") {
parent_node = temp_list.parentNode;
num_child_nodes = temp_list.childNodes.length;
for (child_node_index = 0; child_node_index < num_child_nodes; child_node_index++) {
child_node = temp_list.childNodes[0];
prev_element_node.appendChild(child_node);
}
prev_element_node.normalize();
parent_node.removeChild(temp_list);
parent_node.normalize();
num_list_mergers++;
diagnostic_string += "Merged unordered list " + list_index + " upwards.\n";
} // closes check for adjacent unordered list
} // closes loop over unordered lists
// window.alert(diagnostic_string);
// Merge ordered lists
diagnostic_string = "";
ordered_lists = document.getElementById("bodyContent").getElementsByTagName("OL");
num_ordered_lists = ordered_lists.length;
max_list_index = num_ordered_lists - 1;
diagnostic_string += "There are " + num_ordered_lists + " ordered lists in this document.\n\n";
for (list_index=max_list_index; list_index>=0; list_index--) { // merge upwards
temp_list = ordered_lists[list_index];
prev_element_node = temp_list.previousSibling;
while ((prev_element_node) && (prev_element_node.nodeType != 1)) { // look for previous Element node
if (prev_element_node.nodeType == 3) {
text_length = prev_element_node.data.replace(/\s/ig, "").length;
if (text_length > 0 ) { break; } // break off loop if a non-empty text area is encountered
}
prev_element_node = prev_element_node.previousSibling;
} // closes search for the previous sibling Element node
if (!prev_element_node) { continue; }
diagnostic_string += "Previous element of OL " + list_index + " is of type " + prev_element_node.nodeType + " and tagName " + prev_element_node.nodeName + ".\n";
// if (prev_element_node.nodeType == 3) { diagnostic_string += " text = " + prev_element_node.data.replace(/\s/ig, "") + " length = " + prev_element_node.data.replace(/\s/ig, "").length + "\n"; }
if (prev_element_node.nodeName == "OL") {
parent_node = temp_list.parentNode;
num_child_nodes = temp_list.childNodes.length;
for (child_node_index = 0; child_node_index < num_child_nodes; child_node_index++) {
child_node = temp_list.childNodes[0];
prev_element_node.appendChild(child_node);
}
prev_element_node.normalize();
parent_node.removeChild(temp_list);
parent_node.normalize();
num_list_mergers++;
diagnostic_string += "Merged ordered list " + list_index + " upwards.\n";
} // closes check for adjacent ordered list
} // closes loop over ordered lists
// window.alert(diagnostic_string);
// Merge discursive lists
diagnostic_string = "";
discursive_lists = document.getElementById("bodyContent").getElementsByTagName("DL");
num_discursive_lists = discursive_lists.length;
max_list_index = num_discursive_lists - 1;
diagnostic_string += "There are " + num_discursive_lists + " discursive lists in this document.\n\n";
for (list_index=max_list_index; list_index>=0; list_index--) { // merge upwards
temp_list = discursive_lists[list_index];
prev_element_node = temp_list.previousSibling;
while ((prev_element_node) && (prev_element_node.nodeType != 1)) { // look for previous Element node
if (prev_element_node.nodeType == 3) {
text_length = prev_element_node.data.replace(/\s/ig, "").length;
if (text_length > 0 ) { break; } // break off loop if a non-empty text area is encountered
}
prev_element_node = prev_element_node.previousSibling;
} // closes search for the previous sibling Element node
if (!prev_element_node) { continue; }
diagnostic_string += "Previous element of DL " + list_index + " is of type " + prev_element_node.nodeType + " and tagName " + prev_element_node.nodeName + ".\n";
// if (prev_element_node.nodeType == 3) { diagnostic_string += " text = " + prev_element_node.data.replace(/\s/ig, "") + " length = " + prev_element_node.data.replace(/\s/ig, "").length + "\n"; }
if (prev_element_node.nodeName == "DL") {
parent_node = temp_list.parentNode;
num_child_nodes = temp_list.childNodes.length;
for (child_node_index = 0; child_node_index < num_child_nodes; child_node_index++) {
child_node = temp_list.childNodes[0];
prev_element_node.appendChild(child_node);
}
prev_element_node.normalize();
parent_node.removeChild(temp_list);
parent_node.normalize();
num_list_mergers++;
diagnostic_string += "Merged discursive list " + list_index + " upwards.\n";
} // closes check for adjacent discursive list
} // closes loop over discursive lists
// window.alert(diagnostic_string);
if (num_list_mergers == 1) {
alert_string += "\nThere was one list merger.\n";
} else {
alert_string += "\nThere were " + num_list_mergers + " list mergers.\n";
}
// Fix bug 11555 for screen readers: swap order of "editsection" and "mw-headline" nodes in headings
total_num_header_swaps = 0;
num_header_tag_strings = header_tag_strings.length;
for (header_tag_string_index = 0; header_tag_string_index < num_header_tag_strings; header_tag_string_index++) {
headers = document.getElementsByTagName(header_tag_strings[header_tag_string_index]);
num_headers = headers.length;
num_header_swaps = 0;
for (header_index=1; header_index temp_header = headers[header_index]; editsection_node = null; mw_headline_node = null; num_child_nodes = temp_header.childNodes.length; for (child_node_index = 0; child_node_index < num_child_nodes; child_node_index++) { child_node = temp_header.childNodes[child_node_index]; if (child_node.className == "editsection") { editsection_node = child_node; } else if (child_node.className == "mw-headline") { mw_headline_node = child_node; } } if ((eliminate_edit_section_links) && (editsection_node != null)) { temp_header.removeChild(editsection_node); num_header_swaps++; } else if ((editsection_node != null) && (mw_headline_node != null)) { temp_header.insertBefore(mw_headline_node, editsection_node); num_header_swaps++; } } // closes loop over headers of that type in document total_num_header_swaps += num_header_swaps; } // closes loop over different types of headers // Acknowledgment if (eliminate_edit_section_links) { if (total_num_header_swaps == 1) { alert_string += "Eliminated the edit-section link of one header.\n"; } else { alert_string += "Eliminated the edit-section link of " + total_num_header_swaps + " headers.\n"; } } else { if (total_num_header_swaps == 1) { alert_string += "Swapped text and edit link in one header.\n"; } else { alert_string += "Swapped text and edit link in " + total_num_header_swaps + " headers.\n"; } } // Main work of the script: eliminating hyperlinks hyperlinks = document.getElementById("bodyContent").getElementsByTagName("a"); num_redlinks = 0; num_redlinks_removed = 0; within_closing_section = false; num_hyperlinks = hyperlinks.length; while (hyperlink_counter temp_hyperlink = hyperlinks[hyperlink_index]; hyperlink_counter++; // Count the redlinks if (temp_hyperlink.className == "new") { num_redlinks++; } // Determine whether we've reached the end of the article if ((temp_hyperlink.name) && (!within_closing_section)) { temp_anchor_name = temp_hyperlink.name; temp_anchor_name = temp_anchor_name.replace(/:$/ig,""); // eliminate colons at end temp_anchor_name = temp_anchor_name.replace(/s$/ig,""); // eliminate plurals at end temp_anchor_name = temp_anchor_name.replace(/See_also/ig,""); temp_anchor_name = temp_anchor_name.replace(/Related_topic/ig,""); temp_anchor_name = temp_anchor_name.replace(/Related_article/ig,""); temp_anchor_name = temp_anchor_name.replace(/Further_reading/ig,""); temp_anchor_name = temp_anchor_name.replace(/External_link/ig,""); temp_anchor_name = temp_anchor_name.replace(/Footnote/ig,""); temp_anchor_name = temp_anchor_name.replace(/Note/ig,""); temp_anchor_name = temp_anchor_name.replace(/Reference/ig,""); temp_anchor_name = temp_anchor_name.replace(/Citation/ig,""); temp_anchor_name = temp_anchor_name.replace(/Source/ig,""); temp_anchor_name = temp_anchor_name.replace(/Link/ig,""); temp_anchor_name = temp_anchor_name.replace(/s([_\s]+)and([_\s]+)/ig,""); temp_anchor_name = temp_anchor_name.replace(/([_\s]+)and([_\s]+)/ig,""); temp_anchor_name = temp_anchor_name.replace(/([_\s]+)/ig,""); if (temp_anchor_name == "") { within_closing_section = true; // window.alert("The end of the article begins with section \"" + temp_hyperlink.name + "\"\n"); } } // closes check whether we've reached the end of the article // allow some sections to be skipped if (temp_hyperlink.name == "See_also") { strip_hyperlinks = false; } else if (temp_hyperlink.name == "Related_topics") { strip_hyperlinks = false; } else if (temp_hyperlink.name == "Related_articles") { strip_hyperlinks = false; } else if (temp_hyperlink.name) { strip_hyperlinks = true; } // if ((strip_hyperlinks == false) && (temp_hyperlink.className != "new")) { continue; } // criteria for keeping some links if (!temp_hyperlink.title) { hyperlink_index++; continue; } // replace only wikilinks? if (temp_hyperlink.title.match(/^User:/)) { hyperlink_index++; continue; } // keep user names if (temp_hyperlink.title.match(/^User\stalk:/)) { hyperlink_index++; continue; } // keep user talk pages if (temp_hyperlink.getAttribute("accesskey")) { hyperlink_index++; continue; } // avoid command links if (temp_hyperlink.className == "image") { hyperlink_index++; continue; } // keep images if (temp_hyperlink.className == "internal") { hyperlink_index++; continue; } // keep Enlarge buttons if (temp_hyperlink.className == "external text") { hyperlink_index++; continue; } // keep geotags, etc. // if ((on_main_page) && (temp_hyperlink.className == "extiw")) { continue; } // interwiki links at bottom // force the deletion of some types of links force_hyperlink_deletion = false; /* if (temp_hyperlink.className == "new") { force_hyperlink_deletion = true; } // check ancestor links against criteria to keep other types of links if (!force_hyperlink_deletion) { parent_node = temp_hyperlink.parentNode; grandparent_node = parent_node.parentNode; greatgrandparent_node = grandparent_node.parentNode; greatgreatgrandparent_node = greatgrandparent_node.parentNode; //Save all bold links on the Main Page if ((on_main_page) && (parent_node.nodeName == "B")) { hyperlink_index++; continue; } // Save specific types of navigational links on the Main Page // Save links in the mp-strapline if ((on_main_page) && ((greatgreatgrandparent_node.id == "mp-strapline") || (greatgreatgrandparent_node.parentNode.id == "mp-strapline"))) { hyperlink_index++; continue; } // Save "Recently featured:" links: most other parts use DIV; this section uses P as the parent if ((on_main_page) && (parent_node.nodeName == "P")) { next_sibling_node = parent_node.nextSibling; if ((next_sibling_node) && (next_sibling_node.nextSibling)) { next_sibling_node = next_sibling_node.nextSibling; if ((next_sibling_node.nodeName == "DIV") && (next_sibling_node.className = "noprint")) { hyperlink_index++; continue; } } /* diagnostic_string = temp_hyperlink.innerHTML; diagnostic_string += "\nParent node: " + parent_node.nodeName; if (parent_node.className) { diagnostic_string += "Class: " + parent_node.className; } diagnostic_string += "\nSibling node: " + next_sibling_node.nodeName; if (next_sibling_node.className) { diagnostic_string += "Class: " + next_sibling_node.className; } diagnostic_string += "\nGrandparent node: " + grandparent_node.nodeName; if (grandparent_node.className) { diagnostic_string += "Class: " + grandparent_node.className; } window.alert(diagnostic_string); } // if ((on_main_page) && (parent_node.nodeName == "P") && (grandparent_node.nodeName != "TD")) { hyperlink_index++; continue; } // if ((on_main_page) && (parent_node.nodeName == "P") && (grandparent_node.nodeName != "TD") && (greatgrandparent_node.nodeName != "TD") && (greatgreatgrandparent_node.nodeName != "TD")) { hyperlink_index++; continue; } // Imperfect solutions: // if on Main Page and parent_node firstChild text equals "Recently featured: ": Language-specific is bad // if on Main Page and nextSibling of parent is DIV with align=right and className=noprint and prevSibling has id mp-tfa // next_sibling_node = parent_node.nextSibling; // prev_sibling_node = parent_node.previousSibling; //FAILED if ((on_main_page) && (parent_node.nodeName == "P") && (next_sibling_node.nodeName == "DIV") && (next_sibling_node.className == "noprint")) { hyperlink_index++; continue; } //FAILED if ((on_main_page) && (parent_node.nodeName == "P") && (next_sibling_node.nodeName == "DIV") && (next_sibling_node.className == "noprint") && (grandparent_node.nodeName == "DIV")) { hyperlink_index++; continue; } // Links that should be kept: // keep links within most lists per Graham87's suggestion, but not References and Notes; allow anchor to be in italics if (((parent_node.nodeName == "LI") || (grandparent_node.nodeName == "LI")) && (!on_main_page) && (grandparent_node.className != "references") && (greatgrandparent_node.className != "references-small") && (temp_hyperlink.className != "new")) {hyperlink_index++; continue; } // keep section edit buttons if (parent_node.className == "editsection") { hyperlink_index++; continue; } // keep sidebar buttons if (greatgrandparent_node.className == "pBody") { hyperlink_index++; continue; } // keep category links if ((greatgrandparent_node.className == "catlinks") || (grandparent_node.className == "catlinks")) { hyperlink_index++; continue; } // keep disambiguations if ((parent_node.className == "dablink") || (grandparent_node.className == "dablink") || (greatgrandparent_node.className == "dablink")) { hyperlink_index++; continue; } // keep "Main article" links if (grandparent_node.className == "noprint relarticle mainarticle") { hyperlink_index++; continue; } // keep "Further details" links if ((grandparent_node.className == "boilerplate seealso") || (grandparent_node.className == "boilerplate further")){ hyperlink_index++; continue; } // keep protected and semi-protected icons if (grandparent_node.className == "metadata plainlinks") { hyperlink_index++; continue; } // keep links in sound samples if ((parent_node.className == "medialist listenlist") || (grandparent_node.className == "medialist listenlist") || (greatgrandparent_node.className == "medialist listenlist")) { hyperlink_index++; continue; } } // closes check for forced deletion of hyperlink // Old technique for replacing link; fails for italicized text, and is not general // temp_hyperlink_text = document.createTextNode(temp_hyperlink.innerHTML); // parent_node.replaceChild(temp_hyperlink_text, temp_hyperlink); // Better technique for replacing links: graft subtree back into the document num_child_nodes = temp_hyperlink.childNodes.length; for (child_node_index = 0; child_node_index < num_child_nodes; child_node_index++) { child_node = temp_hyperlink.childNodes[0]; parent_node.insertBefore(child_node, temp_hyperlink); } parent_node.removeChild(temp_hyperlink); num_hyperlinks_removed++; // Count the redlinks removed if (temp_hyperlink.className == "new") { redlink_names.push(temp_hyperlink.title); num_redlinks_removed++; } // Merge blocks of text that are adjacent in the document tree, prevent screen reader pauses parent_node.normalize(); } // closes loop over hyperlinks // Acknowledgment if (num_redlinks == 1) { alert_string += "Counted one redlink in the main article, unlinked " + num_redlinks_removed + ".\n"; if (num_redlinks_removed == 1) { alert_string += " " + redlink_names[0] + "\n"; } } else { alert_string += "Counted " + num_redlinks + " redlinks in the main article, unlinked " + num_redlinks_removed + ".\n"; if (num_redlinks_removed == 1) { alert_string += " " + redlink_names[0] + "\n"; } else if (num_redlinks_removed > 1) { diagnostic_string = "Removed " + num_redlinks_removed + " redlinks:\n\n"; for (redlink_index=1; redlink_index<=num_redlinks_removed; redlink_index++) { if ((redlink_index%40 == 1) && (redlink_index > 1)) { window.alert(diagnostic_string); diagnostic_string = "List of " + num_redlinks_removed + " redlinks continued...\n\n"; } diagnostic_string += redlink_index + " " + redlink_names[redlink_index-1] + "\n"; } // closes loop over removed redlinks window.alert(diagnostic_string); } // checks whether more than one redlink was removed } // closes check for redlinks if (num_hyperlinks_removed == 1) { alert_string += "Removed one hyperlink from this article.\n"; } else { alert_string += "Removed " + num_hyperlinks_removed + " hyperlinks from this article.\n"; } // Count number of significant images // This code seems dangerous for Internet Explorer image_counter = 0; num_significant_images = 0; num_images = document.images.length; for (image_index=0; image_index temp_image = document.images[image_index]; num_pixels = temp_image.width * temp_image.height; if (num_pixels > 5000) { image_counter++; } // closes check for a "significant" image, not an tiny icon } // closes loop over the images num_significant_images = image_counter; // Amend ALT text of image captions, initially to avoid double reading of captions image_counter = 0; num_uncaptioned_images = 0; num_images = document.images.length; for (image_index=0; image_index alt_string = ""; temp_image = document.images[image_index]; num_pixels = temp_image.width * temp_image.height; if (num_pixels > 5000) { image_counter++; alt_string = "Image " + image_counter + " of " + num_significant_images + ": "; if (temp_image.alt != "") { // preface image with number temp_image.alt = alt_string + temp_image.alt; } else if (temp_image.src) { temp_image.alt = alt_string + temp_image.src.split('/').pop(); } } // closes check for a "significant" image, not an tiny icon /* if (temp_image.className == "thumbimage") { if (temp_image.alt) { num_uncaptioned_images++; alt_string = "Image " + num_uncaptioned_images + ": "; temp_image.alt = alt_string + temp_image.alt; // preface image with number } } else if (num_pixels > 5000) { // uncaptioned infobox images num_uncaptioned_images++; } } // closes loop over the images // Acknowledgment if (image_counter == 1) { alert_string += "Modified ALT text of one image.\n"; } else { alert_string += "Modified ALT text of " + image_counter + " images.\n"; } // Print combined alert string window.alert(alert_string); } // closes function stripHyperlinks() addOnloadHook(function () { mw.util.addPortletLink('p-cactions', 'javascript:stripHyperlinks()', '–links', 'ca-nolinks', 'Strips links for screen readers like FireVox', 's', ''); }); // importScript('User:Dr_pda/prosesize.js'); //User:Dr_pda/prosesize.js var book_source_URL = "http://www.worldcat.org/search?q=isbn%3AMAGICNUMBER"; importScript('User:Lunchboxhero/externISBN.js'); importScript('User:2D/commonsmover.js'); showbydefault = true; // Fix hyphens, dashes, and minus signs per MOS:DASH. // // See talk page for instructions. // // The user can disable these conversions by putting "nodashes" somewhere // in the text — either temporarily or permanently. You can similarly add // "scores" if the score-detection heuristic doesn't trigger automatically. // // This tool can be used standalone until it is added to AutoEd and wikEd. // This module should follow unicodify.js if it is used. // Testing page is at User:GregU/dashes.js/tests. // Please report false positives on the talk page. function autoEdDashes (str) { if (str.search(/nodashes/i) >= 0) return str; var scpat = /\bscores?\b|\[\[Category:.*\b(sport|athlet|players|teams|games|league|champion|tournament|competit|cup\b|\w+ball\b|hockey|lacrosse|cricket|rugby|tennis|golf|polo|boxing|boxers|martial.art|chess)/i; var scoresAreLikely = (str.search(scpat) >= 0); // Ensure the replacement isn't a link such as FOO - BAR before // replacing it, so that we don't break the link. But we do want to // replace dashes used in the right-side label part of links. Also, // don't break templates, URLs, DOIs, {{#expr:}}, // source code, or . // function ifNotLink (str) { var pos = arguments[ arguments.length - 2 ]; var string = arguments[ arguments.length - 1 ]; var pat = /\[\\*$|\{\{[^|}]*$|[:\/%][^\s|>]+$|<[^>]*$|#\w*expr:.*$/i; if (string.substring(pos-260,pos+1).search(pat) >= 0) return str; // it's a link, so don't change it var pat2 = /\{\{(main|see|detail|about|for\b|other|redir|conv|coor)[^}]*$/i; if (string.substring(pos-260,pos+1).search(pat2) >= 0) return str; // likely templates with page-name or neg params var m = string.slice(pos).search(/<\/?(math|source|syntaxhighlight|pre|code)\b/i); if (m >= 0 && string.charAt(pos+m+1) == '/') return str; // don't break a if (string.slice(pos).search(/^[^|{}[\]<>\n]*\.[a-z]{3,4}\s*[|}]|^.*hyphen/i) >= 0) return str; // it's a file name parameter, or if (str.search(/[ |(>][-–]\b/) >= 0) return str.replace(/[-–]/, "−"); // minus sign else return str.replace(/--+\b/g, "—") . replace(/[-–−]+/g, "–"); // dash } str = str.replace(/\s--?\s/g, ifNotLink); // en dash looks better str = str.replace(/[a-z\d]---?[a-z\d]/ig, ifNotLink); // em dash str = str.replace(/\d\d\d]*}*[-−](present|current)\b/ig, ifNotLink); // 1973-present str = str.replace(/[^\w−-](18|19|20)\d\d]*}*[-−][^\w−-]/g, ifNotLink); // (1973-) str = str.replace(/\d(s|%|\?|''')[-−]\d/g, ifNotLink); // 1950s-1960s, 40%-50% str = str.replace(/\d[-−](\$|'+)\d/g, ifNotLink); // $40-$50, 7-4, '49-'53 str = str.replace(/[½⅓⅔¼¾⅛⅜⅝⅞]%?[-−][\d½⅓⅔¼¾⅛⅜⅝⅞]/g, ifNotLink); // 3½-6 str = str.replace(/\d(st|nd|rd|th)?[-−]\d+(st|nd|rd|th)\b/g, ifNotLink); // 2nd-3rd str = str.replace(/([a-z,'"”\]>] +|\(|^\| *|\|\| *)[-–]\d/mig, ifNotLink); // minus -35 str = str.replace(/<((sup|sub|td)>\s*)[-–](\d)/ig, "<$1−$3"); // 10-3 str = str.replace(/,*(?=.? ) *[-–—−] *(\d*:\d\d[\s*<])/g, " – $1"); // album track listings // November 15, 2005-March 7, 2006; March 18-April 4 str = str.replace(/(\d\]*)[-–—−](\[*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]* +\d)/g, "$1 – $2"); // July-August 2007 str = str.replace(/\b((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]*[-−]?\b){2,}/g, ifNotLink); str = str.replace(/(\d(?: BC)?\]\])[-−]((ca?\.|AD ?)?\[\[\d+[^\d-])/g, "$1–$2"); // (1984 – 1992) str = str.replace(/([(|=] *\[*\d+\]*) +[–—−] +(\[*\d+\]*\s*[)|}])/g, "$1–$2"); // iv-xii str = str.replace(/[ ;(=](?=\w+-)(m*(cm|cd|d?c*)(xc|xl|l?x*)(ix|iv|v?i*)-?\b){2}[^\w-]/g, ifNotLink); if (scoresAreLikely) // W-L-D or 73–70–67–70=280, but not castling str = str.replace(/[^\w−–-](?!0-0-0)(\d\d?\d?[-–−]){2,}\d\d?[^\w\/−–-]/g, ifNotLink); str = str.replace(/\b(\d+)[–−](year|month|day|hour|minute|mile|yard|foot|inch|bit|door|speed|gun|page|seat|way|point|ton|man)\b/g, "$1-$2"); // hyphen // Number ranges and scores should use en dashes, per MOS:DASH. // This has been well-tested and false positives (e.g., ID nos.) are rare. // function range (str, from,to, pos,string) { var dash = true; var except = /\b(fig(ure)?|table|example|exhibit|circular|section|part|number|no|nr|id|model|pub|std|report|rpt|law|P?L|p|page|date|IS\wN\b[ a-z]*)[^\w(,;]*$/i; var rpat = /^([^A-Za-z]|nbsp)*(AD|BC|B?CE|BP|[kMG]a|km|mi|kg|lb|\w?Hz|vote|decision|record|odds|scor\w*|win|loss|tie|draw|lead|victory|defeat|upset|run|deficit|start|finish|season|game)\b/; var lpat = /\b(pages|pp|rp|nos|\d+\)?'*[:,]|(w[io]n|lost?|tie|dr.w|lea?d|f.ll|vot|rul|decid|pass|fail|defeat|scor|gam|match|trail|finish|end)e?[ds]?|\w\w+ing|ahead|behind|up|down|from|to|is|are|was|were|of|out|by|an?|at|it|went|go|gone|beaten|between)([^a-z]|nbsp)*$/i; var inorder = (to-0 > from.slice(-to.length)); // pp 362-5 var precision = Math.max( from.search(/0*$/), to.search(/0*$/) ); if (string.substring(pos-20,pos+1).search(except) >= 0) { return str; // based on preceding word, looks like a ref number } if (from == 9 && to == 11) { dash = false; // 9-11 is a common special case } if (from-0 >= to) { dash = false; // values don't look like a range } if (to-from > 120 && from * (precision > 2 ? 5 : 50) < to && from > 1) { dash = false; // values don't look like a range } if (scoresAreLikely && from <= 900 && to <= 900) { dash = true; // likely a score or wins-losses } if (from < 2-to && string.search(/Category:.*\bChess\b/i) >= 0) { dash = false; // chess notations 0-0, 0-1, 1-0 } if (str.charAt(0) == '(' && string.charAt(pos + str.length) == ')') { dash = true; // scores often seen as (8-4) } if (from.search(/^0./) >= 0 || to.search(/^0./) >= 0) { dash = false; // 3-07 and 0123-4567 look like ref numbers } if (string.substr(pos-1,15).search(/^\d([:,.])\d+.\d+\1\d/) >= 0) { dash = true; // 10:30-11:30, 35,000-40,000, 2.5-4.0 } if (string.substr(pos,30).search(rpat) >= 0) { dash = true; // 12-5 BC, 5-5000 km, 6-4 win, 73-50 vote } if (string.substring(pos-80,pos).search(lpat) >= 0) { dash = true; // pp. 8, 25, 270-74, 313-7; won 6-4, 6-2 } if (from > 1000 && from < 2100 && to.length == 2 && inorder) { dash = true; // 1994-95 year range } return dash ? ifNotLink(str,pos,string) : str; } str = str.replace(/[^\w\/+−–-](\d{1,4})[-−](\d{1,4})(?!'*[\w\/+−–-])/g, range); return str; } // Hook to allow using this tool "standalone" if (importScript("Wikipedia:AutoEd/core.js")) // if not otherwise using AutoEd { function autoEdFunctions() { var txt = document.editform.wpTextbox1; var str = txt.value; str = str.replace(/—/g, '—'); str = str.replace(/–/g, '–'); str = str.replace(/−/g, '−'); txt.value = autoEdDashes( str ); } autoEdLinkName = "–"; autoEdLinkHover = "Fix dashes, hyphens, and minus signs"; autoEdTag = "fixed dashes using a script"; } /*** BEGIN WIKIBREAK ENFORCER ***/ addOnloadHook(function() { /*** Start editing here ***/ // When you want to end your break? // no leading zeroes. (example: 7 - correct, 07 - incorrect) var date = { year: 2009, month: 7, day: 21}; var time = { hours: 20, minutes: 00, seconds: 0 }; /*** Stop editing here ***/ var currentDate = new Date(); var enforcedBreakEnd = new Date( date.year,date.month-1,date.day,time.hours,time.minutes,time.seconds); if (currentDate <= enforcedBreakEnd) { alert("Enforced wikibreak until "+enforcedBreakEnd.toLocaleString() + "\n(now is "+currentDate.toLocaleString()+")\n\nBye!"); location = "http://"+location.host+"/w/index.php?title=" + "Special:Userlogout&returnto=Main_Page"; } }); /*** END WIKIBREAK ENFORCER ***/ importScript('User:Gary King/nominations viewer.js'); // Wikipedia:Nominations Viewer