Jump to content

User:Btilm/stub.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.
// <nowiki>
function startstub() {
if (location.href.indexOf('&action=edit&stub') == -1) return;
var editb = document.editform.wpTextbox1.value;
var str = /\n(\n)?{{.*stub}}/
var result = str.test(editb);
if (result==false)
  addit();
 else
  removeit();
}

function stub() {
var encode=encodeURIComponent(mw.config.get('wgPageName'))
document.location=mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + encode + "&action=edit&stub";
}
 
function addit() { 
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + '\n\n{{stub}}';
addede=true;
end1()}

function removeit() {
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/\n(\n)?{{.*stub}}/, "");
addede=false;
end1()}

function end1() {
var addremove;
if (addede==true) 
 addremove = 'Added'
else
 addremove = 'Removed'
document.editform.wpSummary.value = addremove + ' stub tag.';
document.editform.wpMinoredit.checked = false;
document.editform.submit();}

$(function() {
mw.util.addPortletLink("p-cactions", "javascript:stub()", "±stub", "ca-stub", "Add stub tag.", "");
startstub()
});
// </nowiki>