User:JoeSmack/reftagger.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:JoeSmack/reftagger. |
if(wgAction == 'edit' || wgAction == 'view') addOnloadHook(refbuttons)
function refbuttons() {
var yesref='/wiki/Special:Random';
if(wgAction == 'edit') {
var noref='javascript:reftag();';
} else {
var noref='javascript:edreftag();';
}
mw.util.addPortletLink('p-cactions',yesref,'y ref','ca-yesref','Go to random article');
mw.util.addPortletLink('p-cactions',noref,'n ref','ca-noref','tag with {{references}}');
}
function reftag() {
if(document.getElementById('wpTextbox1').value.indexOf('{'+'{references}}') != -1) {
alert('Warning: There is already a references tag present. \nNo action taken.');
return;
}
document.getElementById('wpTextbox1').value = '{'+'{references}}\n' + document.getElementById('wpTextbox1').value;
var saveme = confirm('A {'+'{references}} tag has been added to the top of this section.\nDo you want to save this page automatically?\n\nClick cancel/escape to abort, to move the tag, or to save manually.');
document.getElementById('wpSummary').value = '{{references}} - this article or section does not cite any references or sources. Please help improve this article by adding citations to [[WP:RS|reliable sources]].';
document.getElementById('wpMinoredit').checked = true;
// if(saveme) document.getElementById('wpPreview').click()
if(saveme) document.getElementById('wpSave').click()
}
function edreftag() {
var url = document.getElementById('ca-edit').firstChild.href;
document.location.href = url + '&addreftag=true';
}
if(queryString("addreftag") == "true") addOnloadHook(reftag);
function queryString(p) {
var re = RegExp('[&?]' + p + '=([^&]*)');
var matches;
if (matches = re.exec(document.location)) {
try {
return decodeURI(matches[1]);
} catch (e) {
}
}
return null;
}