User:Plastikspork/citetools.js

// --- Cite Template Functions --- // // // Convert some references to cite web templates function spork_cite_web(str){ // MONTH DD, YYYY or MONTH YYYY var smdy = "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(?:\.|[a-z]*)[,\. ]+(?:[0-9]{1,2}[,\. ]+|)[1-9][0-9]{3}"; // DD MONTH YYYY var sdmy = "[0-9]{1,2}[,\. ]+(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(?:\.|[a-z]*)[,\. ]+[1-9][0-9]{3}"; // YYYY-MM-DD var symd = "[1-9][0-9]{3}-[0-9]{1,2}-[0-9]{1,2}"; // Matches any date var matchdate = "\\(?(" + smdy + "|" + sdmy + "|" + symd + ")\\.?\\)?"; // Matchs [URL TITLE] var ut = "\\[(https?:[^\\| ]*)(?: | \\|[ ]*)([^<>\\[\\]\\|]*)\\]"; // Matches whitespace between fields var ws = "[:;\.,— ]+"; // Matches an author's name var au = "([A-Z][a-zî ]+(?:[, ]+|[ ]*[A-Z]\.[ ]*)[A-Z][a-z]+(?:[ ]*[A-Z]\.[ ]*))"; // Matches publisher string var pub = "[- ]*(?:from )*[ -]*[\"']*([^<>][^<>]*?)[\"']*"; // Unified formatting of accessdate string var s = new RegExp("(]*>[^<>]*) (?:URL last accessed|URL accessed|last accessed|last retrieved)[ ]*(?: on|,|)[ ]*" + matchdate, "gi"); str=str.replace(s, "$1 Retrieved on $2"); s.compile("(]*>[^<>]*) (?:accessed|retrieved)[ ]*(?: on|,|)[ ]*" + matchdate, "gi"); str=str.replace(s, "$1 Retrieved on $2"); // Match s.compile( "(]*>)[ ]*" + au + "[ ]*[\"']*[ ]*" + ut + "[\"']*" + ws + pub + ws + matchdate + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$8"); // Match s.compile( "(]*>)[ ]*" + au + ws + matchdate + ws + "[\"']*[ ]*" + ut + "[\"']*" + ws + pub + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$8"); // Match s.compile( "(]*>)[ ]*[\"']*[ ]*" + ut + "[\"']*" + ws + matchdate + ws + pub + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$7"); // Match s.compile( "(]*>)[ ]*" + matchdate + ws + "[\"']*[ ]*" + ut + "[\"']*" + ws + pub + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$7"); // Match s.compile( "(]*>)[ ]*[\"']*[ ]*" + ut + "[\"']*" + ws + pub + ws + matchdate + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$7"); // Match s.compile( "(]*>)[ ]*" + au + "[ ]*[\"']*[ ]*" + ut + "[\"']*" + ws + matchdate + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$7"); // Match s.compile( "(]*>)[ ]*[\"']*[ ]*" + ut + "[\"']*" + ws + matchdate + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$6"); // Match s.compile( "(]*>)[ ]*['\"]*[ ]*" + ut + "['\"]*" + ws + pub + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$6"); // Match s.compile( "(]*>)[ ]*['\"]*[ ]*" + ut + "['\"]*" + ws + "Retrieved on " + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$5"); // Match s.compile( "(]*>)[ ]*['\"]*[ ]*" + ut + "['\"]*" + ws + pub + ws + "(?:published)*" + ws + matchdate + "[:;\., ]*", "gi"); str=str.replace(s, "$1$6"); // Match s.compile( "(]*>)[ ]*['\"]*[ ]*" + ut + "['\"]*" + "[:;\., ]*", "gi"); str=str.replace(s, "$1$4"); // Match s.compile( "(]*>)[ ]*['\"]*[ ]*" + matchdate + ut + ws + "['\"]*" + ws + pub + "[:;\., ]*", "gi"); str=str.replace(s, "$1$6"); // Match s.compile( "(]*>)[ ]*['\"]*[ ]*" + matchdate + ut + ws + "['\"]*" + "[:;\., ]*", "gi"); str=str.replace(s, "$1$5");

return str; }

// Convert some references to cite journal templates function spork_cite_article(str) { // Match str=str.replace(/(]*>)([A-Z][a-zî ]+) ([A-Z][a-z]+) \(([12][0-9][0-9][0-9])\) "([^"<>]*)[, ]*"[, ]* ([^'<>]*), vol.(?: | )([0-9]+), pages(?: | )([0-9]+–?[0-9]*)\.?<\/ref>/g, '$1 '); //" // Match str=str.replace(/(<ref[^<>]*>)([A-Z][a-zî ]+) ([A-Z][a-z]+) \(([12][0-9][0-9][0-9])\) "([^"<>]*)[, ]*"[, ]* ([^'<>]*), vol.(?: | )([0-9]+), no.(?: | )([0-9]+), pages(?: | )([0-9\-]+)\.?<\/ref>/g, '$1 '); //"

return str; } //