User:Kittynator/chat.js

window.colour = {};

/** * colour.chat * * Literally exists to hold PM blocking code */ window.colour.chat = { _blockPM: function(user) { return new Promise(function(resolve, reject) {           $.ajax({ url: mw.util.wikiScript('index') + '?action=ajax&rs=ChatAjax&method=blockOrBanChat', type: 'post', dataType: 'json', data: { userToBan: user, dir: 'add', token: mw.user.tokens.get('editToken') }               })                .done(function(res) { if (!res.hasOwnProperty('success')) reject(res);

if (res.success === true) resolve(true); else reject(res); })               .fail(function(err, stat) { reject(err, stat); });       });    },    blockPM: function(user) { window.colour.chat._blockPM(user).then(           function {                console.log(user + ' was blocked!');            },            function(err, stat) {                console.error(err, stats);            }        ); } };

/** * Blocks PMs on user join * * Please consider, like, leaving me alone */ if (mw.config.get('wgCanonicalSpecialPageName') === 'Chat') { mainRoom.socket.bind('join', function(event) {       var ev = JSON.parse(event.data);        var username = ev.attrs.name;        var whitelist = [            'TyA',            'Sannse',            'Sophiedp'        ];

if (!whitelist.includes(username)) colour.chat.blockPM(username); }); }