:User:Coemgenus/monobook.js
mw.loader.load('//en.wikipedia.org/w/index.php?title=User%3ADr_pda%2Fprosesize.js&action=raw&ctype=text/javascript'); // User:Dr_pda/prosesize.js
//Interiot's javascript edit counter
if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) {
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js&action=raw&ctype=text/javascript'); }
function externISBN() {
for (var i = 0; i < document.links.length; i++)
{
var ln = document.links[i].href.match(/isbn=(.*)/);
if (ln) {
document.links[i].href='http://www.amazon.com/exec/obidos/ASIN/'+RegExp.$1;
}
}
}
addOnloadHook(externISBN);
importScript("User:Lupin/recent2.js");
//Create 'winc' function:
function winc(s) {
document.write('');
}
//function to handle dates:
importScript('User:Lightmouse/monobook.js/script.js');
/**
* Metadata assessment script
* Finds the WP 1.0/WikiProject assessment of every article you go to, then
* displays that information in the article header.
*
* @author Outriggr - created the script and used to maintain it
* @author Pyrospirit - currently maintains and updates the script
*/
// Import stylesheet with custom classes for header colors
importStylesheet('User:Pyrospirit/metadata.css');
/**
* This is the constructor for the script object. All functions this script
* defines are inside this.
*
* @constructor
*/
MetadataScript = function () {};
/**
* Starts the script object running. The main function of the script. If the
* getMainType() function can find the assessment, it uses that assessment
* for the page, parses it, and displays it in the header. Otherwise, it runs
* ajaxMain().
*/
MetadataScript.prototype.init = function () {
var initialAssessment = this.checkArticle();
if ( initialAssessment.exists ) {
this.currentAssessment = initialAssessment;
var data = this.talkAssess(this.currentAssessment);
this.update(data.newClass, data.slogan, data.info);
}
else this.ajaxMain();
};
/**
* The main function when an AJAX request is needed to find the assessment.
* Creates an AJAX request for the contents of a URL (defaults to the
* first section of the article's talk page), then sends the request. After
* getting the requested data back, it finds the assessment information in
* the data, then uses and displays that assessment in the header.
*
* @param {String} arguments[0] - Optional: override the default URL for the
* AJAX request.
*/
MetadataScript.prototype.ajaxMain = function () {
if ( arguments[0] && arguments[0].match(/^https?:\/\//i) ) this.url = arguments[0];
else this.url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=Talk:' + encodeURIComponent(mw.config.get('wgPageName'))
+ '&action=raw§ion=0';
this.request = sajax_init_object();
if ( this.request ) {
var self = this;
this.request.onreadystatechange = function () {
if ( this !== self ) {
arguments.callee.call(self, arguments);
return;
}
if ( this.request.readyState == 4 && this.request.status == 200 ) {
this.text = this.request.responseText;
this.currentAssessment = this.findAssessment(this.request.responseText);
var data = this.talkAssess(this.currentAssessment);
this.update(data.newClass, data.slogan, data.info);
}
};
this.request.open('GET', this.url, true);
this.request.send(null);
}
};
/**
* Checks for various objects on the article page that indicate a certain
* assessment, such as a featured star or disambiguation page notice. If this
* function can find the assessment, AJAX is not needed for this page.
*
* @return {Object} assess - the assessment in an easily readable format
*
* @static
*/
MetadataScript.prototype.checkArticle = function () {
var assess = {};
assess.extra == '';
assess.exists = true;
if ( document.getElementById('disambig') )
assess.rating = 'dab';
else if ( document.getElementById('contentSub').innerHTML == 'Redirect page' )
assess.rating = 'redir';
else if ( document.getElementById('ca-talk').className == 'new' )
assess.rating = 'none';
else assess.exists = false;
return assess;
};
/**
* Searches the provided wikicode for an assessment and returns the
* assessment it finds as an object. This function first checks for things
* such as former FA/GA status and current FA/GA nominations, then looks for
* current assessment status.
*
* Note that a higher assessment takes priority, and less-used assessments
* such as "list", "current", or "future" are used only if nothing else can
* be found.
*
* @param {String} text - some wikitext to be searched for assessment info
*
* @return {Object} assess - the assessment in an easily readable format
*
* @static
*/
MetadataScript.prototype.findAssessment = function (text) {
var assess = {};
var actionNumber = 0;
if ( text.match(/\bclass *= *a\b/i) ) {
if ( text.match(/\bclass *= *ga\b|\bcurrentstatus *= *(ffa\/)?ga\b/i) )
assess.rating = 'a/ga';
else assess.rating = 'a';
} else if ( text.match(/\bclass *= *ga\b|\bcurrentstatus *= *(ffa\/)?ga\b|\{\{ *ga *\|/i)
&& !text.match(/\bcurrentstatus *= *dga\b/i) ) assess.rating = 'ga';
else if ( text.match(/\bclass *= *b\b/i) ) assess.rating = 'b';
else if ( text.match(/\bclass *= *bplus\b/i) ) assess.rating = 'bplus';
else if ( text.match(/\bclass *= *c\b/i) ) assess.rating = 'c';
else if ( text.match(/\bclass *= *start/i) ) assess.rating = 'start';
else if ( text.match(/\bclass *= *stub/i) ) assess.rating = 'stub';
else if ( text.match(/\bclass *= *list/i) ) assess.rating = 'list';
else if ( text.match(/\bclass *= *(dab|disambig)/i) ) assess.rating = 'dab';
else if ( text.match(/\b(class|currentstatus) *= *fl\b/i) ) assess.rating = 'fl';
else if ( text.match(/\b(class|currentstatus) *= *fa\b/i) ) assess.rating = 'fa';
else if ( text.match(/\bclass *= *cur(rent)?/i) ) assess.rating = 'cur';
else if ( text.match(/\bclass *= *future/i) ) assess.rating = 'future';
else assess.rating = 'none';
assess.pageLink = null;
if ( (assess.reg = text.match(/\{\{ *fac *[\|\}]/i)) ) {
assess.extra = 'fac';
} else if ( (assess.reg = text.match(/\{\{ *flc *\}\}/i)) ) {
assess.extra = 'flc';
} else if ( (assess.reg = text.match(/\{\{ *ga ?nominee *[\|\}]/i)) ) {
assess.extra = 'gan';
} else if ( (assess.reg = text.match(/\{\{ *far(ce?)? *[\|\}]/i)) ) {
assess.extra = 'far';
} else if ( (assess.reg = text.match(/\{\{ *flrc *[\|\}]/i)) ) {
assess.extra = 'flrc';
} else if ( (assess.reg = text.match(/\{\{ *gar\/link *[\|\}]/i)) ) {
assess.extra = 'gar';
} else if ( (assess.reg = text.match(/\bcurrentstatus *= *ffa\b/i)) ) {
actionNumber = text.match(/\baction(\d\d?) *= *far\b/i)[1];
assess.extra = 'ffa';
} else if ( (assess.reg = text.match(/\{\{ *formerfa2?\b/i)) ) {
assess.extra = 'ffa';
} else if ( (assess.reg = text.match(/\bcurrentstatus *= *ffl\b/i)) ) {
assess.extra = 'ffl';
} else if ( (assess.reg = text.match(/\{\{ *ffl *[\|\}]/i)) ) {
assess.extra = 'ffl';
} else if ( (assess.reg = text.match(/\bcurrentstatus *= *dga\b/i)) ) {
assess.extra = 'dga';
} else if ( (assess.reg = text.match(/\{\{ *d(elisted)?ga *[\|\}]/i)) ) {
assess.extra = 'dga';
} else if ( (assess.reg = text.match(/\baction(\d\d?) *= *fac\b/i)) &&
!assess.rating.match(/f[al]/i) ) {
actionNumber = assess.reg[1];
assess.pageLink = true;
assess.extra = 'ffac';
} else if ( (assess.reg = text.match(/\{\{ *fac?(failed|(\-| \()?contested\)?) *[\|\{]/i)) ) {
assess.extra = 'ffac';
} else if ( (assess.reg = text.match(/\baction(\d\d?) *= *flc\b/i)) &&
!assess.rating.match(/f[al]/i) ) {
actionNumber = assess.reg[1];
assess.pageLink = true;
assess.extra = 'fflc';
} else if ( (assess.reg = text.match(/\baction(\d\d?) *= *gan\b/i)) &&
!assess.rating.match(/f[al]|(a\/)?ga/i) ) {
actionNumber = assess.reg[1];
assess.pageLink = true;
assess.extra = 'fgan';
} else if ( (assess.reg = text.match(/\{\{ *f(ailed ?)?ga *[\|\}]/i)) ) {
assess.extra = 'fgan';
} else assess.extra = 'none';
if ( assess.pageLink ) {
var pageLinkPattern = '\\baction' + actionNumber + 'link *= *([^\\n\\|]+)\\s*\\|';
assess.pageLink = text.match(RegExp(pageLinkPattern))[1];
}
if ( assess.extra == 'ffa' ) {
var ffaType = RegExp('\\baction' + actionNumber + 'link *= *Wikipedia:Featured[ _]'
+ 'article[ _]removal[ _]candidates\\/', 'i');
assess.ffaPage = text.match(ffaType) ? 'Wikipedia:Featured_article_removal_candidates/'
: 'Wikipedia:Featured_article_review/';
}
assess.exists = true;
return assess;
}
/**
* Parses an assessment object into the HTML and CSS code needed to update
* the article header. If it doesn't recognize a part of the information
* given, it will simply ignore it and mark as unassessed.
*
* @param {Object} assess - assessment information for this article
*
* @return {String} newClass - the CSS class corresponding to its assessment
* @return {String} slogan - HTML giving (with a link) the main assessment
* @return {String} info - HTML giving (with a link) additional information
*
* @static
*/
MetadataScript.prototype.talkAssess = function (assess) {
var info = '';
var path = mw.config.get('wgArticlePath').replace('$1', '');
var page = encodeURIComponent(mw.config.get('wgPageName'));
var assessLink = path + 'Wikipedia:Version_1.0_Editorial_Team/Assessment';
if ( typeof assess.extra === 'undefined' ) assess.extra = '';
var extra = assess.extra.toLowerCase();
var rating = assess.rating.toLowerCase();
var pageLink = assess.pageLink ? encodeURIComponent(assess.pageLink.replace(' ', '_')) : null;
if ( extra == 'fac' ) {
info = '. Currently a featured article candidate.';
}
else if ( extra == 'flc' ) {
info = '. Currently a featured list candidate.';
}
else if ( extra == 'gan' ) {
info = '. Currently a '
+ 'good article nominee.';
}
else if ( extra == 'far' ) {
info = '. Currently undergoing review of its featured status.';
}
else if ( extra == 'flrc' ) {
info = '. Currently a candidate for removal as a featured list.';
}
else if ( extra == 'gar' ) {
info = '. Currently undergoing a reassessment of its status as a good article.';
}
else if ( extra == 'ffa' ) {
info = '. A former'
+ ' featured article.';
}
else if ( extra == 'ffl' ) {
info = '. A former featured list.';
}
else if ( extra == 'dga' ) {
info = '. A delisted '
+ 'good article.';
}
else if ( extra == 'ffac' ) {
info = '. A former featured article '
+ 'candidate.';
}
else if ( extra == 'fflc' ) {
info = '. A former featured list candidate'
+ '.';
}
else if ( extra == 'fgan' ) {
info = '. A former good article nominee.';
}
if ( rating == 'a' || rating == 'a/ga' ) {
newClass = 'assess-A-text';
slogan = 'An A-class article';
if ( rating == 'a/ga' ) {
if ( info.length == 0 ) info += '.';
info += ' Also a good article.'
}
}
else if ( rating == 'ga' ) {
newClass = 'assess-GA-text';
slogan = 'A good article'
}
else if ( rating == 'b' ) {
newClass = 'assess-B-text';
slogan = 'A B-class article';
}
else if ( rating == 'bplus' ) {
newClass = 'assess-Bplus-text';
slogan = 'A B-plus-class article';
}
else if ( rating == 'c' ) {
newClass = 'assess-C-text';
slogan = 'A C-class article';
}
else if ( rating == 'start' ) {
newClass = 'assess-Start-text';
slogan = 'A start-class article';
}
else if ( rating == 'stub' ) {
newClass = 'assess-Stub-text';
slogan = 'A stub-class article';
}
else if ( rating == 'list' ) {
newClass = 'assess-List-text';
slogan = 'A list-class article';
}
else if ( rating == 'dab' ) {
newClass = 'assess-Dab-text';
slogan = 'A disambiguation page';
}
else if ( rating == 'redir' ) {
newClass = 'assess-Redir-text';
slogan = 'A redirect page';
}
else if ( rating == 'fl' ) {
newClass = 'assess-FA-text';
slogan = 'A featured list';
}
else if ( rating == 'fa' ) {
newClass = 'assess-FA-text';
slogan = 'A featured article';
}
else if ( rating == 'cur' ) {
newClass = 'assess-Cur-text';
slogan = 'A current-class article';
}
else if ( rating == 'future' ) {
newClass = 'assess-Future-text';
slogan = 'A future-class'
+ ' article';
}
else {
newClass = '';
slogan = 'An unassessed article';
}
return {newClass: newClass, slogan: slogan, info: info};
};
/**
* Updates article header with new assessment information by giving it a new
* class (for style information such as color) and altering the tagline below
* it to state the assessment found.
*
* @param {String} newClass - the CSS class name added to the article header
* @param {String} slogan - italicized text prepended to the tagline, showing
* the article's main assessment
* @param {String} info - additional assessment info appended to the tagline
*
* @static
*/
MetadataScript.prototype.update = function (newClass, slogan, info) {
var firstHeading = document.getElementsByTagName('h1')[0];
firstHeading.className += ' ' + newClass;
document.getElementById('siteSub').innerHTML = '' + slogan + ''
+ ' from Wikipedia, the free encyclopedia' + info;
};
/**
* Creates the global MetadataObject as an instance of MetadataAssessmentScript, then
* calls the init() method of MetadataObject to start the script.
*/
if ( mw.config.get('wgNamespaceNumber') == 0 && (mw.config.get('wgAction') == 'view' || mw.config.get('wgAction') == 'purge')
&& mw.config.get('wgPageName') != 'Main_Page' ) {
addOnloadHook(function () {
if (typeof MetadataObject === 'undefined') {
MetadataObject = new MetadataScript();
}
MetadataObject.init();
});
}
importScript('User:Plastikspork/date.js')
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|pre|code|tt|source|syntaxhighlight)\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";
}