User:Dinoguy1000/scripts/delsort.js
Appearance
< User:Dinoguy1000 | scripts
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:Dinoguy1000/scripts/delsort. |
/******************************************************************************
* *
* [[Help:Substitution|Substituted]] from [[Template:Deltab]], which was *
* apparently based on code by [[User:Raylu|Raylu]]. Includes generalizations *
* from [[User:Pb30/Delsort tab/delsort.js]] and code snippets from *
* [[Wikipedia:AutoEd|AutoEd]] (and random stuff from other places, *
* identified inline). *
* *
* Some discussion can be found at [[User talk:Ioeth/Archive 6#JS request]]). *
* *
* This script adds a "sort deletion" tab to the top of XfD pages. *
* *
*****************************************************************************/
function addDelsortMessage() {
var action = mw.config.get( "wgAction" );
if( action == 'view' ){
window.location.href = mw.config.get( "wgServer" ) + mw.config.get( "wgScript" ) + '?title=' + encodeURIComponent( mw.config.get( "wgPageName" ) ) + '&action=edit';
}
//prompt for 'type', the name of the delsort list
if( action == 'edit' || action == 'submit' ){
var type = prompt('Enter category');
type = type.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); //trim1 from [http://blog.stevenlevithan.com/archives/faster-trim-javascript]
if( type === null || type.length === 0 || type === 'undefined' ){ return; }
//grab page elements and define vars
var txt = document.forms.editform.wpTextbox1;
var newTxt = '\n\{\{subst:deletion sorting|' + type + '|— \~\~\~\~\}\}\n';
var desc = document.forms.editform.wpSummary;
var newDesc = 'tagged as a ' + type + '-related XfD discussion ([[User:Dinoguy1000/scripts/delsort.js|script-assisted]]).';
//add notice to text
if( txt.value.indexOf(newTxt) == -1 && txt.value.indexOf('This debate has been included in the [[Wikipedia:WikiProject Deletion sorting\/' + type) == -1 ) {
txt.value = txt.value.rtrim();
txt.value += newTxt;
} else {
alert('This debate has already been tagged as a ' + type + '-related XfD discussion.');
return;
}
//add notice to summary
if( newDesc.match(/[^\s]/) ) {
if( desc.value.indexOf(newDesc) == -1 ) {
if( desc.value.match(/[^\*\/\s][^\/\s]?\s*$/) ){ desc.value += " | "; }
desc.value += newDesc;
}
}
//minor edit checked, but don't autosubmit
document.forms.editform.wpMinoredit.checked = true;
//document.forms.editform.submit();
}
}
jQuery( function( $ ) {
var action = mw.config.get( "wgAction" ),
ns = mw.config.get( "wgNamespaceNumber" ),
title = mw.config.get( "wgTitle" );
/*
if( ns == 4 && title.match( / for d(elet|iscuss)ion/ ) &&
( ( title.match( /(Articles|Miscellany) for deletion/ ) != -1 && action == 'view' ) ||
action == 'edit' || action == 'submit' ) ) {
if( typeof( document.forms.editform ) != 'undefined' ) {
mw.util.addPortletLink( 'p-cactions', 'javascript:addDelsortMessage()', 'Sort deletion', 'ca-SortDeletion', 'Sort Deletion', '', document.getElementById('ca-move'));
} else if (wgIsArticle && $('#ca-edit') && action == "view") {
var url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=edit';
mw.util.addPortletLink( 'p-cactions', url + '&DelSort=true', 'Sort deletion', 'ca-SortDeletion', 'Sort Deletion', '', $('#ca-move'));
}
}
*/
if( ns == 4 && title.match( / for d(elet|iscuss)ion/ ) &&
( ( title.match( /(Articles|Miscellany) for deletion/ ) != -1 && action == 'view' ) ||
action == 'edit' || action == 'submit' ) ) {
// if( !$( '.xfd-closed' ) ||
// ( ( action == 'edit' || action == 'submit' ) &&
// document.forms.editform.wpTextbox1.value.indexOf( 'xfd-closed' ) == -1 ) ) {
mw.util.addPortletLink( 'p-cactions', 'javascript:addDelsortMessage()', 'Sort deletion', 'ca-Sortdeletion', 'Sort Deletion', '' );
// }
}
} );