User:Jonesey95/AutoEd/issn.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Jonesey95/AutoEd/issn. |
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);
}