└── lacampfire.user.js /lacampfire.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Logically awesome Campfire enhancements 3 | // @namespace http://logicalawesome.com/ 4 | // @description Stuff we added that's cool. 5 | // @author Chris Wanstrath 6 | // @homepage http://github.com/ 7 | // @include *.campfirenow.com/room* 8 | // ==/UserScript== 9 | 10 | // Logical and awesome 11 | LA = {} 12 | 13 | //// 14 | // Aliases - whatever is typed is expanded to something else 15 | LA.Aliases = [] 16 | 17 | // tweet status url => twicture.gif 18 | LA.Aliases.push(function(text) { 19 | var matches = text.match(/^http:\/\/twitter.com\/.+?\/statuses\/(\d+)$/) 20 | return matches ? 'http://twictur.es/' + matches[1] + '.gif' : text 21 | }) 22 | 23 | //// 24 | // Transforms - plaintext stored in campfire's db is expanded on 25 | // receipt or load into something else 26 | LA.Transformers = [] 27 | 28 | // gist url => gist embed 29 | LA.Transformers.push(function(text) { 30 | var matches = text.match(/^http:\/\/gist.github.com\/(\d+)$/); 31 | if (!matches) return; 32 | 33 | var url = "http://gist.github.com/" + matches[1] + ".pibb"; 34 | var divId = 'gist-div-' + (new Date).valueOf() 35 | 36 | var iframe = new Element('iframe', { 37 | src: url, 38 | height: "200px", 39 | width: "100%", 40 | style: 'border:0;padding:0;margin:0;display:none;', 41 | onload: 'LA.gistFromIframe(this, "' + divId + '")' 42 | }) 43 | 44 | var div = new Element('div', { id: divId }).update('Loading Gist ' + matches[1] + '...') 45 | 46 | return new Element('div').insert(div).insert(iframe) 47 | }) 48 | 49 | LA.gistFromIframe = function(iframe, id) { 50 | $(id).remove() 51 | $(iframe).show() 52 | } 53 | 54 | if (Campfire) { 55 | //// 56 | // Plumbing for the alises 57 | chat.speaker.filters = LA.Aliases.concat(Campfire.Speaker.Filters).toArray(); 58 | 59 | //// 60 | // Plumbing for the transforms 61 | LA.Transform = function(messages) { 62 | $A(messages || chat.transcript.messages).each(function(message) { 63 | if (message.kind != "text") return 64 | var text = message.bodyElement().innerText 65 | 66 | var newText = LA.Transformers.returnFirstApplication(function(transformer) { 67 | return transformer(text) 68 | }) 69 | 70 | if (newText) { 71 | message.updateBody(newText) 72 | if (messages) chat.windowmanager.scrollToBottom() 73 | } 74 | }) 75 | } 76 | 77 | // hook into campfire receive event - called by foreign and local message inserts 78 | Campfire.Transformer = Class.create() 79 | Campfire.Transformer.prototype = { 80 | initialize: function() {}, 81 | onMessagesInserted: LA.Transform 82 | } 83 | 84 | Campfire.Responders.push("Transformer") 85 | chat.register.apply(chat, Campfire.Responders) 86 | 87 | // run transforms on load 88 | LA.Transform() 89 | chat.windowmanager.scrollToBottom() 90 | } 91 | 92 | if (Growler) { 93 | // remove the built-in growl stuff if a growl userscript is detected 94 | delete chat.growlnotifier 95 | } 96 | 97 | // debug 98 | function LALog(e) { 99 | new Insertion.Bottom('chat', "" + e + ""); 100 | } 101 | --------------------------------------------------------------------------------