User:Sligocki/hatnotes.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:Sligocki/hatnotes. |
// 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;
}
//