User:Dorumin/awaybutton.​js

// Adds an AFK button to the chat-js buttons list. Doesn't disable the default away in 10 minutes.  importArticle({   type: 'script',    article: 'u:dev:MediaWiki:Chat-js/code.js' });

mw.hook('dev.chat.render').add(function {   var button = new dev.chat.Button({ name: 'AFKButton', attr: { text: 'AFK', click: toggleAway }   }).el;

mainRoom.model.chats.bind('afteradd', function(model) {       var userMain = mainRoom.model.users.findByName(wgUserName);        if (model.attributes.name == wgUserName && userMain && userMain.attributes.statusState == 'away') {            setBack;        }    });

var sb = mainRoom.setBack;

function toggleAway { var current = mainRoom.model.users.findByName(wgUserName).attributes.statusState; // No, mainRoom.userMain doesn't work

if (current == 'away') { setBack; } else { setAway; }   }

function setAway { mainRoom.setAway; clearTimeout(mainRoom.activityTimeout); mainRoom.setBack = $.noop; button.textContent = 'Back'; }

function setBack { mainRoom.setBack; mainRoom.activityTimer = setTimeout($.proxy(mainRoom.setAway, mainRoom), 5 * 60 * 1000); mainRoom.setBack = sb; mainRoom.setBack; button.textContent = 'AFK'; }

mainRoom.socket.on("updateUser", function(msg) {       var data = JSON.parse(msg.data).attrs,            type = data.statusMessage,            status = data.statusState,            user = data.name;

if (user == wgUserName && status != 'away') { mainRoom.setBack = sb; button.textContent = 'AFK'; }   }); });