Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GIFV Support for Propane
/*
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
You can’t perform that action at this time.