User:Quarl/automod.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. |
![]() | This user script seems to have a documentation page at User:Quarl/automod. |
// User:Quarl/automod.js
// requires: wikipage.js, util.js
// based on http://wiki.riteme.site/wiki/User:Jnothman/automod.js
// - added 'amnocreate'
// - fixed escape '+' bug
//<pre><nowiki>
if ((typeof auto_mod_loaded == 'undefined')
|| !auto_mod_loaded) {
auto_mod_loaded = true;
auto_mod_exectd = false;
function am_make_url(title, before, after, summary) {
return 'http://wiki.riteme.site/w/index.php?title='+wpaescape(title)+
'&action=edit'+
'&amaddbefore='+escape(before)+'&amaddafter='+escape(after)+
'&amsummary='+escape(summary);
}
function auto_mod() {
if (auto_mod_exectd)
return false;
auto_mod_exectd = true;
if (queryVars['action']=='edit') {
if (queryVars['amnull']) {
document.getElementById('editform').submit();
return true;
}
if (queryVars['amaddafter'] || queryVars['amaddbefore'] || queryVars['amreplace']) {
var summ_el = document.getElementById('wpSummary');
if (summ_el.value != '' && summ_el.value.substr(summ_el.value.length - 3, 3) != '*/ ') {
// have already added summary
return true;
}
var text = document.getElementById('wpTextbox1');
if (queryVars['amnocreate'] && ! text.value) {
alert("Error! Page is empty; refusing to create.");
return false;
}
if (queryVars['amclear'])
text.value = '';
if (queryVars['amfind'] && queryVars['amreplace'])
text.value = text.value.replace(new RegExp(queryVars['amfind'], "g"), queryVars['amreplace']);
if (queryVars['amaddafter']) {
if (text.value.charAt(text.value.length-1) != '\n')
text.value += '\n';
text.value += queryVars['amaddafter'];
}
if (queryVars['amaddbefore']) {
if (text.value.charAt(0) != '\n')
text.value = '\n' + text.value;
text.value = queryVars['amaddbefore'] + text.value;
}
summ_el.value += (queryVars['amsummary'] || ' ');
document.getElementById('editform').submit();
}
return true;
}
return false;
}
addOnloadHook(auto_mod);
} // end if auto_mod_loaded
// </nowiki></pre>