ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
User:Gimmetrow/fixRefs.js - Wikipedia, the free encyclopedia

User:Gimmetrow/fixRefs.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

//<pre><code>
// This code requires addLink from: [[User:Omegatron/monobook.js/addlink.js]]
//
// [[User:Gimmetrow/fixRefs.js]]
 
function fixRefMarks() {
   var qt = String.fromCharCode(34)
   // var hb = String.fromCharCode(124)
   var txt = document.editform.wpTextbox1;
 
   // fact and other templates (geographic reference template, ref/note)
   var FactTag = "({{[ ]*fact[ ]*}}|{{[ ]*fact[ ]*[\|][^}]*}}|{{[ ]*facts[ ]*}}|{{[ ]*citequote[ ]*}}|{{[ ]*citation needed[ ]*}}|{{[ ]*cn[ ]*}}|{{[ ]*verification needed[ ]*}}|{{[ ]*verify source[ ]*}}|{{[ ]*verify credibility[ ]*}}|{{[ ]*who[ ]*}}|{{[ ]*failed verification[ ]*}}|{{[ ]*nonspecific[ ]*}}|{{[ ]*dubious[ ]*}}|{{[ ]*or[ ]*}}|{{[ ]*lopsided[ ]*}}|{{[ ]*GR[ ]*[\|][ ]*[^ ]+[ ]*}}|{{[ ]*[c]?r[e]?f[ ]*[\|][^}]*}}|{{[ ]*ref[ _]label[ ]*[\|][^}]*}}|{{[ ]*ref[ _]num[ ]*[\|][^}]*}})";
 
   txt.value = txt.value
   .replace(new RegExp("[\n\r\f\t ]+?"+FactTag, "gi"), "$1")
   // one+ space/linefeed, avoid matching references tag as a named ref
   .replace(new RegExp("[\n\r\f\t ]+?<ref([ >])", "gi"), "<ref$1")
   // remove trailing spaces from named refs
   .replace(new RegExp("<ref ([^>]*[^> ])[ ]*>", "gi"), "<ref $1>")
   // remove some superscripted punctuation between refs (is between necessary?)
   .replace(new RegExp("(</ref>|<ref[^>]*?/>)<sup>[ ]*[,;-]?[ ]*</sup><ref", "gi"), "$1<ref")
   .replace(new RegExp("(</ref>|<ref[^>]*?/>)[ ]*[,;-]?[ ]*<ref", "gi"), "$1<ref")
 
   .replace(new RegExp("(</ref>|<ref[^>]*?/>)[ \n\r\f\t]*([\.,])", "gi"), "$1$2");
 
   var LacksPunctuation = "([^\.,;:!\?"+qt+"'’])";
   var QuestionOrExclam = "([!\?])";
   var MinorPunctuation = "([\.,;:])";
   var Blockquote       = "(</blockquote>)";
 
   var Quote = "([" + qt + "'’]*)";
   //var Space = "[\n\r\f\t ]*"; // to handle  http://en.wikipedia.org/w/index.php?title=Cat&diff=99697351&oldid=99697026
   var Space = "[ ]*";
   var Space2 = "[\n\r\f\t ]*";
 
   var AnyPunctuation = "([\.,;:!\?])";
   var MajorPunctuation = "([,;:!\?])";
   var Period = "([\.])";
 
   // can this complicated close tag be simplified?
   //var closetag = "(([^<]|<[^/]|</[^r]|</r[^e]|</re[^f]|</ref[^>])*?)</ref>";
   //var closetag = "((.*?))</ref>";
   var RefTag1 = "(<ref>([^<]|<[^/]|</[^r]|</r[^e]|</re[^f]|</ref[^>])*?</ref>)";
   var RefTag2 = "(<ref[^>]*?[^/]>([^<]|<[^/]|</[^r]|</r[^e]|</re[^f]|</ref[^>])*?</ref>)";
   var RefTag3 = "(<ref[^>]*?/>)";
   //var Note = "("+RefTag1 + "|(" + RefTag2 + ")|(" + FactTag + "))";
 
   var match0a = LacksPunctuation+Quote+FactTag+Space+AnyPunctuation;
   var match0b = QuestionOrExclam+Quote+FactTag+Space+MajorPunctuation;
   var match0c = MinorPunctuation+Quote+FactTag+Space+AnyPunctuation;
   var match0d = QuestionOrExclam+Quote+FactTag+Space+Period;
 
   var match1a = LacksPunctuation+Quote+RefTag1+Space+AnyPunctuation;
   var match1b = QuestionOrExclam+Quote+RefTag1+Space+MajorPunctuation;
   var match1c = MinorPunctuation+Quote+RefTag1+Space+AnyPunctuation;
   var match1d = QuestionOrExclam+Quote+RefTag1+Space+Period;
 
   var match2a = LacksPunctuation+Quote+RefTag2+Space+AnyPunctuation;
   var match2b = QuestionOrExclam+Quote+RefTag2+Space+MajorPunctuation;
   var match2c = MinorPunctuation+Quote+RefTag2+Space+AnyPunctuation;
   var match2d = QuestionOrExclam+Quote+RefTag2+Space+Period;
 
   var match3a = LacksPunctuation+Quote+RefTag3+Space+AnyPunctuation;
   var match3b = QuestionOrExclam+Quote+RefTag3+Space+MajorPunctuation;
   var match3c = MinorPunctuation+Quote+RefTag3+Space+AnyPunctuation;
   var match3d = QuestionOrExclam+Quote+RefTag3+Space+Period;
 
   for (var j=0; j<5; j++)  // repeat for multiple refs together
   {
      txt.value = txt.value
      .replace(new RegExp(match0a, "gi"), "$1$2$4$3")
      .replace(new RegExp(match0b, "gi"), "$1$2$4$3")
      .replace(new RegExp(match0c, "gi"), "$2$4$3")
      .replace(new RegExp(match0d, "gi"), "$1$2$3")
 
      .replace(new RegExp(match1a, "gi"), "$1$2$5$3")
      .replace(new RegExp(match1b, "gi"), "$1$2$5$3")
      .replace(new RegExp(match1c, "gi"), "$2$5$3")
      .replace(new RegExp(match1d, "gi"), "$1$2$3")
 
      .replace(new RegExp(match2a, "gi"), "$1$2$5$3")
      .replace(new RegExp(match2b, "gi"), "$1$2$5$3")
      .replace(new RegExp(match2c, "gi"), "$2$5$3")
      .replace(new RegExp(match2d, "gi"), "$1$2$3")
 
      .replace(new RegExp(match3a, "gi"), "$1$2$4$3")
      .replace(new RegExp(match3b, "gi"), "$1$2$4$3")
      .replace(new RegExp(match3c, "gi"), "$2$4$3")
      .replace(new RegExp(match3d, "gi"), "$1$2$3");
   }
   // blockquotes (if trapped punctuation exists, remove it, and move blockquote past at least one ref)
   txt.value = txt.value
   .replace(new RegExp(Blockquote + AnyPunctuation + FactTag, "gi"), "$3$1")
   .replace(new RegExp(Blockquote + AnyPunctuation + RefTag1, "gi"), "$3$1")
   .replace(new RegExp(Blockquote + AnyPunctuation + RefTag2, "gi"), "$3$1")
   .replace(new RegExp(Blockquote + AnyPunctuation + RefTag3, "gi"), "$3$1")
   .replace(new RegExp(Blockquote + FactTag, "gi"), "$2$1")
   .replace(new RegExp(Blockquote + RefTag1, "gi"), "$2$1")
   .replace(new RegExp(Blockquote + RefTag2, "gi"), "$2$1")
   .replace(new RegExp(Blockquote + RefTag3, "gi"), "$2$1");
 
   var summary = document.editform.wpSummary;
   //summary.value = summary.value + " various minor fixes ";
}
 
addOnloadHook(function () {
    if(document.forms.editform) {
        // addLink('p-cactions', 'javascript:fixRefMarks()', 'fix refs', 'ca-reffix', 'Ref fix for the edit window', '', 'ca-history');
        addPortletLink('p-tb', 'javascript:fixRefMarks()', 'Fix reference marks', 't-reffix', 'Ref fix', '', '');
    }
});
//</code></pre>


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -