MediaWiki:DiscussionsBlock.js

$(function { disBlock = {};  disBlock.init = function {    var disBlInterval1, disBlInterval2;    // Check on dash events, if the person is on a /d/u page, if there's no block button, add    document.addEventListener('animationstart', function (event) { if (event.animationName != "dash") return; timeoutKill('disBlInterval1'); disBlInterval1 = setInterval(function {       if (window.location.pathname.indexOf('/d/u') > -1 && $(".discussions-button").length === 0) {          clearInterval(disBlInterval1);          disBlock.preload;        }      }, 500); });   // On page load, check if they are at /d/u and the button isn't there    disBlInterval2 = setInterval(function { if (window.location.pathname.indexOf('/d/u') > -1 && $(".discussions-button").length === 0) { clearInterval(disBlInterval2); disBlock.preload; }   }, 500);    timeoutKill('disBlInterval2');    // Kills an interval after 5 secs so it doesn't clog up    function timeoutKill(intName) {      setTimeout(function { clearInterval(intName); }, 7000);   }  };

disBlock.preload = function(i18n) { $.getScript("//dev.wikia.com/index.php?title=MediaWiki:DiscussionsBlock.css&action=raw&ctype=text/css"); $.getScript("//dev.wikia.com/index.php?title=MediaWiki:I18n-js/code.js&action=raw&ctype=text/js");

$.when(     i18n.loadMessages('DiscussionsBlock')    ).then(disBlock.addButton); };

disBlock.addButton = function(i18n, data) { disBlock.i18n = i18n; $('.ember-view .discussion-moderator-tools').append(     "" +         "" +         " " + disBlock.i18n.msg('block').escape  + " " +       " "    ); $('.discussions-button').on('click', function {     disBlock.onClick;    }); };

disBlock.onClick = function {

$('.discussion-wrapper > .ember-view > .discussion-dialog').addClass('is-visible').removeAttr('style').append(     ' ' +        ' ' +        ' ' +          ' ' +          ' Block ' +          ' ' +          ' ' +            '' + disBlock.i18n.msg("cancel").escape  + ' ' +            '' + disBlock.i18n.msg("block-exclamation") + ' ' +          ' ' +        ' ' +      ' '    ); disBlock.populateBoxes; disBlock.onChange; $(".disBlock-cancel-button").on("click", function {     $('.discussions-block-dialogue').removeClass('is-visible').css('display', 'none').empty;    }); $(".disBlock-confirm-button").on("click", function {     disBlock.block;    }); }; disBlock.populateBoxes = function { var mwExpiry, mwReasons, mwDisableUserTalk, mwEnableAutoBlock, mwWatchUser, mwHardBlock; $.get('/api.php', {       action: 'query',        format: 'json',        meta: 'allmessages',        ammessages: 'Ipboptions|Ipbreason-dropdown|Ipb-disableusertalk|Ipbenableautoblock|Ipbwatchuser|Ipb-hardblock|Ipbexpiry|Ipbreason|htmlform-selectorother-other'    }).done(function(d){        mwExpiry = d.query.allmessages[0]['*'];        mwReasons = d.query.allmessages[1]['*'];        mwDisableUserTalk = d.query.allmessages[2]['*'];        mwEnableAutoBlock = d.query.allmessages[3]['*'];        mwWatchUser = d.query.allmessages[4]['*'];        mwHardBlock = d.query.allmessages[5]['*'];        mwExpiry = d.query.allmessages[6]['*'];        mwReason = d.query.allmessages[7]['*'];        mwOther = d.query.allmessages[8]['*'];        $("#disBlock-expiry").innerHTML(mwExpiry);        $("#disBlock-reason").innerHTML(mwReason);        $("#disBlock-other").innerHTML(mwOther);        $("#disBlock-disable-meswall").after("" + mwDisableUserTalk + " "); $("#disBlock-block-ip").after("" + mwEnableAutoBlock + " "); $("#disBlock-watch-pages").after("" + mwWatchUser + " "); $("#disBlock-prevent-logged").after("" + mwHardBlock + " "); mwExpiry = mwExpiry.split(','); mwExpiry.forEach(function(time) {         realTime = time.replace(/^(.*):.*$/, "$1");          textTime = time.replace(/^.*:(.*)$/, "$1");          $("#disblock-expiry-dropdown").append("" + textTime + " ");        }); mwReasons = mwReasons.split('\n'); mwReasons.forEach(function(reason) {         if (reason.match(/^\*\b.*/)) {            $("#disBlock-reason-choices").append("");          } else {            $("#disBlock-reason-choices > optgroup").last.append("" + reason.replace(/^\*\*\s?(.*)$/, "$1") + " ");          }        }); }); };  disBlock.onChange = function {    $("#disblock-expiry-dropdown").change(function { if ($("#disblock-expiry-dropdown").val != "other") { $("#disBlock-expiry-choices-other").hide(600); } else { $("#disBlock-expiry-choices-other").show(600); }   });  };  disBlock.block = function {    var expiry         = $("#disblock-expiry-dropdown").val,        expiryOther    = $("#disBlock-expiry-choices-other").val,        reasonMenu     = $("#disBlock-reason-choices").val,        reasonTxt      = $("#disBlock-reason-choices-other").val,        reason         = ,        disablemsgwall = $("#disBlock-disable-meswall:checked"),        blockIP        = $("#disBlock-block-ip:checked"),        watchPages     = $("#disBlock-watch-pages:checked"),        preventLogged  = $("#disBlock-prevent-logged:checked"),        username       = $(".discussion-left-rail__header").text,        token          = ;    if (!reasonTxt) {      if (reasonMenu == "other") {        reason = reasonTxt;      } else {        reason = reasonMenu + ': ' + reasonTxt;      }    } else {      reason = reasonMenu;    }    // Gotta get a token lol    $.ajax({ url: '/api.php', type: 'GET', data: { action: 'query', prop: 'info', titles: 'A', intoken: 'edit', format: 'json' },     success: function(data) { token = data.query.pages[-1].edittoken; var blockQuery = { action: 'block', user: username, reason: reason, token: token, format: 'json' };       if (!disablemsgwall) blockQuery.allowusertalk = true; if (blockIP) blockQuery.autoblock = true; if (watchPages) blockQuery.watchuser = true; if (!preventLogged) blockQuery.nocreate = true; if (expiry == "other") { blockQuery.expiry = expiryOther; } else { blockQuery.expiry = expiry; }       $.ajax({          url: '/api.php',          type: 'POST',          data: blockQuery,          success: function(data) {            if (!data.error) {              $("#disBlock-result-box").innerHTML(disBlock.i18n.msg('success-block', username, blockQuery.expiry, reason).escape);            } else {              $("#disBlock-result-box").innerHTML(disBlock.i18n.msg('error-block', username, data.error.code).escape);            }          },          error: function(data) {            $("#disBlock-result-box").innerHTML(disBlock.i18n.msg('error-block', username, data.error.code).escape);          }        }); }   });  };  disBlock.init; });