User:Eurodyne/AutoEd/twoisbnparams.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:Eurodyne/AutoEd/twoisbnparams. |
//<source lang=javascript>
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 + 'core.js'); //Imports the "framework" script needed to make this function
//Sets variable configuration
autoEdTag = "Fixing [[Category:Pages with citations having redundant parameters|redundant ISBN parameters]] or [[Category:Pages with ISBN errors|ISBN error]] using [[WP:AutoEd|AutoEd]]"; //Tweaks edit summary
autoEdLinkName = "AutoEd dual ISBNs"; //Changes the link name at the top of the page
autoEdLinkHover = "Fix ISBN errors"; //When user hovers over link
//Set up function
function ReplacetwoISBNparams(str) { //function to remove erroneous ISBN parameter values
//Replace isbn= followed by isbn13=
str = str.replace(/(\|\s*isbn\s*=\s*)[\d-X]+\s*\|\s*isbn13\s*=\s*([\d-]+\s*[\}\|])/gi, '$1$2');
//Replace isbn= followed by isbn= (case insensitive)
str = str.replace(/(\|\s*isbn\s*=\s*)[\d-X]+\s*\|\s*isbn\s*=\s*([\d-]+\s*[\}\|])/gi, '$1$2');
//Replace isbn= followed by two ISBNs
str = str.replace(/(\|\s*isbn\s*=\s*)(97[89][\d-]+)[,\/;:\(]\s*[\d-X]+\)*\s*([\}\|])/gi, '$1$2$3');
str = str.replace(/(\|\s*isbn\s*=\s*)[\d-X]+\s*[,\/;:]\s*([\d-]+\s*[\}\|])/gi, '$1$2');
str = str.replace(/(\|\s*isbn\s*=\s*)[\d-X]+\s*[,;:\/]*\s*ISBN\s*([\d-]+\s*[\}\|])/gi, '$1$2');
str = str.replace(/(\|\s*isbn\s*=\s*)ISBN\s*[\d-X]+\s*[,;:\/]*\s*ISBN\s*([\d-]+\s*[\}\|])/gi, '$1$2');
str = str.replace(/(\|\s*isbn\s*=\s*)(97[89][\d-]+)\s\d\d\d\d\d\d\d\d\d[\dX]\s*([\}\|])/gi, '$1$2$3');
str = str.replace(/(\|\s*isbn\s*=\s*)\d\d\d\d\d\d\d\d\d[\dX]\s(97[89][\d-]+\s*[\}\|])/gi, '$1$2');
//Replace isbn= trailing or leading punctuation
str = str.replace(/(\|\s*isbn\s*=\s*[\d-X]+)[\.\,\;\)\*\/]\s*([\}\|])/gi, '$1$2');
str = str.replace(/(\|\s*isbn\s*=)=\s*([\d-X]+)\s*([\}\|])/gi, '$1$2$3');
//Change = and other separators to - in ISBN value
str = str.replace(/(\|\s*isbn\s*=\s*[\d- ]+)[=‐–—\.]([\d-X ]+)\s*([\}\|])/gi, '$1-$2$3');
str = str.replace(/(\|\s*isbn\s*=\s*[\d- ]+)[=‐–—\.]([\d- ]+)[=–—‐\.]([\d-X ]+)\s*([\}\|])/gi, '$1-$2-$3$4');
str = str.replace(/(\|\s*isbn\s*=\s*[\d- ]+)[=‐–—\.]([\d- ]+)[=–—‐\.]([\d- ]+)[=–—‐\.]([\d-X ]+)\s*([\}\|])/gi, '$1-$2-$3-$4$5');
str = str.replace(/(\|\s*isbn\s*=\s*[\d- ]+)[=‐–—\.]([\d- ]+)[=–—‐\.]([\d- ]+)[=–—‐\.]([\d-X ]+)[=‐–—\.]([\d- ]+)\s*([\}\|])/gi, '$1-$2-$3-$4-$5$6');
//Comment "n/a" or "unknown"
str = str.replace(/(\|\s*isbn\s*=\s*)(n\/a\s*)([\}\|])/gi, '$1<!--$2-->$3');
str = str.replace(/(\|\s*isbn\s*=\s*)(na\s*)([\}\|])/gi, '$1<!--$2-->$3');
str = str.replace(/(\|\s*isbn\s*=\s*)(unknown\s*)([\}\|])/gi, '$1<!--$2-->$3');
str = str.replace(/(\|\s*isbn\s*=\s*)(nk\s*)([\}\|])/gi, '$1<!--$2-->$3');
str = str.replace(/(\|\s*isbn\s*=\s*)(no isbn\s*)([\}\|])/gi, '$1<!--$2-->$3');
str = str.replace(/(\|\s*isbn\s*=\s*)(none\s*)([\}\|])/gi, '$1<!--$2-->$3');
str = str.replace(/(\|\s*isbn\s*=\s*)(none given\s*)([\}\|])/gi, '$1<!--$2-->$3');
str = str.replace(/(\|\s*isbn\s*=\s*)(unspecified\s*)([\}\|])/gi, '$1<!--$2-->$3');
str = str.replace(/(\|\s*isbn\s*=\s*)(\?+\s*)([\}\|])/gi, '$1<!--$2-->$3');
//Change case of trailing "x"
str = str.replace(/(\|\s*isbn\s*=\s*)([\d-]+)x(\s*[\}\|])/gi, '$1$2X$3');
//Remove extraneous trailing character
str = str.replace(/(\|\s*isbn\s*=\s*)([\d-X]+)[a-wyz](\s*[\}\|])/gi, '$1$2$3');
//Remove extraneous trailing text in parentheses
str = str.replace(/(\|\s*isbn\s*=\s*)([\d-X]+\s*)\([a-z -\;\,]+\.*\)(\s*[\}\|])/gi, '$1$2$3');
str = str.replace(/(\|\s*isbn\s*=\s*)[\d-X]+\s*\([a-z -\;\,]+\.*\)\s*[,\/;]\s*([\d-X]+\s*)\([a-z -\;\,]+\.*\)(\s*[\}\|])/gi, '$1$2$3');
str = str.replace(/(\|\s*isbn\s*=\s*)[\d-X]+\s*\([a-z -\;\,]+\.*\)\s*[,\/;]\s*ISBN\s*([\d-X]+\s*)\([a-z -\;\,]+\.*\)(\s*[\}\|])/gi, '$1$2$3');
//Comment any "ISBN" starting with 977 (probably a UPC)
str = str.replace(/(\|\s*isbn\s*=\s*977[\d-]+)(\s*[\}\|])/gi, '<!--$1-->$2');
//Replace isbn= followed by prefix
str = str.replace(/(\|\s*isbn\s*=\s*)13:* (97[89][\d-]+\s*[\}\|])/gi, '$1$2');
str = str.replace(/(\|\s*isbn\s*=\s*)10:* ([\d-X]+\s*[\}\|])/gi, '$1$2');
str = str.replace(/(\|\s*isbn\s*=\s*)ISBN1*0*3*:*\s*([\d-X]+\s*[\}\|])/gi, '$1$2');
//Replace Billboard "ISBN" with ISSN
str = str.replace(/\|\s*isbn\s*=\s*(0006-*2510\s*[\}\|])/gi, '\|issn=$1');
//Delete "please check ISBN" template
str = str.replace(/(\|\s*isbn\s*=\s*[\d-X]+\s*)\{\{Please check ISBN\|reason\=[a-z\d\s\.\(\)]+\}\}/gi, '$1');
//ISBN is really ISSN
str = str.replace(/\|\s*isbn\s*=\s*(\d\d\d\d-\d\d\d[\dX]\s*[\}\|])/gi, '\|issn=$1');
str = str.replace(/\|\s*isbn\s*=\s*issn\s*(\d\d\d\d-\d\d\d[\dX]\s*[\}\|])/gi, '\|issn=$1');
//ISBN is explicitly an ASIN
str = str.replace(/\|\s*isbn\s*=\s*ASIN\:*\s*([\da-z]+\s*[\}\|])/gi, '\|asin=$1');
//Whittaker Chambers, Witness
str = str.replace(/\|\s*isbn\s*=\s*52-5149\s*([\}\|])/gi, '\|lccn = 52005149 $1');
// try to work this in:
// ({{\s*[cC]it[ea](?:[^}{]*(?:\{\{[^}{]*}}[^}{]*)*)\|\s*)isbn(\s*=\s*)
return str;
}
function autoEdFunctions() { //Activates individual modules when "auto ed" tab is clicked
var txt = document.editform.wpTextbox1; //This stays as "Textbox1". Do not increment.
txt.value = ReplacetwoISBNparams(txt.value);
// txt.value = autoEdWhitespace(txt.value);
}
//</source>