User:Kirito (Kirigaya Kazuto)/global.js

// \ ';

/** * @variable [string] modal CSS */ QuickTools.formCSS = '\ display: none; \ -moz-border-radius: 10px; \ -moz-box-shadow: -3px 2px 9px 0 rgba(50, 50, 50, 0.81); \ -webkit-border-radius: 10px; \ -webkit-box-shadow: -3px 2px 9px 0 rgba(50, 50, 50, 0.81); \ background-color: #0175c7; \ border-radius: 10px; \ box-shadow: -3px 2px 9px 0 rgba(50, 50, 50, 0.81); \ height: auto; \ left: 25%; \ margin: 0; \ padding: 4px; \ position: fixed !important; \ top: 20%; \ width: 650px; \ z-index: 2000000004 !important; \ } \   -moz-border-radius: 4px; \ -webkit-border-radius: 4px; \ border-collapse: collapse; \ border-radius: 4px; \ height: 300px; \ margin-bottom: 3px; \ } \   border: 2px solid #fff !important; \ } \   height: auto; \ width: 100%; \ } \   color: #fff; \ float: left; \ font-family: "Times New Roman"; \ font-size: 170%; \ font-weight: bold; \ margin-top: 0; \ margin: 4px; \ } \   -moz-border-radius: 4px; \ -webkit-border-radius: 4px; \ -webkit-transition: background-color 1s; \ border-radius: 4px; \ border: 2px solid #fff; \ color: #fff; \ float: right; \ font-weight: bold; \ margin-top: 2px; \ margin: 4px; \ padding: 2px; \ padding-left: 4px; \ padding-right: 4px; \ transition: background-color: 1s; \ } \   background-color: #0061a6; \ cursor: pointer; \ } \   width: 100%; \ } \   height: 100%; \ margin: 0; \ padding: 0; \ width: 80%; \ } \   border-right: 1px solid #fff; \ height: 100%; \ margin: 0; \ overflow: auto; \ padding: 0; \ width: 20%; \ } \   height: 100%; \ list-style: none; \ margin: 0; \ padding: 0; \ } \   border-left: 1px solid #fff; \ height: 100%; \ width: 99%; \ padding: 8px 8px 8px 8px; \ color: #fff; \ font-weight: bold; \ } \   width: 96%; \ float: left; \ } \   width: auto; \ } \   border: 2px solid #FFF; \ width: 94%; \ height: 83px; \ padding: 4px; \ overflow: auto; \ } \ .QuickToolsLink { \ -webkit-transition: background-color 1s; \ border: 2px solid #fff; \ color: #fff; \ display: inline-block; \ font-weight: bold; \ margin: 3px; \ padding: 3px; \ transition: background-color: 1s; \ width: 87%; \ } \ .QuickToolsLink:hover { \ background-color: #0061a6; \ text-decoration: none; \ } \ .QuickToolsInput { \ background: transparent; \ border-bottom: 2px solid #fff !important; \ border-left: 2px solid #fff !important; \ border: none; \ color: #fff; \ font-weight: bold; \ margin: 4px; \ padding: 2px; \ } \ .QuickToolsInput:focus { \ outline: 0; \ }\ .QuickToolsSingleButton { \ -webkit-transition: background-color 1s; \ background-color: transparent; \ border: 2px solid #fff; \ color: #fff; \ font-weight: bold; \ margin: 2px; \ padding: 2px; \ text-decoration: none; \ transition: background-color: 1s; \ cursor: pointer; \ } \ .QuickToolsSingleButton:hover { \ background-color: #0061a6; \ text-decoration: none; \ cursor: pointer; \ }';
 * 1) QuickToolsModal { \
 * 1) QuickToolsWrapper { \
 * 1) QuickToolsWrapper, \
 * 2) QuickToolsWrapper>td, \
 * 3) QuickToolsWrapper>th, \
 * 4) QuickToolsWrapper > tr { \
 * 1) QuickToolsHead { \
 * 1) QuickToolsHeading { \
 * 1) QuickToolsClose { \
 * 1) QuickToolsClose:hover { \
 * 1) QuickToolsWrapper { \
 * 1) QuickToolsContext { \
 * 1) QuickToolsRail { \
 * 1) QuickToolsRail > ul { \
 * 1) QuickToolsDraw { \
 * 1) QuickToolsDraw hr { \
 * 1) QuickToolsDraw p { \
 * 1) QuickToolsStatus { \

/** * Adds even listeners to various UI components * * @function [args] none * @returns [] none */ QuickTools.addListeners = function { // Open button (tool bar) document.getElementById('QuickToolsOpen').addEventListener('click', function {       QuickTools.showHideModal;    });

// Close button (in modal) document.getElementById('QuickToolsClose').addEventListener('click', function {       QuickTools.showHideModal;    });

//All sidebar buttons $('#QuickToolsRail ul li').each(function {       $(this).click(function { switch ($(this).children('a').text.toLowerCase) { case 'batch delete': QuickTools.applet.showApplet('batch delete'); break; case 'block': QuickTools.applet.showApplet('block'); break case 'delete': QuickTools.applet.showApplet('delete'); break; case 'move': QuickTools.applet.showApplet('move'); break; case 'protect': QuickTools.applet.showApplet('protect'); break; default: QuickTools.applet.showApplet('home'); }       });    }); };

/** * Adds modal HTML and CSS to the body/head of the page * * @function [args] none * @returns [] none */ QuickTools.buildModal = function { $('body').append(QuickTools.formHTML); document.getElementsByTagName('head')[0].innerHTML += ' ' + QuickTools.formCSS + ' '; }; /** * Toggles the modals state on or off * * @function [args] none * @returns [] none * * @TODO: Replace with CSS animations */ QuickTools.showHideModal = function { if (QuickTools.modalShown == false) { $('#QuickToolsModal').fadeIn('slow'); QuickTools.modalShown = true; } else if (QuickTools.modalShown == true) { $('#QuickToolsModal').fadeOut('slow'); QuickTools.modalShown = false; } };

/** * Draws applet HTML to the applet context * * @function [args] [[string](applet): applet name] * @returns [] none */ QuickTools.applet.showApplet = function(applet) {   var applet = applet.replace(/ /g, '');

$('#QuickToolsDraw').html(QuickTools.applet.html[applet]);

if (applet !== 'home') { $('a[name=QuickToolsSubmit]').click(function {           QuickTools.applet[applet];        }); } };

/** * Creates an XHR request to the API * * @function [args] [[object](payload): API params] * @returns [[object](response data)] */ QuickTools.applet.post = function(payload, callback) {   $.ajax({        url: mw.util.wikiScript('api'),        type: "POST",        dataType: "JSON",        data: payload,        success: function(data) {            callback(data);        },        error: function(err, status) {            callback('FAILED ' + err + ':' + status);        }    }); };

/** * Creates an XHR request to the API * * @function [args] [[string](message): message to write] *                  [[bool](status): fail or success] * @returns [] none */ QuickTools.applet.writeOut = function(message, status) {    var html = $('#QuickToolsStatus').html;    var color = status === true ? 'white' : 'red';    var line = '> ' + message + ' ';

html += line;

$('#QuickToolsStatus').html(html); };

/** * Creates an XHR request to the API * * @function [args] none * @returns [] none */ QuickTools.applet.block = function { var payload = { action: 'block', user: $('input[name=QuickToolsBlock]').val, expiry: $('input[name=QuickToolsDuration]').val, reason: $('input[name=QuickToolsReason]').val, nocreate: '', allowusertalk: '', autoblock: 0, format: 'json', token: mw.user.tokens.values.editToken };

if (!$('input[name=QuickToolsNoCreate]:checked').length > 0) { delete payload.nocreate; }   if ($('input[name=QuickToolsNoTalk]:checked').length > 0) { delete payload.allowusertalk; }

QuickTools.applet.writeOut('attempting to block ' + payload.user + ' for ' + payload.expiry + '...', true);

QuickTools.applet.post(payload, function(data) {       if (typeof data === 'object') {            if (!data.error) {                QuickTools.applet.writeOut(payload.user + ' was blocked!', true);            } else {                QuickTools.applet.writeOut('block failed: ' + data.error.code, false);            }        } else {            QuickTools.applet.writeOut(result, false);        }    }); };

/** * Initializes script * * @function [args] none * @returns [] none */ QuickTools.init = function { if ($('#QuickToolsOpen').length > 0) { return; }

var link ='Quick Tools';

$('.toolbar > ul.tools').append(link); QuickTools.buildModal; QuickTools.addListeners; QuickTools.applet.showApplet('home'); };

$(document).ready(function {   QuickTools.init; }); //