Created
January 27, 2015 22:06
-
-
Save gdiggs/9d9eb3007055fa04f0c4 to your computer and use it in GitHub Desktop.
GIFV Support for Propane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
From https://gist.github.com/GordonDiggs/9d9eb3007055fa04f0c4 | |
Add this to your caveatPatchor.js file | |
(located at ~Library/Application Support/Propane/unsupported/caveatPatchor.js) | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
*/ | |
var displayGifvImages = true; | |
if (displayGifvImages) { | |
Campfire.GifvExpander = Class.create({ | |
initialize: function(chat) { | |
this.chat = chat; | |
var messages = this.chat.transcript.messages; | |
for (var i = 0; i < messages.length; i++) { | |
this.detectGifvURL(messages[i]); | |
} | |
}, | |
detectGifvURL: function(message) { | |
if (!message.pending() && message.kind === 'text') { | |
var links = message.bodyElement().select('a:not(image)'); | |
if (links.length != 1) { | |
return; | |
} | |
var href = links[0].getAttribute('href'); | |
var match = href.match(/^https?:\/\/i\.imgur\.com\/([A-Za-z0-9]+)\.gifv$/); | |
if (!match) return; | |
var imgurID = match[1]; | |
message.resize((function() { | |
message.bodyCell.insert({ | |
bottom: '<div style="width:100%; margin-top:5px; padding-top: 5px; border-top:1px dotted #ccc;"><video autoplay="" loop="" muted=""><source type="video/webm" src="http://i.imgur.com/'+imgurID+'.webm"><source type="video/mp4" src="http://i.imgur.com/'+imgurID+'.mp4"></video></div>' | |
}); | |
}).bind(this)); | |
} | |
}, | |
onMessagesInsertedBeforeDisplay: function(messages) { | |
for (var i = 0; i < messages.length; i++) { | |
this.detectGifvURL(messages[i]); | |
} | |
}, | |
onMessageAccepted: function(message, messageID) { | |
this.detectGifvURL(message); | |
} | |
}); | |
Campfire.Responders.push("GifvExpander"); | |
window.chat.installPropaneResponder("GifvExpander", "gifvexpander"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment