User:Vacation9/NFURtag.js

// addOnloadHook(function { if (wgCanonicalNamespace != "File" && wgCanonicalNamespace != "Image"){   return; } mw.util.addPortletLink('p-tb', 'http://en.wikipedia.org/w/index.php?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=edit&section=2&tagNFUR=true', 'Image has rationale', 't-rationale', 'Set image has rationale=yes', 'Y'); if (location.href.indexOf("&action=edit&section=2&tagNFUR=true") == -1) return; if (document.getElementById('wpTextbox1').value.indexOf("{{Non-free") == -1 || document.getElementById('wpTextbox1').value.indexOf("rationale") != -1) return; templateRationale = /([^{]*{{[Nn]on(?:-| ).*)}}/; templateAfter = /{{.*(}}[\s\S]*)/; var template = templateRationale.exec(document.getElementById('wpTextbox1').value)[1]; var templateAfterExec = templateAfter.exec(document.getElementById('wpTextbox1').value)[1]; document.getElementById('wpTextbox1').value = template+"|image has rationale = yes"+templateAfterExec; document.getElementById('wpSummary').value = "image has rationale = yes"; document.getElementById('wpMinoredit').checked = true; document.getElementById('editform').submit; }); //