User:Jonesey95/AutoEd/issn.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var AutoEd_baseurl = 'http://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Jonesey95/AutoEd/';
if (location.protocol === 'https:') {
  AutoEd_baseurl = 'https://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Jonesey95/AutoEd/';
}
 
mw.loader.load(AutoEd_baseurl + 'core5.js'); //Imports the "framework" script needed to make this function

//Sets variable configuration
autoEdTag5 = "Fixing [[:Category:CS1 errors: ISSN|CS1 ISSN errors]] or other invalid ISSN using [[WP:AutoEd|AutoEd]]"; //Tweaks edit summary
autoEdLinkName5 = "AutoEd ISSN"; //Changes the link name at the top of the page
autoEdLinkHover5 = "Run AutoEd to replace strings"; //When user hovers over link
 
//Set up function
function ReplaceISSN(str) { //function to replace ISSN strings

  //Replace bad Time magazine ISSN
  str = str.replace(/issn\s*=\s*0040-*718X/g, 'issn=0040-781X');
  //Comment out invalid Billboard Brasil ISSN (probably a UPC)
  str = str.replace(/(issn\s*=\s*977-\s*217605400-2\s*\|*)/gi, '<!--$1-->');
  str = str.replace(/(issn\s*=\s*977-2155985400-2)/gi, '<!--$1-->');
  str = str.replace(/(issn\s*=\s*977-879605400-2)/gi, '<!--$1-->');
  //Replace ISSN lower-case x with uppercase X
  str = str.replace(/(issn\s*[=\|]\s*\d\d\d\d)[-–—= ]*(\d\d\d)x/g, '$1-$2X');
  str = str.replace(/(ISSN\s*[=\|]\s*\d\d\d\d)[-–—= ]*(\d\d\d)x/g, '$1-$2X');
  //Fix crazy separators
  str = str.replace(/(issn\s*=\s*\d\d\d\d)[‐–—=\. ](\d\d\d[\dX])/gi, '$1-$2');
  str = str.replace(/(issn\s*=\s*\d\d\d\d)\&ndash\;(\d\d\d[\dX])/gi, '$1-$2');
  //Fix crazy values
  str = str.replace(/issn\s*=\s*none\s*([\|\}])/gi, 'issn=$1');
  str = str.replace(/issn\s*=\s*null\s*([\|\}])/gi, 'issn=$1');
  str = str.replace(/issn\s*=\s*n\/a\s*([\|\}])/gi, 'issn=$1');
  str = str.replace(/issn\s*=\s*needed\s*([\|\}])/gi, 'issn=$1');
  //Fix punctuation or word following
  str = str.replace(/(issn\s*=\s*\d\d\d\d)-*(\d\d\d[\dX])[\.\,\)]\s*([\|\}])/gi, '$1-$2 $3');
  str = str.replace(/issn\s*=\s*(\d\d\d\d)-*(\d\d\d[\dX])\s*\([a-z]+\)\s*([\|\}])/gi, 'issn=$1-$2 $3');
  //Fix letters before or after
  str = str.replace(/issn\s*=\s*[a-z,]+\s*(\d\d\d\d)-*(\d\d\d[\dX])\s*[\.\,\)\=]*\s*([\|\}])/gi, 'issn=$1-$2 $3');
  str = str.replace(/issn\s*=\s*\#\s*(\d\d\d\d)-*(\d\d\d[\dX])/gi, 'issn=$1-$2');
  str = str.replace(/issn\s*=\s*(\d\d\d\d)-*(\d\d\d[\dX])\s*[a-z]+\s*([\|\}])/gi, 'issn=$1-$2 $3');
  str = str.replace(/(issn\s*=\s*\d\d\d\d-*\d\d\d[\dX])[\;\,\s]*\([-a-z]+\)\s*([\|\}])/gi, '$1');
  //Fix extra "issn" after = 
  str = str.replace(/issn\s*=\s*issn[\s-:=]+(\d\d\d\d)-*(\d\d\d[\dX])\s*\([a-z]+\)\s*([\|\}])/gi, 'issn=$1-$2 $3');
  str = str.replace(/issn\s*=\s*issn[\s-:=]+(\d\d\d\d)-*(\d\d\d[\dX])/gi, 'issn=$1-$2');
  //Fix double issn
  str = str.replace(/(issn\s*=\s*\d\d\d\d-\d\d\d[\dX])[\;\,]\s+\d\d\d\d-\d\d\d[\dX]/gi, '$1');
  str = str.replace(/(issn\s*=\s*\d\d\d\d-\d\d\d[\dX])\s+\d\d\d\d-\d\d\d[\dX]/gi, '$1');
  str = str.replace(/(issn\s*=\s*\d\d\d\d-\d\d\d[\dX])\/\d\d\d\d-\d\d\d[\dX]/gi, '$1');
  str = str.replace(/(issn\s*=\s*\d\d\d\d-*\d\d\d[\dX])[\;\,\s]*\([-a-z]+\)\/*[\;\,\s]*\d\d\d\d-*\d\d\d[\dX]\s*\([-a-z]+\)\/*/gi, '$1');
  //Billboard USA ISSN
  str = str.replace(/issn\s*=\s*0005-*2510/gi, 'issn=0006-2510');
  str = str.replace(/issn\s*=\s*006-*2510/gi, 'issn=0006-2510');
  //Super Play ISSN
  str = str.replace(/issn\s*=\s*0966-*6199/gi, 'issn=0966-6192');
  //ISSN is actually an ISBN
  str = str.replace(/issn\s*=\s*(97[89][\d-]+\s*[\|\}])/gi, 'isbn=$1');
  //Royal Asiatic Society Hong Kong Branch
  str = str.replace(/issn\s*=\s*1990-*7295/gi, 'issn=1991-7295');
  //Replace Zilmer invalid ISSN with valid ISBN
  str = str.replace(/issn\s*=\s*1406-*2865/gi, 'isbn=9789949110896');
  
  return str;
}
 
function autoEdFunctions5() { //Activates individual modules when "auto ed" tab is clicked
    var txt = document.editform.wpTextbox1; //leave this value as 1
    txt.value = ReplaceISSN(txt.value);
}