User:YumeChaser/monobook.js

//   /* delinking dates per updated MoS Numb */ importScript('User:Lightmouse/monobook.js/script.js')

// --- --- // // --- Credits  // // // This script was created by modifying the following scripts: //     User:Lightmouse/monobook.js/script.js //     WikiProject User scripts/Scripts/Formatter // // This script is intended to be complimentary to these scripts with very little // to no duplication of function. // -- Disclaimer -- // // // Use at your own risk and make sure you check the edit changes before you save // // Let me know User_Talk:Plastikspork if you find bugs! // - Installing the Script // // // (1) Open/Create your USERNAME/monobook.js page, where USERNAME is your username. //    A quick way to get there is to go to your user page, then append //    '/monobook.js' to the end of the URL. // // (2) Put the following command on your monobook.js page: //         importScript('User:Plastikspork/monobook.js/script.js'); // // (3) Save the page and reload it by following the instructions at the top of your //    monobook.js page. For example, Ctrl+Shift+R in Firefox. // --- Using the Script --- // // // (1) Open an article which you would like to edit, and you should see a bunch of //    'Spork' buttons in your 'toolbox' on the left side of your browser. // // (2) Click on one of the Spork buttons and the script will run, performing edits //    by pattern matches. When it is finished, it will show you the changes and //    add some comments to the edit summary. It is up to you to accept these //    changes as is by clicking 'Save page', modify the changes by further editing //    the edit form, or reject by leaving the page. // // Note: The script will run very slowly on very large pages, but it does always //       eventually complete in my experience. // - Current Functionality // // // [Sprk: WS] Removes excessive non-essential whitespace, non-breaking space, and //       some minor wikification. // // [Sprk: Wki/Lnk Rpair] Wikification, fixes of simple repeated references, //       conversion of external wikilinks to wikilinks, and simplification of //        piped wikilinks. // // [Sprk: [] to Refs] Replaces [URL] with // // [Sprk: Cite Templte] Adds citation templates to some common //       untemplated references. // // [Sprk: Ref Repeat] Fixes obvious repeated references and marks //       non-obvious ones for human inspection with REPEAT tags. //       Once the script runs, you can inspect the tagged refs to //        see if they are actual repeats, or if they are false //       positives. // // [Sprk: Color] Simplifies some hex color codes to named colors. // // [Sprk: Table to Wiki] An attempt to turn HTML tables into //       wikitables. Requires some hand tuning after it runs. // // [Sprk: cite date to mdy] Changes date = YYYY-MM-DD to date = Month DD, YYYY // // [Sprk: cite date to dmy] Changes date = YYYY-MM-DD to date = DD Month YYYY // // [UnSprk: cite date] Reverses prior two commands // // --- Turning off and Renaming Buttons --- // // // The buttons in the script can be selectively disabled and renamed, to rename a // button, say 'Sprk: WS' to 'Spork: Whitespace', paste the following into your // monobook.js: // // if( typeof( SporkConfig ) == 'undefined' ) SporkConfig = {}; // SporkConfig.ws = "Spork: Whitespace"; // // To rename more buttons, just add an additional line for each button. The initial // creation of the empty structure only needs to be performed once. // // To remove a button, give it a null string for its name. For example, // // if( typeof( SporkConfig ) == 'undefined' ) SporkConfig = {}; // SporkConfig.ws = ""; // // will turn off the 'Sprk: WS' button. // // The variable names for each button can be found in the code directly below. // --- --- // // Set Default Button Names if( typeof( SporkConfig ) == 'undefined' ) SporkConfig = {}; if( typeof( SporkConfig.wlr ) == 'undefined' ) SporkConfig.wlr  = "Sprk: Wki/LinkRepair"; if( typeof( SporkConfig.b2r ) == 'undefined' ) SporkConfig.b2r  = "Sprk: [] to Refs"; if( typeof( SporkConfig.ct  ) == 'undefined' ) SporkConfig.ct   = "Sprk: CiteTemplate"; if( typeof( SporkConfig.rr  ) == 'undefined' ) SporkConfig.rr   = "Sprk: Ref Repeat"; if( typeof( SporkConfig.ws  ) == 'undefined' ) SporkConfig.ws   = "Sprk: WS"; if( typeof( SporkConfig.c   ) == 'undefined' ) SporkConfig.c    = "Sprk: Color"; if( typeof( SporkConfig.t2w ) == 'undefined' ) SporkConfig.t2w  = "Sprk: Table to Wiki"; if( typeof( SporkConfig.cmdy ) == 'undefined' ) SporkConfig.cmdy = "Sprk: cite date mdy"; if( typeof( SporkConfig.cdmy ) == 'undefined' ) SporkConfig.cdmy = "Sprk: cite date dmy"; if( typeof( SporkConfig.unc ) == 'undefined' ) SporkConfig.unc  = "UnSprk: cite date"; if( typeof( SporkConfig.noa ) == 'undefined' ) SporkConfig.noa  = ""; // testing 1 if( typeof( SporkConfig.tst ) == 'undefined' ) SporkConfig.tst  = ""; // testing 2 if( typeof( SporkConfig.fullurl ) == 'undefined' ) SporkConfig.fullurl  = ""; // testing 3 // --- --- // // Import Spork-Tools scripts importScript('User:Plastikspork/tools.js'); importScript('User:Plastikspork/whitespace.js'); importScript('User:Plastikspork/citetools.js'); importScript('User:Plastikspork/reftools.js'); importScript('User:Plastikspork/datetools.js'); // --- --- // // Spork: Wiki/LinkRepair function spork_wiki_link_repair(clk){ var txt = document.editform.wpTextbox1; txt.value = spork_headings2wiki(txt.value);      // See User:Plastikspork/tools.js  txt.value = spork_section_headings(txt.value); txt.value = spork_external_links(txt.value); txt.value = spork_extern_wikilinks_to_wikilinks(txt.value); // See User:Plastikspork/tools.js txt.value = spork_ref_clean(txt.value); txt.value = spork_dehexchar_wikilinks(txt.value); // See User:Plastikspork/tools.js txt.value = spork_special_char(txt.value); txt.value = spork_simplify_wikilinks(txt.value); // See User:Plastikspork/tools.js  txt.value = spork_no_selflink(txt.value);         // See User:Plastikspork/tools.js  txt.value = spork_convert(txt.value); txt.value = spork_lists(txt.value); spork_edit_summary("wikification"); spork_edit_summary("link repair"); if(clk) document.editform.wpDiff.click; } // Spork: [] to ref function spork_bracket_to_ref(clk){ var txt = document.editform.wpTextbox1; txt.value = spork_bracket_url_to_ref(txt.value); spork_edit_summary("wikification"); if(clk) document.editform.wpDiff.click; } // Spork: CiteTemplate function spork_citation_template(clk){ var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(/([\[]+http[^\[\]<>]*)([\]]+)/gi, '$1$3$2'); txt.value = txt.value.replace(/(\/]*>[^<>]*)([^<>]*<\/ref>)/gi, '$1$3$2'); txt.value = spork_cite_web(txt.value); txt.value = spork_cite_article(txt.value); txt.value = txt.value.replace(/(\/]*>[^<>]*)(<\/ref>)/gi, '$1$3$2'); txt.value = txt.value.replace(/(\{\{cite[^}]*\|[ ]*title[ ]*=[^\|}]*)([^\|}]*?\}\}[^<>]*)/gi, '$1$3$2'); txt.value = txt.value.replace(/([\[]+http[^\[\]<>]*)([\]]+)/gi, '$1$3$2'); spork_edit_summary("cite template"); if(clk) document.editform.wpDiff.click; } // Spork: Ref Repeat function spork_ref_repeat(clk){ var txt = document.editform.wpTextbox1; txt.value = spork_ref_clean(txt.value); // Mark duplicate ref names with NAME REPEAT1 REPEAT2 (change to name by hand and re-run script) txt.value=txt.value.replace(/ $5$6$7$3$8 '); spork_edit_summary("ref simplification"); if(clk) document.editform.wpDiff.click; } // Spork: WS function spork_ws_compress(clk){ var txt = document.editform.wpTextbox1; txt.value = spork_whitespace(txt.value);          //See User:Plastikspork/whitespace.js  txt.value = spork_ws_refs(txt.value);              //See User:Plastikspork/whitespace.js  txt.value = spork_ws_nowrap(txt.value);            //See User:Plastikspork/whitespace.js  txt.value = spork_br(txt.value);                   //See User:Plastikspork/tools.js  txt.value = spork_ws_tables_infoboxes(txt.value);  //See User:Plastikspork/whitespace.js  txt.value = spork_dehexchar_wikilinks(txt.value);  //See User:Plastikspork/tools.js  txt.value = spork_special_char(txt.value); txt.value = spork_whitespace(txt.value);          //See User:Plastikspork/whitespace.js  spork_edit_summary("wikification"); spork_edit_summary("WS removal"); if(clk) document.editform.wpDiff.click; } // Spork: Color function spork_color(clk){ var txt = document.editform.wpTextbox1; txt.value = spork_color_simple(txt.value); spork_edit_summary("color simplification"); if(clk) document.editform.wpDiff.click; } // Spork: Table to Wiki function spork_wiki_table(clk){ var txt = document.editform.wpTextbox1; txt.value = spork_table2wiki(txt.value); spork_edit_summary("wikification"); if(clk) document.editform.wpDiff.click; } // Spork: cite date mdy function spork_cite_to_mdy(clk) { var txt = document.editform.wpTextbox1; txt.value = spork_yyyymmdd_to_mdy(txt.value); // See User:Plastikspork/tools.js  txt.value = spork_dmy_to_mdy(txt.value);       // See User:Plastikspork/tools.js  spork_edit_summary("date formatting"); if(clk) document.editform.wpDiff.click; } // Spork: cite date dmy function spork_cite_to_dmy(clk) { var txt = document.editform.wpTextbox1; txt.value = spork_yyyymmdd_to_dmy(txt.value); // See User:Plastikspork/tools.js  txt.value = spork_mdy_to_dmy(txt.value);       // See User:Plastikspork/tools.js  spork_edit_summary("date formatting"); if(clk) document.editform.wpDiff.click; } // Unspork: cite date function spork_cite_to_yyyymmdd(clk) { var txt = document.editform.wpTextbox1; txt.value = spork_mdy_to_yyyymmdd(txt.value); // See User:Plastikspork/tools.js  txt.value = spork_dmy_to_yyyymmdd(txt.value);  // See User:Plastikspork/tools.js  spork_edit_summary("date formatting"); if(clk) document.editform.wpDiff.click; } // Spork: No Align function spork_no_align(clk){ var txt = document.editform.wpTextbox1; txt.value=txt.value.replace(/([\r\n]\||\|\||[\r\n]!|!!|\|-)([ ]*[a-z][^\|!]* |[ ]*)align[ ]*=["' ]*(?:center|left|right)['" ]*/gi, '$1$2 '); txt.value=txt.value.replace(/([\r\n]\||\|\||[\r\n]!|!!|\|-)([ ]*[a-z][^\|!]* |[ ]*)(style[ ]*=["' ]*)([ ]*[a-z][^'"\|!]*;|[ ]*)text-align[ ]*:[ ]*(?:center|left|right);?[ ]*/gi, '$1$2$3$4'); txt.value=txt.value.replace(/([^a-z])style[ ]*=[ ]*["'][ ]*['"]/gi, '$1 '); txt.value=txt.value.replace(/([\r\n]\||\|\||[\r\n]!|!!|\|-)[ ]+\|([^\|])/g, '$1 $2'); txt.value=txt.value.replace(/<[\/]*center[ ]*>/gi, ''); txt.value=txt.value.replace(/([\r\n]\||\|\||[\r\n]!|!!|\|-)[ ]+([\r\n])/g, '$1$2'); txt.value=txt.value.replace(/]*>/g, ''); txt.value=txt.value.replace(/<\/span>/g, ''); spork_edit_summary("table simplification"); if(clk) document.editform.wpDiff.click; } // Spork: Testing function spork_testing(clk){ // Spork: WS   spork_ws_compress(0); // Spork: Wiki/Link/Repair spork_wiki_link_repair(0); // Spork: [] to Refs spork_bracket_to_ref(0); // Spork: CiteTemplate spork_citation_template(0); // Spork: Ref Repeat spork_ref_repeat(0); // Spork: Color spork_color(0); // Spork: WS   spork_ws_compress(0); // WP:DATE var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(/(\(|years_?active[\s]*=[\s]*)([12][0-9]{3})[\s]*(?:[–—\-–]| to[\s]+present|[–—\-–][\s]*present)([\s]*\)|[\s]*\||[\s]*\}\}|[\s]*$)/gi, '$1since $2$3'); //txt.value=txt.value.replace(/\[http:\/\/www\.hulu\.com\/watch[^ \[\]]*\]/g, ''); //txt.value=txt.value.replace(/\[http:\/\/www\.hulu\.com\/watch[^ \[\]]* ([^\[\]]*)\]/g, '$1'); document.editform.wpSummary.value = "Script assisted wikification"; if(clk) document.editform.wpDiff.click; } // Spork: Fullurl Template function spork_fullurl(clk){ // WP:DATE var txt = document.editform.wpTextbox1; var loopcount = 0; txt.value = txt.value.replace(/\{\{SERVER\}\}\/wiki\/([^\/\?]*)\?([^\[\]{}\|\r\n ]*)([}\]\| \r\n])/gi, '\{\{fullurl:$1|$2\}\}$3'); txt.value = txt.value.replace(/http:\/\/en\.wikipedia\.org\/wiki\/([^\/\?]*)\?([^\[\]{}\|\r\n ]*)([}\]\| \r\n])/gi, '\{\{fullurl:$1|$2\}\}$3'); txt.value = txt.value.replace(/http:\/\/en\.wikipedia\.org\/w\/index\.php\?title=([^\/&]*)&([^\[\]{}\|\r\n ]*)([}\]\| \r\n])/gi, '\{\{fullurl:$1|$2\}\}$3'); txt.value = txt.value.replace(/https:\/\/secure\.wikipedia\.org\/wikipedia\/en\/wiki\/([^\/\?]*)\?([^\[\]{}\|\r\n ]*)([}\]\| \r\n])/gi, '\{\{fullurl:$1|$2\}\}$3'); loopcount = 0; while( txt.value.search( /\{\{fullurl:Special:Search\|[^}]*&search=[^&}]*%20/gi ) >= 0 && loopcount <= 10 ) { txt.value = txt.value.replace(/(\{\{fullurl:Special:Search\|[^}]*&search=[^&}]*)%20/gi, '$1+'); loopcount++; }   loopcount = 0; while( txt.value.search( /\{\{fullurl:Special:Search\|[^}]*&search=[^&}]*%27/gi ) >= 0 && loopcount <= 10 ) { txt.value = txt.value.replace(/(\{\{fullurl:Special:Search\|[^}]*&search=[^&}]*)%27/gi, "$1'"); // "'" loopcount++; }   document.editform.wpSummary.value = "Script assisted switch to fullurl template"; if(clk) document.editform.wpDiff.click; } // - WS Functions - // // Called by Spork: WS function spork_special_char(str) { str=str.replace(/([a-z][ ]*) -- ([ ]*[a-z])/gi, '$1 – $2'); str=str.replace(/&mdash;/gi, '—'); str=str.replace(/–/gi, '–'); // str=str.replace(/[‘’]/g, "'"); //' // str=str.replace(/[“”]/g, '"'); //" return str; } // -- Wiki/LinkRepair Functions -- // // Called by Spork: Wiki/LinkRepair function spork_section_headings(str){ // Extra bold section headings str=str.replace(/(^|[\r\n])(=[=]+[ ]*)([^\r\n]*)([ ]*=[=]+)[\t ]*([\r\n]|$)/g, '$1$2$3$4$5'); // Capitalization of common section headings str=str.replace(/(==See) A(lso==)/g, '$1 a$2'); str=str.replace(/(==External) L(inks==)/g, '$1 l$2'); str=str.replace(/(==Early) L(ife==)/g, '$1 l$2'); return str; } // Called by Spork: Wiki/LinkRepair function spork_external_links(str) { // Common broken links str=str.replace(/(\[https?:[^\[\]]+\])([a-z])/gi, '$1 $2'); str=str.replace(/(\[https?:\/\/[^\]\]\| ]+)[ ]*\|[ ]*([^\]\[\|]*\])/gi, '$1 $2'); // Convert links to secure wikipedia to standard wikipedia str=str.replace(/\https:\/\/secure.wikimedia.org\/wikipedia\/([a-z]+)\//g, 'http://$1.wikipedia.org/'); // Linking to upload page rather than image page str=str.replace(/http:\/\/upload\.wikimedia\.org\/wikipedia\/commons\/[a-z0-9]\/[a-z0-9][a-z0-9]\//gi, 'http://commons.wikimedia.org/wiki/Image:'); // Punctuation inside external links str=str.replace(/(\[https?:[^\[\]\| ]*)[\| ][ ]*([']+|["]+)([^"'\|\[\]]*)\2([:\.,\? ]*\])/g, '$2$1 $3$4$2'); str=str.replace(/(\[https?:[^\[\]\| ]*)[\| ][ ]*([‘’]|[“])([^“’‘\|\[\]]*)([‘’]|[”])([:\.,\? ]*\])/g, '$2$1 $3$5$4'); // Extra brackets around references str=str.replace(/\[(\[)(http|ftp|https)(:[^\[\]]+\])\]/gi, '$1$2$3'); // Extra brackets inside references str=str.replace(/(\/]*>)\[([^\[\]<> ]*)\](<\/ref>)/gi, '$1$2$3'); // Convert "external wikipedia" image references to (PIC) links str=str.replace(/(\)/gi, '($1$1$2:$3|pic$4$4)'); str=str.replace(/(\[)http:\/\/en\.wikipedia\.org\/wiki\/Image(:[^ \[\]\|<>]*)(\])/gi, '($1$1:File$2|pic$3$3)'); return str; } // Called by Spork: Wiki/LinkRepair function spork_convert(str) { // Template Fun str=str.replace(/ ([1-9])[ ]*'[ ]*([1-9]|1[01])[ ]*"[ ]*\([12]\.[0-9][0-9]?[ ]*m\)/g, ' \{\{height|ft=$1|in=$2\}\}'); str=str.replace(/ ([0-9][0-9,\.]*)( | )+(\[\[)square mile(\]\])s[ ]+\([0-9][0-9,\.]*( | )+(\[\[)km²(\]\])\)/g, ' \{\{convert|$1|sqmi|km2|lk=on\}\}');  str=str.replace(/ ([0-9][0-9,\.]*)( | )+(\[\[)square mile(\]\])s[ ]+\([0-9][0-9,\.]*( | )+km²\)/g, ' \{\{convert|$1|sqmi|km2|lk=in\}\}');  str=str.replace(/ ([0-9][0-9,\.]*)( | )+square miles[ ]+\([0-9][0-9,\.]*( | )+(\[\[)km²(\]\])\)/g, ' \{\{convert|$1|sqmi|km2|lk=out\}\}');  str=str.replace(/ ([0-9][0-9,\.]*)( | )+square miles[ ]+\([0-9][0-9,\.]*( | )+km²\)/g, ' \{\{convert|$1|sqmi|km2\}\}');  str=str.replace(/ ([0-9][0-9,\.]*) people per square mile \([0-9][0-9,\.]*\/km²\)/g, ' \{\{convert|$1|PD/sqmi|/km2\}\}');  str=str.replace(/ ([0-9][0-9,\.]+) people per square mile/g, ' \{\{convert|$1|PD/sqmi|/km2\}\}');  str=str.replace(/ ([0-9][0-9,\.]*)\/sq mi \([0-9][0-9,\.]*\/km²\)/g, ' \{\{convert|$1|/sqmi|/km2\}\}'); str=str.replace(/(\{\{convert\|[0-9]+),/g, '$1'); return str; } // Called by Spork: Wiki/LinkRepair function spork_lists(str) { // Wikify bullet lists str=str.replace(/([\r\n])•(.*[\r\n])[\r\n]/gim, '$1* $2'); // Convert all-bold lines to use semicolon markup str=str.replace(/([\r\n])'''([^':]*)[']*[ ]*<[\\\/\. ]*BR[^<>]*>([\r\n])/gi, '$1;$2$3'); str=str.replace(/([\r\n])'''([^':]*)[']*[ ]*([\r\n])/gi, '$1;$2$3'); return str; } // --- Color Functions --- // // Called by Spork: Color function spork_color_simple(str){ str=str.replace(/([\r\n]\||[\r\n]!|\|\||!!)([^\|!<>\[\]]*)style[ ]*=[" ]*color[ ]*:[ ]*([a-z0-9\#]*)[; ]*[ "]*([^\|!<>\[\]]*\|)([^\|])/gi, '$1$2 $4$5'); str=str.replace(/([\r\n]\||[\r\n]!|\|\||!!)([^\|!<>\[\]]*style[ ]*=[ ]*"[^"<>\|!]*;)[ ]*color[ ]*:[ ]*([a-z0-9\#]*)[ ;]*([^\|!<>\[\]]*\|)([^\|])/gi, '$1$2$4$5'); str=str.replace(/({1,4}|\{\{nbsp\|[1-4]\}\})<\/span>/gi, '\{\{colorbox|$2\}\}'); //" str=str.replace(/([^<>]*)<\/span>/gi, '\{\{colorbox|$2|$3\}\}'); //" str=str.replace(/(\|\|[^\|\r\n]*)style="(?:background|background-color):([^ ";]*)[; ]*"/gi, '$1bgcolor="$2"'); //" str=str.replace(/([\r\n]\|[^\|\r\n]*)style="(?:background|background-color):([^ ";]*)[; ]*"/gi, '$1bgcolor="$2"'); //" str=str.replace(/bgcolor="(transparent|none)"/gi, 'style="background: $1"'); str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?000000\2/gi, '$1$2black$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?0000FF\2/gi,  '$1$2blue$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?A52A2A\2/gi, '$1$2brown$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FF7F50\2/gi, '$1$2coral$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?00FFFF\2/gi,  '$1$2cyan$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FF00FF\2/gi,'$1$2fuchsia$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FFD700\2/gi,  '$1$2gold$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?808080\2/gi,  '$1$2gray$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?008000\2/gi, '$1$2green$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?00FF00\2/gi,  '$1$2lime$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FF00FF\2/gi,'$1$2magenta$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?800000\2/gi, '$1$2maroon$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?000080\2/gi,  '$1$2navy$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?808000\2/gi, '$1$2olive$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FFA500\2/gi, '$1$2orange$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FFC0CB\2/gi,  '$1$2pink$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?800080\2/gi, '$1$2purple$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FF0000\2/gi,   '$1$2red$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?C0C0C0\2/gi, '$1$2silver$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?D2B48C\2/gi,   '$1$2tan$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?008080\2/gi,  '$1$2teal$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?EE82EE\2/gi, '$1$2violet$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FFFFFF\2/gi, '$1$2white$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FFFF00\2/gi, '$1$2yellow$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?FFF5EE\2/gi,'$1$2seashell$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?F08080\2/gi,'$1$2lightcoral$2'); // " str=str.replace(/(color[ ]?box[ ]*\||color[ ]*=|color[ ]*:)[ ]*("?)#?D2691E\2/gi,'$1$2chocolate$2'); // " str=str.replace(/(color[ ]?box[ ]*\|)[ ]*"([^\|}{]*)"/gi, '$1$2'); // Font tag outside of footnote str=str.replace(/(]*>[ ]*)(\[\[#fn[^\|\]]*\|)/gi, '$2$1'); return str; } // -- testing Functions -- // function spork_newlines(str) { var loopcount = 0; // Extra newlines after section headings str = str.replace(/([\r\n]=.*=[\r\n])[\t ]*[\r\n][\t ]*([\r\n])/gim, '$1$2'); // newlines in citation templates (multiple times) str = str.replace(/(\{\{(?:cite|citation))[\r\n]/gim, '$1 '); loopcount = 0; while( str.search( /\{\{(?:cite|citation) [^}]*[\r\n]/gi ) >= 0 && loopcount <= 10 ) { str=str.replace(/(\{\{(?:cite|citation) [^}]*)[\r\n]/gim, '$1 '); loopcount++; } // Extra newlines after before bullets str=str.replace(/([\r\n]\*.*[\r\n])[\t ]*[\r\n](\*)/gim, '$1$2'); // Extra newlines before semicolon marked bold lines str=str.replace(/([\r\n])([#;:\*].*[\r\n])[ ]*[\r\n]([#;:\*])/gim, '$1$2$3'); return str; } // - interface Functions - // function spork_edit_summary(summary){ // Add a tag to the summary box var txt = document.editform.wpSummary; var fullsummary = "Script assisted " + summary; if (txt.value.indexOf(summary) == -1) { if (txt.value.match( /Script assisted [A-Za-z]/ )) { txt.value = txt.value.replace( /Script assisted /, fullsummary + "/"); } else if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | " + fullsummary; } else { txt.value += fullsummary; } } } $(function  {  if(document.forms.editform) {    if( SporkConfig.ws != "" )      mw.util.addPortletLink('p-tb', 'javascript:spork_ws_compress(1)', SporkConfig.ws);    if( SporkConfig.wlr != "" )      mw.util.addPortletLink('p-tb', 'javascript:spork_wiki_link_repair(1)', SporkConfig.wlr);    if( SporkConfig.b2r != "" )      mw.util.addPortletLink('p-tb', 'javascript:spork_bracket_to_ref(1)', SporkConfig.b2r);    if( SporkConfig.ct != "" )      mw.util.addPortletLink('p-tb', 'javascript:spork_citation_template(1)', SporkConfig.ct);    if( SporkConfig.rr != "" )      mw.util.addPortletLink('p-tb', 'javascript:spork_ref_repeat(1)', SporkConfig.rr);    if( SporkConfig.c != "" )      mw.util.addPortletLink('p-tb', 'javascript:spork_color(1)', SporkConfig.c);    if( SporkConfig.t2w != "" )      mw.util.addPortletLink('p-tb', 'javascript:spork_wiki_table(1)', SporkConfig.t2w);    if( SporkConfig.cmdy != "" ) mw.util.addPortletLink('p-tb', 'javascript:spork_cite_to_mdy(1)', SporkConfig.cmdy); if( SporkConfig.cdmy != "" ) mw.util.addPortletLink('p-tb', 'javascript:spork_cite_to_dmy(1)', SporkConfig.cdmy); if( SporkConfig.unc != "" ) mw.util.addPortletLink('p-tb', 'javascript:spork_cite_to_yyyymmdd(1)', SporkConfig.unc); if( SporkConfig.noa != "" ) mw.util.addPortletLink('p-tb', 'javascript:spork_no_align(1)', SporkConfig.noa); if( SporkConfig.tst != "" ) mw.util.addPortletLink('p-tb', 'javascript:spork_testing(1)', SporkConfig.tst); if( SporkConfig.fullurl != "" ) mw.util.addPortletLink('p-tb', 'javascript:spork_fullurl(1)', SporkConfig.fullurl); } });

importScript('User:AzaToth/twinkle.js');

importScript('User:Ioeth/friendlywelcome.js');

importScript('User:Ioeth/friendlytag.js');

importScript('User:Ioeth/friendlyshared.js');

importScript('User:TheDJ/Gadget-HotCat.js');

// User:Lupin/popups.js

importScript('User:Lupin/popups.js');

// install User:Cacycle/wikEdDiff enhanced diff view using ajax importScript('User:Cacycle/wikEdDiff.js');

//Auto AFD script

//Please include the two following lines //Modified version of AutoVFD script to work with AFD //Script Modified by User:Jtkiefer //Further modified to work with WP:AFDC by User:ais523

// This needs to change depending on skin used. function add_link(url, name) { var na = document.createElement('a'); na.setAttribute('href', url); na.appendChild(document.createTextNode(name));

var li = document.createElement('li'); li.appendChild(na);

var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; tabs.appendChild(li); }

function strip_namespace(target) { var colon = target.indexOf(':'); if (colon != -1) {     var spaces = new Array('User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category'); var ns = target.substring(0, colon); if (ns == '' || ns == 'Talk') return target.substring(colon + 1); else for (var i = 0; i < spaces.length; ++i) {           if (ns == spaces[i]                || ns == spaces[i] + '_talk') return target.substring(colon + 1); }   }

return target; }

function afd { document.editform.wpTextbox1.value = '\n' + document.editform.wpTextbox1.value; document.editform.wpSummary.value = 'afd';

var target = document.editform.action; target = target.substring(target.indexOf('title=') + 6,                           target.lastIndexOf('&action=submit'));

var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var date = new Date; date = date.getUTCFullYear + '_' + months[date.getUTCMonth] + '_' + date.getUTCDate;

var pagename = strip_namespace(target);

window.open('/w/index.php?title=Wikipedia:Articles_for_deletion/' + pagename + '&action=edit&fakeaction=afdsub&faketarget=' + target,             'Afd ' + unescape(target),              'status,toolbar,location,menubar,directories,resizeable,scrollbars'); window.open('/w/index.php?title=Wikipedia:Articles_for_deletion/Log/' + date + '&action=edit&fakeaction=afdlist&faketarget=' + pagename,             'AfdLog ' + unescape(target),              'status,toolbar,location,menubar,directories,resizeable,scrollbars'); }

function autoafd { if (document.title.indexOf('Editing ') == 0) {     var action = ''; var target = ''; if (location.search) {         var l = location.search.substring(1).split('&'); for (var i = 0; i < l.length; ++i) {             var eq = l[i].indexOf('='); var name = l[i].substring(0, eq); if (name == 'fakeaction') action = l[i].substring(eq + 1); else if (name == 'faketarget') target = unescape(l[i].substring(eq + 1)).replace(/_/g, ' '); }       }

if (action == 'afdlist') {         document.editform.wpTextbox1.value += '\n'; document.editform.wpSummary.value = 'Articles for deletion/' + target + ''; }     else if (action == 'afdsub') {         if (document.editform.wpTextbox1.value.length > 0) {             target = document.editform.action; target = unescape(target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit'))).replace(/_/g, ' '); window.alert("There's an old afd at the default location already.\n\n" +                          'Please either move it out of the way (and update existing links to it), or file the Afd by hand in another location (such as ' + target + ' (2)).'); }         else document.editform.wpTextbox1.value += '===' + target + '===\n' + '\n'+ ': – (View AfD) \n'+ 'Reason for nomination. ' + '\n*\n*\n*\n'; }     else add_link('javascript:afd', 'Afd'); } }

$(autoafd);

//

//This function adds a link to the toolbox which, when clicked, displays the size of the page //and the size of the prose in bytes. See the talk page for more details. // //To use this function add User:Dr pda/prosesizebytes.js to your monobook.js // function loadXMLDocPassingTemplate(url,handler, page) {   // 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, page)}; req.open("GET", url, true); req.send(""); } } function getWikiText(req, page) { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // ...processing statements go here... response = req.responseXML.documentElement; var rev = response.getElementsByTagName('rev'); if(rev.length > 0){ result = rev[0].getAttribute('size'); result = result+' B'; wiki_value = document.createElement("li"); wiki_value.id = "wiki-size"; wiki_value.innerHTML = 'Wiki text: '+result; var output = document.getElementById("document-size-stats"); prose_value = document.getElementById("prose-size"); output.insertBefore(wiki_value,prose_value); }	 else{ //alert("There was a problem using the Wikipedia Search to find the wiki text size\nEither the search is not working or the correct article did not appear on the first page of results"); wiki_value = document.createElement("li"); wiki_value.id = "wiki-size"; wiki_value.innerHTML = 'Wiki text: Problem getting wiki text size'; var output = document.getElementById("document-size-stats"); prose_value = document.getElementById("prose-size"); output.insertBefore(wiki_value,prose_value); }       } else { alert("There was a problem retrieving the XML data:\n" +               req.statusText); }   } } function getFileSize(req, page) { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // ...processing statements go here... var fsize = req.responseText.length; window.status = fsize; var total_value = document.createElement("li"); total_value.id = "total-size"; total_value.innerHTML='File size: '+fsize+' B'; var output = document.getElementById("document-size-stats"); var prose_html_value = document.getElementById("prose-size-html"); output.insertBefore(total_value,prose_html_value); } else { alert("There was a problem retrieving the XML data:\n" +               req.statusText + "\n(" + url + ")"); }   } } function getLength(id){ var textLength = 0; for(var i=0;i<id.childNodes.length; i++){ if(id.childNodes[i].nodeName == '#text'){ textLength += id.childNodes[i].nodeValue.length; } else{ textLength += getLength(id.childNodes[i]); } } return textLength; } function getRefMarkLength(id,html){ var textLength = 0; for(var i=0;i<id.childNodes.length; i++){ if(id.childNodes[i].className == 'reference'){ textLength += (html)? id.childNodes[i].innerHTML.length : getLength(id.childNodes[i]); } } return textLength; } function getDocumentSize{ contentDivName = ''; if(skin == 'monobook' || skin == 'chick' || skin == 'myskin' || skin == 'simple'){ contentDivName = 'bodyContent'; } else if (skin == 'modern'){ contentDivName = 'mw_contentholder'; } else if (skin == 'standard' || skin == 'cologneblue' || skin == 'nostalgia'){ contentDivName = 'article'; } else{ //fallback case; the above covers all currently existing skins contentDivName = 'bodyContent'; } //Same for all skins if previewing page if(wgAction == 'submit') contentDivName = 'wikiPreview'; var bodyContent = document.getElementById(contentDivName); if(document.getElementById("document-size-stats")){ //if statistics already exist, turn them off and remove highlighting var output = document.getElementById("document-size-stats"); var oldStyle = output.className; var pList = bodyContent.getElementsByTagName("p"); for(var i=0;i<pList.length; i++){ if(pList[i].parentNode.id == contentDivName) pList[i].style.cssText = oldStyle; }  output.parentNode.removeChild(output); var header = document.getElementById("document-size-header"); header.parentNode.removeChild(header); } else{ var output = document.createElement("ul"); output.id = "document-size-stats"; var prose_html_value = document.createElement("li"); prose_html_value.id = "prose-size-html"; output.appendChild(prose_html_value); var ref_html_value = document.createElement("li"); ref_html_value.id = "ref-size-html"; output.appendChild(ref_html_value); var prose_value = document.createElement("li"); prose_value.id = "prose-size"; output.appendChild(prose_value); output.className = bodyContent.getElementsByTagName("p").item(0).style.cssText; var ref_value = document.createElement("li"); ref_value.id = "ref-size"; output.appendChild(ref_value); var dummy = document.getElementById("siteSub"); dummy.parentNode.insertBefore(output, dummy.nextSibling); var header = document.createElement("span"); header.id = "document-size-header"; header.innerHTML = ' Document statistics: (See here for details.) '; dummy.parentNode.insertBefore(header,output); //File size not well defined for preview mode or section edit if(wgAction != 'submit'){ //If browser supports document.fileSize property (IE) if(document.fileSize){ var total_value = document.createElement("li"); total_value.id = "total-size"; total_value.innerHTML='File size: '+document.fileSize+' B'; output.insertBefore(total_value,prose_html_value); }  else{ loadXMLDocPassingTemplate(location.pathname,getFileSize,'') } } //Get size of images only if browser supports filesize property (IE) var iList = bodyContent.getElementsByTagName("img"); if(iList.length >0 && iList[0].fileSize){ //Get size of images included in document var image_size = 0; var first_magnify = true; for (var i=0;i<iList.length; i++){ var im = iList[i]; if(im.getAttribute("src").indexOf("magnify-clip.png") != -1){ if(first_magnify){ image_size += im.fileSize*1; first_magnify = false; }   }    else{ image_size += im.fileSize*1; }  }   var image_value = document.createElement("li"); image_value.id = "image-size"; image_value.innerHTML='Images: '+image_size+' B'; output.appendChild(image_value); } //Calculate prose size and size of reference markers ([1] etc) var pList = bodyContent.getElementsByTagName("p"); prose_size = 0; prose_size_html = 0; refmark_size = 0; refmark_size_html = 0; word_count = 0; for(var i=0;i]+)>)/ig,"").split(' ').length para.style.cssText = "background-color:yellow"; } } prose_value.innerHTML='Prose size (text only): '+(prose_size-refmark_size)+' B ('+word_count+' words) "readable prose size"'; prose_html_value.innerHTML='Prose size (including all HTML code): '+(prose_size_html-refmark_size_html)+' B'; //Calculate size of references (i.e. output of ) var rList = bodyContent.getElementsByTagName("ol"); var ref_size = 0; var ref_size_html = 0; for (var i=0; i<rList.length; i++){ if(rList[i].className == "references"){ ref_size = getLength(rList[i]); ref_size_html = rList[i].innerHTML.length; } } ref_value.innerHTML='References (text only): '+(ref_size+refmark_size)+' B'; ref_html_value.innerHTML='References (including all HTML code): '+(ref_size_html+refmark_size_html)+' B'; //get correct name of article from wikipedia-defined global variables var pageNameUnderscores = wgPageName; var pageNameSpaces = pageNameUnderscores.replace(/_/g,' ') //if page is a permalink, diff, etc don't try to search if(!location.pathname.match('/w/index.php')){ //Get revision size from API var searchURL = '/w/api.php?action=query&prop=revisions&rvprop=size&format=xml&revids=' + wgCurRevisionId; loadXMLDocPassingTemplate(searchURL,getWikiText,pageNameSpaces); } else if(wgAction == 'submit'){ //Get size of text in edit box result = document.getElementById('wpTextbox1').value.length; result = result+' B'; wiki_value = document.createElement("li"); wiki_value.id = "wiki-size"; wiki_value.innerHTML = 'Wiki text: '+result; var output = document.getElementById("document-size-stats"); prose_value = document.getElementById("prose-size"); output.insertBefore(wiki_value,prose_value); } } } $(function {  if(wgAction == 'edit' || (wgAction == 'submit' && document.getElementById('wikiDiff')) ){    mw.util.addPortletLink('p-tb', 'javascript:alert("You need to preview the text for the prose size script to work in edit mode.")', 'Page size', 't-page-size', 'Calculate page and prose size', , );    document.getElementById("t-page-size").firstChild.style.cssText = "color:black;"  }  else if(wgAction == 'view' || wgAction == 'submit' || wgAction == 'purge'){    mw.util.addPortletLink('p-tb', 'javascript:getDocumentSize', 'Page size', 't-page-size', 'Calculate page and prose size', , );  } }); importScript('User:Gary King/localize comments.js'); LocalizeConfig = { dateFormat : 'mdy' }; importScript('User:AzaToth/twinkle.js'); //