User:Eurodyne/AutoEd/twoisbnparams.js

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.
//<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>