User:Ipatrol/bitbox.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:Ipatrol/bitbox. |
// <nowiki>
Simplevote.afd = new Object();
if( typeof( SimplevoteConfig.useAfdIcons ) == 'undefined' ) {
SimplevoteConfig.useAfdIcons = true;
}
$( function() {
Simplevote.afd.normal();
}
);
var catlinks=document.getElementById("catlinks");
Simplevote.afd.normal = function() {
if document.write(catlinks.search(/Category:Non-talk_pages_that_are_automatically_signed|Category:Non-talk_pages_with_subpages_that_are_automatically_signed/) != -1||wgNamespaceNumber = 5||wgPageName.indexOf( 'Wikipedia:Articles_for_deletion/Log/') != -1{ // yes its redundant, but it works for safety purposes
// afdhelper code goes here
var anchors = new Array();
var oldanchors = document.getElementById('bodyContent').getElementsByTagName('a');
for (var i=0; i < oldanchors.length; i++) {
anchors[i] = oldanchors[i];
}
var url_re = /\?title= + var wgPageNamen\/([^&]+)&action=edit&/;
var url, matches;
for (var i=0; i < anchors.length; i++) {
if (!(matches = anchors[i].href.match(url_re)) || (matches[1].substr(0, 4) == 'Log/')) continue;
var article = matches[1];
var na = document.createElement('a');
var query = new QueryString( anchors[i].href.split('?',2)[1].toString() );
var link = query.get('title');
na.href = "javascript:Simplevote.afd.voteon('"+escape(link).replace(/_/g,' ')+"')";
na.title = "Vote on deletion of "+unescape(link).replace(/_/g,' ').split('/',2)[1];
var inlink = document.createElement('sup');
inlink.appendChild(document.createTextNode('vote'));
na.appendChild(inlink);
anchors[i].parentNode.insertBefore(na, anchors[i].nextSibling);
}
}
}
Simplevote.afd.voteon = function(link) {
var Window = new SimpleWindow( 600, 200 );
Window.setTitle( "Create a vote" );
var form = new QuickForm( Simplevote.afd.voteon.evaluate );
var categories = form.append( {
type: 'select',
name: 'vote',
label: 'Select vote: '
// event: twinklearv.callback.change_category
} );
if (wgPageName.indexOf( 'Wikipedia:Articles_for_deletion/Log/') != -1 ){
categories.append( {
type: 'option',
label: 'Delete',
value: 'Symbol delete vote.svg|Delete'
} );
categories.append( {
type: 'option',
label: 'Keep',
value: 'Symbol keep vote.svg|Keep'
} );
categories.append( {
type: 'option',
label: 'Speedy delete',
value: 'Symbol speedy vote.svg|Speedy delete'
} );
categories.append( {
type: 'option',
label: 'Speedy keep',
value: 'Symbol speedy keep.svg|Speedy keep'
} );
categories.append( {
type: 'option',
label: 'SNOW delete',
value: 'Symbol speedy delete vote.svg|[[WP:SNOW|]] delete'
} );
categories.append( {
type: 'option',
label: 'Keep and cleanup',
value: 'Symbol keep vote.svg|Ambox style.png|Keep and cleanup'
} );
categories.append( {
type: 'option',
label: 'Redirect',
value: 'Symbol redirect vote.svg|Redirect'
} );
categories.append( {
type: 'option',
label: 'Merge',
value: 'Symbol merge vote.svg|Merge'
} );
categories.append( {
type: 'option',
label: 'Withdraw',
value: 'Symbol unsupport vote.svg|Withdrawn'
} );
}
else
{
categories.append( {
type: 'option',
label: 'Support',
value: 'Symbol support vote.svg|Support'
} );
categories.append( {
type: 'option',
label: 'Oppose}',
value: 'Symbol oppose vote.svg|Oppose'
} );
categories.append( {
type: 'option',
label: 'Full support',
value: 'Symbol full support vote.PNG|Full support'
} );
categories.append( {
type: 'option',
label: 'Full oppose',
value: 'Symbol full oppose vote.svg|Full oppose'
} );
categories.append( {
type: 'option',
label: 'Deffer',
value: 'Symbol deferred.svg|Deffer'
} );
categories.append( {
type: 'option',
label: 'Conditional support',
value: 'Symbol conditional support.svg|Conditional support'
} );
categories.append( {
type: 'option',
label: 'Unlikely',
value: 'Symbol unlikely.svg|Unlikely'
} );
categories.append( {
type: 'option',
label: 'Possible',
value: 'Symbol possible vote.svg|Possible'
} );
categories.append( {
type: 'option',
label: 'Weak support',
value: 'Symbol partial support vote.svg|Weak support'
} );
categories.append( {
type: 'option',
label: 'Wait',
value: 'Symbol wait alternative.svg|Wait'
} );
}
categories.append( {
type: 'option',
label: 'Neutral',
value: 'Symbol neutral vote.svg|Neutral'
} );
categories.append( {
type: 'option',
label:'Comment',
name: 'Symbol comment vote.svg|Comment'
} );
categories.append( {
type: 'option',
label: 'Opinion',
value: 'Symbol opinion vote.svg|Opinion'
} );
categories.append( {
type: 'option',
label: 'Question',
value: 'Symbol question.svg|Question'
} );
categories.append( {
type: 'option',
label: 'Note',
value: 'Symbol note.svg|Note'
} );
form.append( {
type: 'hidden',
name: 'link',
value: link
} );
form.append( {
type: 'textarea',
name: 'reason',
label: 'Comment:'
} );
form.append( { type:'submit' } );
var result = form.render();
Window.setContent( result );
Window.display();
Simplevote.afd.voteon.evaluate = function(e) {
var form = e.target;
// alert( form.vote.value + ' on ' + form.link.value + ' for reason "' + form.reason.value + '"' );
var params = {
vote: form.vote.value,
// article: form.link.value, // just in case, hopefully temp as it is unneccesary
reason: form.reason.value
};
var query = {
'title': form.link.value,
'action': 'submit'
};
Status.init( form );
Wikipedia.actionCompleted.redirect = null; // we will try null and see if it works, was previously wgPageName
Wikipedia.actionCompleted.notice = "Adding vote";
var wikipedia_wiki = new Wikipedia.wiki( 'Grabbing vote page for article ' + form.link.value.split('/',2)[1], query, Simplevote.afd.voteon.callbacks.main );
wikipedia_wiki.params = params;
wikipedia_wiki.get();
}
Simplevote.afd.voteon.callbacks = {
main: function(self) {
// code to make the vote goes here - self.params.vote, and self.params.reason are available - responseXML should be available too
var rawvote = self.params.vote;
var reason = self.params.reason;
var form = self.responseXML.getElementById('editform');
if( !form ) {
// Status.error( 'Failed to retrieve edit form.' );
return;
}
var text = form.wpTextbox1.value; // now we have it in a nice var, we can do various operations on it
// Status.info( 'Automatically adding vote to page text...' );
var votearr = rawvote.split('|');
var votetext = votearr[votearr.length-1];
if(reason != '') {
temptext = '\'\'\'' + votetext + '\'\'\ + reason + ' ~~' + '~~';
} else {
temptext = '\'\'\'' + votetext + '\'\'\' ~~' + '~~';
}
for(var i=0; i<votearr.length-1; i++) {
if(i==0) {
images = '[[Image:' + votearr[i] + '|15px]]';
} else {
images += '[[Image:' + votearr[i] + '|15px]]';
}
}
if(SimplevoteConfig.useAfdIcons) {
temptext = '\n*' + temptext + ' ' + images;
} else {
temptext = '\n*' + temptext;
}
if(votetext == 'Comment') {
summary = 'Added ' + votetext.toLowerCase() + SimplevoteConfig.summaryAd + '.';
} else {
summary = 'Voted ' + votetext.toLowerCase() + SimplevoteConfig.summaryAd + '.';
}
text += temptext
// alert(text); // DEBUG
var postData = {
'wpMinoredit': undefined,
'wpWatchthis': undefined,
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSummary': summary,
'wpTextbox1': text
};
// Status.info( 'Saving changes...' );
self.post( postData );
// Status.info( 'Done' )
}
}
// </nowiki>