Skip to content

Instantly share code, notes, and snippets.

@larryfox
Last active December 20, 2015 09:49
Show Gist options
  • Save larryfox/6110365 to your computer and use it in GitHub Desktop.
Save larryfox/6110365 to your computer and use it in GitHub Desktop.
Inlined images in notices, and embedded youtube videos in the Textual app.

Inlined images in notices, and embedded youtube videos in the Textual app.

Add it to your Styles scripts.js file.

Your User Styles can be found in ~/Library/Containers/com.codeux.irc.textual/Data/Library/Application Support/Textual IRC/Styles/. For more info see: http://www.codeux.com/textual/wiki/Styles.wiki

Textual.newMessagePostedToView = function(lineNumber) {
var message = document.getElementById('line-'+lineNumber);
[].forEach.call(message.querySelectorAll('.url'), function(el) {
if (el.href.match(/(\.gif|\.jpg|\.jpeg|\.png)/i)) {
if (message.getAttribute('type') != 'notice') return true;
appendImage(el);
} else if (el.href.match(/(youtube\.com|youtu\.be)/i)) {
appendYoutube(el);
}
});
}
function appendYoutube(el) {
el.parentNode.removeChild(el.nextElementSibling);
var url = el.href;
var regex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?([\w\-]{10,12})(?:&feature=related)?(?:[\w\-]{0})?/g;
var embed = 'http://www.youtube.com/embed/$1';
url = url.replace(regex, embed);
var iframe = document.createElement('iframe');
iframe.src = url;
iframe.width = 300;
iframe.height = 200;
iframe.setAttribute('frameborder', '0');
el.parentNode.appendChild(iframe);
}
function appendImage(el) {
var link = document.createElement('a');
link.setAttribute('onclick', 'return Textual.hideInlineImage(this)');
var img = document.createElement('img');
img.src = el.href;
img.setAttribute('style', 'max-width: 300px;');
img.classList.add('inlineimage');
link.appendChild(img);
link.href = el.href;
el.parentNode.appendChild(link);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment