Jump to content
  • Advertisement
  • entries
    18
  • comments
    35
  • views
    29577

IPBoard Extensions v1.5

Sign in to follow this  
fastcall22

1340 views

Changelog:
Added new emotes.
Fixed literal backslash escaping.
Changed users command to link users to their profiles.
And various other things since version 1.0 that I've forgotten.

// ==UserScript==// @name IPBoard Extensions// @namespace fastcall22.com// @include http://www.gamedev.net/chat/*// @version 1.5// @grant none// ==/UserScript==(function ipb_ext(){try{ var Chat = IPBoard.prototype.chat; // util Chat.ext_post_message = function(content_or_nodes,content_is_html) { var post = document.createElement('li'); ['post','chat-myown'].forEach(function(cl){ post.classList.add(cl); }); if ( typeof content_or_nodes == 'string' ) { var content = content_or_nodes; var target = content_is_html ? 'innerHTML' : 'textContent'; post[target] = content; } else { var nodes = content_or_nodes; [].concat(nodes).forEach(function(elem){ post.appendChild(elem); }); } document.getElementById('storage_chatroom') .appendChild(post); post.scrollIntoView(false); }; Chat.ext_search_users = function(query) { var result = {}; var q_reg = new RegExp(query||'^'); for ( var id in Chat.forumIdMap._object ) { var name = Chat.nameFormatting._object[id][2]; if ( q_reg.test(name) ) result[name] = id; } return result; }; Chat.ext_user_action = function(action,target_id){ ipb.chat.sendMessageToChild( "server="+serverHost + "&path="+serverPath + "&room="+roomId + "&user="+userId + "&access_key=" + accessKey + "&action="+action + "&against="+target_id ); ipb.chat.lastAction = parseInt(new Date().getTime().toString().substring(0, 10)); }; // config var null_f = function(){}; Chat.ext_empty_event = { stopPropagation: null_f, preventDefault: null_f }; Chat.ext_confirm_action = null; var make_action = function(action){ return function(query) { if ( !query.trim() ) return; var users = Chat.ext_search_users(query); Chat.ext_confirm_action = function() { for ( var k in users ) Chat.ext_user_action(action,users[k]); }; var str = ''; for ( var k in users ) { if ( str ) str += ', '; str += k; } Chat.ext_post_message("Send /confirm to "+action+": "+str+". Send /cancel to ignore"); }; }; Chat.ext_commands = { kick: make_action('kick'), ban: make_action('ban'), test: function() {Chat.test = !(Chat.test || false)}, debug: function() {Chat.debug = !(Chat.debug || false)}, users: function(query) { var users = {}; var keys = []; [].slice.call(document.querySelectorAll('#chatters-online li')) .forEach(function(li){ var a = li.querySelector('a.ipsUserPhotoLink'); var user_id = li.getAttribute('id').replace(/^user_/,''); var user_profile = a.getAttribute('href'); var user_name = Chat.nameFormatting._object[user_id][2]; var out_a = document.createElement('a'); out_a.setAttribute('href',user_profile); out_a.textContent = user_name; users[user_name] = out_a; keys.push(user_name); }); var nodes = []; keys.sort().forEach(function(key) { if ( nodes.length ) nodes.push(document.createTextNode(', ')); nodes.push(users[key]); }); Chat.ext_post_message(nodes); }, confirm: function() { if ( !Chat.ext_confirm_action ) return; Chat.ext_confirm_action(); Chat.ext_confirm_action = null; }, cancel: function() { Chat.ext_confirm_action = null; }, mute: function() { document.getElementById('sound_toggle').click(); }, quit: function(){ document.getElementById('leave_room').click(); }, }; Chat.ext_escape = { 'n': '\n', 't': '?', 'e': '?', '\\': '\\', }; Chat.ext_emotes = { fear: ':f34r:', lenny: '( ?? ?? ??)', wat: '?__?', shrug: '?\\_(?)_/?', whee: '?( ? )?', flip: '(????)??????', why: '?(????)', }; Chat.ext_bbc = { rick: function(param,content) { // never gonna give you up // never gonna let you down // never gonna run around // and desert you } }; // helpers Chat.arg_parse = /\s*(?:(\w+?)(?:="(.+?)"))?/g; Chat.bbc_filter = function ext_bbc_filter(_,tag,param,content) { var f = Chat.ext_bbc[tag]; if ( !f ) return _; return f(param,content); }; Chat.ext_filters = [ /* commands */ [ /^\/(\w+)\s*(.*)$/, function ext_command_filter(_,cmd,argstr) { var args = argstr.split(' '); var f = Chat.ext_commands[cmd]; if ( !f ) return _; f.apply(null,args); return ''; } ], /* emotes */ [ /:(\w+):/g, function ext_emote_filter(_,tag) { return Chat.ext_emotes[tag] || _; } ], /* backslash */ [ /\\(?:(x[0-9a-fA-f]{4})|([a-z\\]))/g, function ext_backslash_filter(_,hex,code) { if ( hex ) return '&#'+hex+';'; return Chat.ext_escape || _; } ], /* BBC w/ content */ [ /\[(\w+)(?:=(.+))?\](.*?)\[\/\1\]/g, Chat.bbc_filter ], /* self-closing BBC tags */ [ /\[(\w+)(?:=(.+))?\s*()\/\]/g, Chat.bbc_filter ], /* general */ [ /\t/g, '?' ] ]; Chat.ext_filter_message = function(str) { Chat.ext_filters.forEach(function(f){ if ( !str.length ) return; if ( Chat.debug ) console.log(f,str); str = String.prototype.replace.apply(str,f); }); return str; }; Chat.ext_send = function ext_send(e) { if ( e.preventDefault ) e.preventDefault(); if ( e.stopPropagation ) e.stopPropagation(); var message = (document.getElementById('message_textarea').value || '').trim(); if ( Chat.debug ) console.log('send',message); if ( !message ) return; var filtered = Chat.ext_filter_message(message) || null; document.getElementById('message_textarea').value = filtered; if ( filtered ) return Chat.ipb_sendChat.call(this,Chat.ext_empty_event); }; Chat.ipb_sendChat = Chat.sendChat; Chat.sendChat = Chat.ext_send; Chat.ext_rewired = true; console.log('okay');} catch ( ex ) { console.log("Error: " + ex); console.log((new Error).stack);}})();commands: kick, ban, quit, and users
escaping: e, n, t, e, and \
emots: lenny, wat, shrug, whee, flip, and why



As usual, add this as a greasemonkey script or dump it into your javascript console

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!