User:Ost316/substLongComment.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:Ost316/substLongComment. |
// <nowiki>
//Script to tag pages with {{long comment}}
// Adapted from https://en.wikipedia.org/wiki/Wikipedia:autoEd/complete.js and https://en.wikipedia.org/wiki/Wikipedia:autoEd/core.js
function addLongComment() { //Activates individual modules when "substLC" tab is clicked
var $textbox = $( '#wpTextbox1' );
var txt = $textbox.textSelection('getContents');
txt = txt + "\n{{" + "subst:long comment}}";
$textbox.textSelection('setContents', txt);
}
//Initiates substLC
function substLCExecute() {
if(!document.getElementById('wpTextbox1')) return;
// copy wikEd ([[User:Cacycle/wikEd.js]]) frame to wpTextbox1 textarea
// for compatibility with WikiEd
if (typeof wikEdUseWikEd !== 'undefined') {
if (wikEdUseWikEd === true) {
WikEdUpdateTextarea();
}
}
//alert/return if substLCFunctions is not defined
if( typeof addLongComment === 'undefined' ) {
alert('addLongComment is undefined');
return;
}
addLongComment();
substLCEditSummary();
// copy wpTextbox1 textarea back to wikEd frame
// for compatibility with WikiEd
if (typeof wikEdUseWikEd !== 'undefined') {
if (wikEdUseWikEd === true) {
WikEdUpdateFrame();
}
}
}
//Adds Tag to edit summary textbox
function substLCEditSummary() {
var txt = document.forms.editform.wpSummary;
var tag;
if( typeof substLCTag === 'undefined' ) {
tag = '+{{' + 'subst:long comment}}';
} else {
tag = substLCTag;
}
// Is the tag blank?
if( tag.match(/[^\s]/) ) {
// Has it already been tagged?
if( txt.value.indexOf(tag) == -1 ) {
// Append a pipe if necessary
if( txt.value.match(/[^\*\/\s][^\/\s]?\s*$/) ) {
txt.value += ' | ';
}
// Append our tag
txt.value += tag;
}
}
// Check 'This is a minor edit'
if( typeof substLCMinor === 'undefined' || substLCMinor ) {
document.forms.editform.wpMinoredit.checked = true;
}
// Click 'Show changes'
if( typeof substLCClick === 'undefined' || substLCClick ) {
document.forms.editform.wpDiff.click();
}
}
// Add "substLC" tab and associate with actions
// Make sure the document is ready and our dependencies are loaded
$.when(
$.ready,
mw.loader.using(['mediawiki.util'])
).done(function () {
var $link;
//Execute substLC after call from "view mode"
if( mw.util.getParamValue('substLC') ) {
substLCExecute();
}
// Set default values for any unset variables
if( typeof substLCLinkHover === 'undefined' ) {
substLCLinkHover = "Run substLC";
}
if( typeof substLCLinkName === 'undefined' ) {
substLCLinkName = "substLC";
}
if( typeof substLCLinkLocation === 'undefined' ) {
substLCLinkLocation = "p-cactions";
}
// Add the "substLC" tab
if( document.getElementById('ca-edit') ) {
var url = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', substLC: 'true' });
$link = $(mw.util.addPortletLink(
substLCLinkLocation,
url,
substLCLinkName,
'ca-substLC',
substLCLinkHover,
'',
document.getElementById('ca-move')
));
if( typeof document.forms.editform !== 'undefined' ) {
$link.on('click', function (e) {
e.preventDefault();
substLCExecute();
});
}
}
}
);
//
// </nowiki>