Jump to content

User:Sligocki/hatnotes.js

From Wikipedia, the free encyclopedia
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.
// Convert hatnotes
function autoEdHatnotes(str) {
 
  // {otheruses4|...} -> {about|...}
  str = str.replace(/\{\{\s*otheruses4\|([^\{\}]*)\}\}/gi, '{{About|$1}}');
  
  // {otheruses1|...} -> {about|...}
  str = str.replace(/\{\{\s*otheruses1\|([^\{\}]*)\}\}/gi, '{{About|$1}}');
  
  // {otheruses3|...} -> {otheruses|...}
  str = str.replace(/\{\{\s*otheruses3\|([^\{\}]*)\}\}/gi, '{{Otheruses|$1}}');
  
  // {otheruses8|FOO|BAR|BAZ} -> {about|FOO|other uses|BAR|and|BAZ}
  str = str.replace(/\{\{\s*otheruses8\|([^\{\}\|]*)\|([^\{\}\|]*)\|([^\{\}\|]*)\}\}/gi, '{{About|$1|other uses|$2|and|$3}}');
  
  // {this|FOO} -> {about|FOO}
  str = str.replace(/\{\{\s*this\|([^\{\}\|]*)\}\}/gi, '{{About|$1}}');
  
  // {this|FOO|BAR} -> {about|FOO||BAR}
  str = str.replace(/\{\{\s*this\|([^\{\}\|]*)\|([^\{\}\|]*)\}\}/gi, '{{About|$1||$2}}');
  
  
  // {This article is about|FOO. For other uses, see [[THIS]].} -> {about|FOO||THIS}
  str = str.replace(/\{\{\s*this article is about\|([^\{\}\|\.]*). For other uses, see\:? \[\[([^\{\}\|\]\[]*)\]\].?\}\}/gi, '{{About|$1||$2}}');
  
  // {This article is about|FOO. For BLAH, see [[THIS]].} -> {about|FOO|BLAH|THIS}
  str = str.replace(/\{\{\s*this article is about\|([^\{\}\|\.]*). For ([^\{\}\|]*), see\:? \[\[([^\{\}\|\]\[]*)\]\].?\}\}/gi, '{{About|$1|$2|$3}}');
  
  
  // {redirect1|FOO|BAR|[[BAZ]]} -> {redirect|FOO|BAR|BAZ}
  str = str.replace(/\{\{\s*redirect1\|([^\{\}\|]*)\|([^\{\}\|]*)\|\[\[([^\{\}\|]+)\]\]\}\}/gi, '{{Redirect|$1|$2|$3}}');
  
  // {redirect3|FOO|For BLAH, see [[THIS]]. For BLAH2, see [[THIS2]]} -> {redirect|FOO|BLAH|THIS|BLAH2|THIS2}
  // TODO: doesn't work yet.
  //str = str.replace(/\{\{\s*redirect3\|([^\{\}\|]*)\|\s*For ([^\{\}\|]*?),? ?see\:? \[\[([^\{\}\|\[\]]*)\]\].\s*For ([^\{\}\|]*?),? ?see\:? \[\[([^\{\}\|\[\]]*)\]\].\}\}/gi, '{{Redirect|$1|$2|$3|$4|$5}}');
  
  // {redirect3|FOO|For other uses, see [[THIS]].} -> {redirect|FOO||THIS}
  str = str.replace(/\{\{\s*redirect3\|([^\{\}\|]*)\|\s*For other uses,? ?see\:? \[\[([^\{\}\|\]\[]*)\]\].?\}\}/gi, '{{Redirect|$1||$2}}');
  
  // {redirect3|FOO|For BLAH, see [[THIS]].} -> {redirect|FOO|BLAH|THIS}
  str = str.replace(/\{\{\s*redirect3\|([^\{\}\|]*)\|\s*For ([^\{\}\|]*?),? ?see\:? \[\[([^\{\}\|\[\]]*)\]\].?\}\}/gi, '{{Redirect|$1|$2|$3}}');
  
  // {redirect5|FOO|BAR|BAZ} -> {redirect|FOO|BAR|BAZ}
  str = str.replace(/\{\{\s*redirect5\|([^\{\}\|]*)\|([^\{\}\|]*)\|([^\{\}\|]*)\|*\}\}/gi, '{{Redirect|$1|$2|$3}}');
  
  // {redirect5|FOO|BAR|BAZ|THAT|OTHER} -> {redirect|FOO|BAR|BAZ|THAT|OTHER}
  str = str.replace(/\{\{\s*redirect5\|([^\{\}\|]*)\|([^\{\}\|]*)\|([^\{\}\|]*)\|([^\{\}\|]+)\|([^\{\}\|]*)\|*\}\}/gi, '{{Redirect|$1|$2|$3|$4|$5}}');
  
  // {redirect5|TERM|USE|PAGE1||PAGE2} -> {redirect|TERM|USE|PAGE1|and|PAGE2}
  str = str.replace(/\{\{\s*redirect5\|([^\{\}\|]*)\|([^\{\}\|]*)\|([^\{\}\|]*)\|\|([^\{\}\|]*)\|*\}\}/gi, '{{Redirect|$1|$2|$3|and|$4}}');
  
  // {redirect8|FOO|BAR|BAZ|THAT} -> {redirect2|FOO|BAR|BAZ|THAT}
  str = str.replace(/\{\{\s*redirect8\|([^\{\}\|]*)\|([^\{\}\|]+)\|([^\{\}\|]*)\|([^\{\}\|]*)\|*\}\}/gi, '{{Redirect2|$1|$2|$3|$4}}');
  
  // {redirect8|FOO|BAR|BAZ|THAT|A|B} -> {redirect2|FOO|BAR|BAZ|THAT|A|B}
  str = str.replace(/\{\{\s*redirect8\|([^\{\}\|]*)\|([^\{\}\|]+)\|([^\{\}\|]*)\|([^\{\}\|]*)\|([^\{\}\|]*)\|([^\{\}\|]*)\|*\}\}/gi, '{{Redirect2|$1|$2|$3|$4|$5|$6}}');
  
  return str;
}
 
//