User:Date delinker/City state.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
function city_state() {
var txt=document.editform.wpTextbox1;
//citation template fixes
// txt.value=txt.value.replace(/\[\[((city), (state))\]\]/gi, '$1');
// txt.value=txt.value.replace(/(\[\[city)]], [[(state\]\])/gi, '$1, $2');
txt.value=txt.value.replace(/\[\[(?:Sydney\,(?:\sNew South Wales|\sAustralia)|Sydney)\|([^\]]{1,30})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[Netherlands\|(Dutch)\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[Republic of Ireland\|(Ireland|Irish)\]\]/gi, '$1');
// US States piped
txt.value=txt.value.replace(/\[\[(Chicago|Detroit|Hawai.?i|Los\sAngeles|Miami|New\sYork|New\sYork\sCity|San\sFrancisco)\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[((?:Los Angeles|San\sDiego|San\sFrancisco), (?:California|CA))\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[(?:Los\sAngeles\,\sCalifornia|Los\sAngeles, CA)\|([^\]]{1,30})\]\]/gi, '$1');
// txt.value=txt.value.replace(/(\[\[Vancouver)\]\], \[\[(British Columbia\]\])/gi, '$1, $2');
//US txt.value=txt.value.replace(/\[\[([^\]]{1,20})\,\s(AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY|Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming)\|([^\]]{1,20})\]\]\,?\s\[\[(Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming)\]\]/gi, '[[$1, $2]]');
//Canada
txt.value=txt.value.replace(/\[\[([^\]]{1,20})\,\s(AB|Alta\.?|B\.?C\.?|Man\.?|MB|N\.?B\.?|N\.?S\.?|Nfld\.?, Lab\.?|NL|ON|Ont\.?|P\.?E\.?I\.?|PE|QC|Que\.?, P\.?Q\.?|Sask\.?|SK|Alberta|British Columbia|Manitoba|New Brunswick|Newfoundland and Labrador|Nova Scotia|Ontario|Prince Edward Island|Quebec|Saskatchewan)\|([^\]]{1,20})\]\]\,?\s\[\[(Alberta|British Columbia|Manitoba|New Brunswick|Newfoundland and Labrador|Nova Scotia|Ontario|Prince Edward Island|Quebec|Saskatchewan)\]\]/gi, '[[$1, $2]]');
// Add a tag to the summary box
var txt=document.editform.wpSummary;
var summary = "Refs style";
if (txt.value.indexOf(summary) == -1) {
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
txt.value += " | ";
}
txt.value += summary;
}
// document.forms.editform.wpMinoredit.checked = true;
// document.editform.wpDiff.click();
}
$(function () {
if(document.forms.editform) {
mw.util.addPortletLink('p-tb', 'javascript:city_state()', 'Amalg city-state', 't-citefix', 'format citations', '', '');
}
});