User:Ohconfucius/script/Sources.js: Difference between revisions

Content deleted Content added
mirroring test script
line spacing
 
(3 intermediate revisions by the same user not shown)
Line 14:
importScript("User:Ohconfucius/test/Sources_subscript2.js"); //Correctly casing titles and apply or rem italicisation
importScript("User:Ohconfucius/test/Sources_subscript3.js"); //link-fixing, dabbing etc
// importScript("User:Ohconfucius/script/foreigndates.js"); //link-fixing, dabbing etc
}
 
function Ohc_add_ref_tags() {
var txt=document.editform.wpTextbox1;
Line 37 ⟶ 38:
 
}
 
 
function Ohc_remove_urls() {
var txt=document.editform.wpTextbox1;
// warning-tagging template:Primary source inline
regex(/(<ref[^<>]*>[^<>]*\|[ ]*url ?= ?https?:\/\/(?:(?:www\.|mobile\.|)(?:blogger|blogspot|facebook|sites\.google|instagram|tiktok|twitter|wordpress|x)\.com|www\.formspring\.me)\/[^<>{]*<\/ref>)(?:\{\{Primary source inline\}\}|)/gi, '$1{{Primary source inline}}');
regex(/(<ref[^<>]*>[^<>]*\|[ ]*url ?= ?https?:\/\/(?:(?:www\.|)(?:myspace|findagrave)\.com)\/[^<>{]*<\/ref>)(?:\{\{Primary source inline\}\}|)/gi, '$1{{Primary source inline}}');
regex(/(<ref>\s*https?:\/\/(?:(?:www\.|)(?:blogger|blogspot|facebook|sites\.google|findagrave|instagram|myspace|tiktok|twitter|wordpress|x)\.com)\/[^\s\]<]*<\/ref>)(?:\{\{Primary source inline\}\}|)/gi, '$1{{Primary source inline}}');
regex(/(<ref>\s*\[https?:\/\/(?:(?:www\.|)(?:blogger|blogspot|facebook|sites\.google|findagrave|instagram|myspace|tiktok|twitter|wordpress|x)\.com)\/[^\s\]]*[ ]+[\w\d][^\]]*\]<\/ref>)(?:\{\{Primary source inline\}\}|)/gi, '$1{{Primary source inline}}');
regex(/(\{\{Primary source inline\}\})\1/gi, '$1');
 
// removing http links within publisher/journal/work fields
//
// regex(/(\|\s*(?:author|publisher|work) *= *)(?:https?:\/{2}|)(?:w{3}\.|)(\w+(?:\.(?:com?|net|org|gov|\w{2})|)(?:\.\w{2}|))(?:\/[^|}]*|)(?=\s*[\]|}])/gi, '$1$2'); //returns ___domain name
// regex(/(\|\s*title\s*\=)\s*)https?:\/{2}(?:w{3}\.|)(\w+\.com)(?=\s?(?:[=|{]|\}\}))/gi, '$1<!-- ACTUAL ARTICLE TITLE BELONGS HERE! original text: $2 -->');
// regex(/(\|\s*title\s*\=)\s*)https?:\/{2}([^|\s]+)(?=\s?(?:[=|{]|\}\}))/gi, '$1<!-- ACTUAL ARTICLE TITLE BELONGS HERE! original text: $2 -->');
// regex(/(\|\s*title\s*\=)\s*)(Archived copy)(?=\s?(?:[=|{]|\}\}))/gi, '$1<!-- ACTUAL'); ARTICLErem TITLEas BELONGScreating HERE!CS1 original text: $2 -->');errors
regex(/\s?<!--ACTUAL ARTICLE TITLE BELONGS HERE!(?: original text:|)[^>]*-->/gi, ' '); //rem error introduced by earlier version of this script; entirely strip title field
regex(/(\|\s*(?:author(?:link\d?|)|chapter|journal|magazine|newspaper|publisher|title|work|via)\s*\=\s*)https?:\/{2}(?:w{3}\.|)(?=\w)/gi, '$1'); //removes http:// and optionally www.
Line 88:
regex(/(\|\s*url\s*\=\s*)(https?:[^|{}#\s]+\.html?)\?[^|}]{1,5}(?=[\s\[\]|{}<>])/gi, '$1$2'); //rem link tracking
regex(/(\|\s*url\s*\=\s*|\[)(https?:\/\/books\.google\.[^\/]+\/books\?id=\w{12}&pg=PA\d{1,3})&dq[^\s|}]+(?=\s?[|}])/gi, '$1$2'); //rem browser optimisation
 
 
}
Line 110 ⟶ 109:
regex(/(\.\.\. |)\{\{!\}\} 立場(報道|新聞)/gi, '');
regex(/(\|\s*title\s*\=\s*)Login ?(?=[|}])/gi, '$1'); //creating deliberate error (blank title) per Trappist
 
regex(/(\|\s*)(?:publisher|website|work)=You ?tube(Newspapers\.com|Twitter|Vimeo|Youtube)(?:\.com|)(?=\s*[|}])/gi, '$1via=YouTube$2');
regex(/(\|\s*)(?:publisher|website|work)=(Amazon)(?:\.com|)(?:\.\w{2}|)(?=\s*[|}])/gi, '$1via=$2');
regex(/(\|\s*)(?:publisher|website|work)=(Vimeo\[\[Twitter\|𝕏\]\])(?: *\.com(Formerly (?:Twitter|\[\[Twitter\]\]\)) *|)(?=\s*[|}])/gi, '$1via=$2');
regex(/(\|\s*)(?:publisher|website|work)=(Newspapers\.com)(?=\s*[|}])/gi, '$1via=$2');
regex(/(\|\s*publisher=)\|\s?via\s*\=\s*(\w+)(?=\s*[|}])/gi, '$1$2');
regex(/(?:-[ ]*Google Books[ ]*(?:\|[^}]*|)|)\|\s?publisher\s*\=\s*(Google Books)(?=[\s\.]*[|}])/g, '|via=$1');
// regex(/(\|\s*)(?:publisher|website|work)=books\.google(?:\.com?|.co\.uk|)(?=\s*[|}])/gi, '|via=Google Books');
// regex(/\|\s?(?:publisher|website|work)=(British Newspaper Archive|Google Books|Project Gutenberg|Proquest|Scribd|web(?:\.archive\|citation)(?:\.org|))(?=\s*[|}])/gi, '|via=$1');
 
//Remove COinS corrupting templates from CS1 citations
Line 127 ⟶ 124:
regex(/(\|\s*dead-?url=no?)(?=\s*[|}])/gi, '|url-status=dead'); //common cs1 error (deprecated parameter)
 
// regex(/\{\{wikinews ?(|2|cat(?:egory)?|has|par2?|portal|table|-inline)(\|[^\}]+|)\}\}\s*/gi, '');
regex(/(\*[ ]*|)\[\[n:[^\]\|]*\]\][\r\n]*/gi, '');
// regex(/\*[ ]*\{\{(?:Facebook|Find a Grave|Myspace)\|([^}]*)\}\}[\n\r\s]*/gi, ''); //disabled 19 Sept 2015 per Batty's request
 
//citation template fixes
Line 143 ⟶ 138:
 
// rem toggles and redundant quote marks
regex(/(\|\s*(?:agency|author|newspaper|work|journal|publisher|title)\s*\=\s*)\'\'([^|}]+)\'\'(?=\s*[\}\|])/gi, '$1$2'); //without link //disabled 18/06/2022 per Jonesey
regex(/(\|\s*(?:agency|author|newspaper|work|journal|publisher|title)\s*\=\s*)\'\'(\[\[(?:[^\|]+\||)[^\|\]]+\]\])\'\'(?=\s*[\}\|])/gi, '$1$2'); //with link //disabled 18/06/2022 per Jonesey
regex(/(\|\s*title\s*\=\s*)\'&#39;([^\|\{\}]+)\'&#39;/gi, '$1$2'); //rem &#39; in titles
regex(/(\|\s*publisher\s*\=\s*)\(([^\|\{\}]+)\)/gi, '$1$2'); //rem parenthetical publishers
Line 187 ⟶ 182:
regex(/(?:\|[ ]*(?:agency|arxiv|asin|at|author(-?link|-mask|-name-separator|-separator|\d|\d-link|link\d?|)|bibcode|chapter|chapter-url|coauthors?|contribution(?:-url|)|date|deadurl|display-authors|doi|doi-inactive|doibroken|edition|(?:editor|translator)(?:-first|-last|-link|\d|\d-first|\d-last|\d-link)|(?:first|last)\d?|format|id|is[bs]n|issue|jfm|journal|jstor|language|lay(?:date|source|summary)|lccn|___location|magazine|day|month|mr|newspaper|nopp|oclc|ol|origyear|osti|others|pages?|periodical|place|pm[cd]|pmid|postscript|publisher|quote|ref|rfc|separator|series|ssrn|trans_title|type|url|volume|via|work|year|zbl)[ ]*=[\s]*)(?=[}|])/gi, '');
// regex(/(?:\|[ ]*(began|ended)[ ]*=[^}|]*)(?=[}|])/gi, ''); //disabled 18/06/20: false positive removal of associated (Start date) templates
regex(/(\|\s*work\s?\=\s?)\[\[iTunes\]\] Archive\s/gi, '|publisher=[[iTunes Store]]');
 
//rem underlining within certain fields
Line 225 ⟶ 220:
// (disabling for persistent errors) ohc_regex(/(?:Retrieved|Accessed)(?: on(?:line|)|):? (@Month\s@DD,?\s@YYYY|@DD\s@Month\s@YYYY|@yyyy-@mm-@dd)(?=\D)/gi, 'Retrieved $1');
ohc_regex(/(\w|\])[\.,;]?[ ]\((Retrieved (?:@Month\s@DD,\s@YYYY|@DD\s@Month\s@YYYY|@yyyy-@mm-@dd))\)/gi, '$1. $2');
 
// equivalence for French language cite web template
regex(/(\|)\s*auteur1\s*(?=\=)/gi, '$1author1');
regex(/(\|)\s*auteur2\s*(?=\=)/gi, '$1author2');
regex(/(\|)\s*citation\s*(?=\=)/gi, '$1quote');
regex(/(\|)\s*consulté le\s*(?=\=)/gi, '$1accessdate');
regex(/(\|)\s*éditeur\s*(?=\=)/gi, '$1publisher');
regex(/(\|)\s*langue\s*(?=\=)/gi, '$1language=fr');
regex(/(\|)\s*lienauteur1\s*(?=\=)/gi, '$1authorlink1');
regex(/(\|)\s*lieu\s*(?=\=)/gi, '$1place');
regex(/(\|)\s*lire en ligne\s*(?=\=)/gi, '$1place');
regex(/(\|)\s*nom1\s*(?=\=)/gi, '$1last1');
regex(/(\|)\s*nom2\s*(?=\=)/gi, '$1last2');
regex(/(\|)\s*périodique\s*(?=\=)/gi, '$1newspaper');
regex(/(\|)\s*prénom1\s*(?=\=)/gi, '$1first1');
regex(/(\|)\s*prénom2\s*(?=\=)/gi, '$1first2');
regex(/(\|)\s*site\s*(?=\=)/gi, '$1website');
regex(/(\|)\s*titre\s*(?=\=)/gi, '$1title');
 
regex(/(\{\{)\s*Lien web\s*(?=\|)/gi, '$1cite web');
regex(/(>)\{\{[,\.]\}\}(?=<)/gi, '$1');
regex(/\{\{date-\|([^\|]+)\|(\d{4})\-\}\}/gi, '$1 $2');
 
}
Line 320 ⟶ 293:
regex(/(\|)(The Advertiser)(?: \((Adelaide)\))(\]\])/g, '$1$2$4|___location=$3');
regex(/(\[\[)(The Advertiser)( \((Adelaide)\))(\]\])/g, '$1$2$3|$2$5|___location=$4');
regex(/(=[ ]*)(Apollo|Billboard|Brick|Campaign|Clash|Coda|Ebony|Esquire|Essence|Fanfare|Fast Company|Fortune|Glamour|Hello!|Life|Limelight|Maxim|Mojo|Mother Jones|New York|Nuts|Paste|People|Poetry|Q|Reason|Shape|Slate|Spin|Time(?: Out|)|Variety|Wired) \((?:magazine)\)(?=\s*[|}])/g, '$1$2'); //non-standard code
regex(/('')(Apollo|Billboard|Brick|Campaign|Clash|Coda|Ebony|Esquire|Essence|Fanfare|Fast Company|Fortune|Glamour|Hello!|Life|Limelight|Maxim|Mojo|Mother Jones|New York|Nuts|Paste|People|Poetry|Q|Reason|Shape|Slate|Spin|Time(?: Out|)|Variety|Wired) \(magazine\)(?='')/g, '$1$2'); //non-standard code
regex(/(\[\[(Apollo|Billboard|Brick|Campaign|Clash|Coda|Ebony|Esquire|Essence|Fanfare|Fast Company|Fortune|Glamour|Hello!|Life|Limelight|Maxim|Mojo|Mother Jones|New York|Nuts|Paste|People|Poetry|Q|Reason|Shape|Slate|Spin|Time(?: Out|)|Variety|Wired) \(magazine\))(?=\]\])/g, '$1|$2'); //non-standard code - tweaked to insert title per pipe trick
regex(/(\|)(Apollo|Billboard|Brick|Campaign|Clash|Coda|Ebony|Esquire|Essence|Fanfare|Fast Company|Fortune|Glamour|Hello!|Life|Limelight|Maxim|Mojo|Mother Jones|New York|Nuts|Paste|People|Poetry|Q|Reason|Shape|Slate|Spin|Time(?: Out|)|Variety|Wired)(?: \(magazine\))(?=\]\])/g, '$1$2');
regex(/(=[ ]*)(Empire) \((?:film magazine)\)(?=\s*[|}])/g, '$1$2'); //non-standard code
regex(/('')(Empire) \(film magazine\)(?='')/g, '$1$2'); //non-standard code
Line 329 ⟶ 302:
regex(/(=[ ]*\[\[(Empire) \(film magazine\))(?=\]\][ ]*\|)/g, '$1|$2'); //non-standard code (unique regex added 20/6/2021)
regex(/(\|)(Empire)(?: \(film magazine\))(?=\]\])/g, '$1$2');
 
//Journals
regex(/(=[ ]*)(Science|Nature) \((?:journal)\)(?=\s*[|}])/g, '$1$2'); //non-standard code
regex(/('')(Science|Nature) \(journal\)(?='')/g, '$1$2'); //non-standard code
regex(/(''\[\[(Science|Nature) \(journal\))(?=\]\]'')/g, '$1|$2'); //non-standard code
regex(/(\|)(Science|Nature)(?: \(journal\))(?=\]\])/g, '$1$2');
 
regex(/(=[ ]*)(Quartz) \((?:publication)\)(?=\s*[|}])/g, '$1$2'); //non-standard code
regex(/('')(Quartz) \(publication\)(?='')/g, '$1$2'); //non-standard code
regex(/(''\[\[(Quartz) \(publication\))(?=\]\]'')/g, '$1|$2'); //non-standard code
regex(/(\|)(Quartz)(?: \(publication\))(?=\]\])/g, '$1$2');
regex(/(=[ ]*)(Salon) \((?:website)\)(?=\s*[|}])/g, '$1$2'); //non-standard code
regex(/('')(Salon) \(website\)(?='')/g, '$1$2'); //non-standard code
regex(/(''\[\[(Salon) \(website\))(?=\]\]'')/g, '$1|$2'); //non-standard code
regex(/(\|)(Salon)(?: \(website\))(?=\]\])/g, '$1$2');
regex(/(=[ ]*)(Stuff) \((?:company)\)(?=\s*[|}])/g, '$1$2'); //non-standard code
regex(/('')(Stuff) \(company\)(?='')/g, '$1$2'); //non-standard code
regex(/(''\[\[(Stuff) \(company\))(?=\]\]'')/g, '$1|$2'); //non-standard code
regex(/(\|)(Stuff)(?: \(company\))(?=\]\])/g, '$1$2');
Line 376 ⟶ 355:
regex(/(''The Herald) \((Glasgow)\)('')/g, '$1$3 ($2)');
regex(/(\|)(The Herald)(?: \(Glasgow\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*The Mercury) \((Hobart)\)(\s*[|}])/g, '$1|___location=$2$3');
regex(/(''The Mercury) \((Hobart)\)('')/g, '$1$3 ($2)');
regex(/(\|)(The Mercury)(?: \(Hobart\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*Metro) \((British newspaper)\)(\s*[|}])/g, '$1|___location=UK$3');
regex(/(''Metro) \((British newspaper)\)('')/g, '$1$3 (UK)');
Line 565 ⟶ 547:
// regex(/(<ref name=[^/>"]*)>([\s\S]*)\1>/gi, '$1A>$2$1B>');
// regex(/(<ref name="[^/>]*)">([\s\S]*)\1>/gi, '$1A>$2$1B">');
 
}
 
Line 598 ⟶ 581:
regex(/((?:[\[=]\s*)(?:https?:|ftp:))([^\]\|\}]*)(\s*[\]|}])/gi, protect_function);
regex(/((?:Category|Image|File):)([^|\]]*)([|\]])/gi, protect_function); //protect file names from being changed
regex(/(\{\{(?:FAA-airport|harv\w*|sfn\w*|cite ?book|listen)\s?\|)([^\}]+)(\}\})/gi, protect_function);
regex(/(\|\s*(?:contribution|quote|title)\s*=)([^|}]+)([\|\}])/gi, protect_function);
 
//whitelisting -against changes made by generic regex in Ohc_sourcepub (e.g. Fast Company)
Line 605 ⟶ 588:
 
}
 
 
function ohc_unprotect_urls()
Line 644 ⟶ 626:
ohc_protect_urls();
Ohc_sources_prep();
// ohc_foreign_dates();
Ohc_unpipe();
Ohc_dab_news_sources();
Line 655 ⟶ 637:
Ohc_sources_cleanup();
ohc_unprotect_urls();
 
 
Ohc_Source_edit_summary();
Line 664 ⟶ 645:
 
// removing references to other WP articles and 'external' WP links
regex(/<ref[^<>]*>[^<>]*\|[ ]*url ?= ?https?:\/\/(?:\w{2}\.wikipedia\.org\/wiki|(?:www\.|)(?:blogger|blogspot|facebook|myspacefindagrave|twitterinstagram|mailonline|findagravemyspace|twitter|x)\.com)\/[^<>]*<\/ref>/gi, '');
regex(/<ref>https?:\/\/(?:en\.wikipedia\.org\/wiki|(?:www\.|)(?:blogger|blogspot|facebook|myspacefindagrave|twitterinstagram|mailonline|findagravemyspace|twitter|x)\.com)\/[^\s\]<]*<\/ref>/gi, '');
regex(/<ref>\[https?:\/\/(?:en\.wikipedia\.org\/wiki|(?:www\.|)(?:blogger|blogspot|facebook|myspacefindagrave|twitterinstagram|mailonline|findagravemyspace|twitter|x)\.com)\/[^\s\]]*[ ]+[\w\d][^\]]*\]<\/ref>/gi, '');
regex(/\|[ ]*url[ ]*=[ ]*https?:\/\/(?:\w{2}\.wikipedia\.org\/wiki|(?:www\.|)(?:blogger|blogspot|facebook|myspacefindagrave|twitterinstagram|mailonline|findagravemyspace|twitter|x)\.com)[^\s\|\{\}<]*(?=[ ]*[|}])/gi, '');
 
 
regex(/[ ]\[https?:\/\/en\.wikipedia\.org\/wiki\/[^\s\]]*[ ]+([\w][^\]]*)\]/gi, ' [[$1]]');
Line 676 ⟶ 656:
function ohc_ref_names() {
// give names to citations in templates that are without names
regex(/<ref>((?:[^<>]*\|w,\s*url\s*=|[.&]+\"?\[\s]?)https?:\/\/(?:[^|</]+\.)*(\w+)\.(?:(?:com?|org|net|gov|ac)(?:\.[a-z]{2}|))\/(?:[^<>|{}\d]*\D|)(\d{6,12})[^<>]*)(?=<\/ref>)/gi, "<ref name=$22_$3>$1"); //urls with non-date serial numbers
regex(/<ref>((?:[^<>]*\|\s*url\s*=|[\[\s]?)https?:\/\/(?:[^|</]+\.)*([-\w]+)\.(?:(?:com?|org|net|gov|ac)(?:\.[a-z]{2}|))\/(?:[^<>|{}\d]*\D|)(\d{6,12})[^<>]*)(?=<\/ref>)/gi, "<ref name=$22_$3>$1"); //urls with non-date serial numbers
regex(/<ref>((?:[^<>]*\|\s*url\s*=|[\[\s]?)https?:\/\/(?:[^|</]+\.)*([-\w]+)(?:\.[a-z]{2})\/[^<>|{}\d]*(\d{6,12})[^<>]*)(?=<\/ref>)/gi, "<ref name=$2_$3>$1"); //urls with non-date serial numbers
 
regex(/<ref>((?:[^<>]*\|\s*url\s*=|[\[\s]?)https?:\/\/(?:[^|</]+\.)*(reuters)\.com\/[^<>|{}\d]*(id\w{11})[^<>]*)(?=<\/ref>)/gi, "<ref name=$2_$3>$1"); //reuters urls with non-date serial numbers
ohc_regex(/<ref>((?:[^<>]*\|\s*url\s*=|[\[\s]?)https?:\/\/(?:[^|</]+\.)*([-\w]+)(?:\.[a-z]{2,3})\/[^<>|{}\d]*@YYYY[-\/]@MM[-\/]@DD\/(\w+)[^<>]*)(?=<\/ref>)/gi, "<ref name=$2_@Year@ZM@ZD$2-ZD_$3>$1"); //urls with non-date serial numbers
ohc_regex(/<ref>((?:[^<>]*\|\s*url\s*=|[\[\s]?)https?:\/\/(?:[^|</]+\.)*([-\w]+)(?:\.[a-z]{2,3})\/[^<>|{}\d]*@YYYY[-\/]@MonthMon[-\/]@DD\/(\w+)[^<>]*)(?=<\/ref>)/gi, "<ref name=$2_@Year@ZM@ZD$2-ZD_$3>$1"); //urls with non-date serial numbers
 
ohc_regex(/<ref>([^<>]*\|\s*url\s*=https?:\/\/(?:[^|</]+\.)*(\w+)\.(?:(?:com?|org|net|gov|ac|)(?:\.[a-z]{2}|))\/[^<>]*\|\s*date\s*=\s*@Day @Month @YYYY\s*[|}][^<>]*)(?=<\/ref>)/gi, "<ref name=$2_@Year@ZM@ZD$2>$1");
ohc_regex(/<ref>([^<>]*\|\s*url\s*=https?:\/\/(?:[^|</]+\.)*(\w+)\.(?:(?:com?|org|net|gov|ac|)(?:\.[a-z]{2}|))\/[^<>]*\|\s*date\s*=\s*@Month @Day, @YYYY\s*[|}][^<>]*)(?=<\/ref>)/gi, "<ref name=$2_@Year@ZM@ZD$2>$1"); //this line may cause unwarranted substitution of "$5" by a comma (e.g. in 2019–20 Hong Kong protests)
ohc_regex(/<ref>([^<>]*\|\s*url\s*=https?:\/\/(?:[^|</]+\.)*(\w+)\.(?:(?:com?|org|net|gov|ac|)(?:\.[a-z]{2}|))\/[^<>]*\|\s*date\s*=\s*=\s*@YYYY-@MM-@DD\s*[|}][^<>]*)(?=<\/ref>)/gi, "<ref name=$2_@Year@MMZM@DD$2ZD>$1");
ohc_regex(/<ref>((?:[^<>]*\|\s*url\s*=|\[?)https?:\/\/(?:[^|<]+\.)*(\w+)\.(?:(?:com?|org|net|gov|ac|[a-z]{2})(?:\.[a-z]{2}|))\/[^<>|{}]+@YYYY[\/-]?@Month[\/-]?@Day[^<>]*)(?=<\/ref>)/gi, "<ref name=$2_@YYYYYear@MMZM@DD$2ZD>$1"); //urls with embedded dates
 
}
 
function prevDef ( e ) {
e.preventDefault();
}
 
function addLinks() {