Skip to content

Instantly share code, notes, and snippets.

@kasimi
Last active November 29, 2017 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasimi/94e8bc6ff112833238193aeb71d88bde to your computer and use it in GitHub Desktop.
Save kasimi/94e8bc6ff112833238193aeb71d88bde to your computer and use it in GitHub Desktop.
Making Magic OGP Parser compatible with mChat for phpBB 3.2
(function ($) {
"use strict";
function parseOgp($container) {
$container.find('.postlink').each(function() {
var ogpdata = $(this).data('ogp');
if (ogpdata.title !== undefined) {
var block = '<div class="ogpblock">';
if (ogpdata.image !== undefined) {
block += '<img src="' + ogpdata.image + '"/>';
}
block += '<div class="ogptext"><h4>' + ogpdata.title + '</h4>' + ogpdata.description + '</div></div>';
$(this).html(block);
$(this).addClass('ogplink');
$(this).removeAttr('data-ogp');
}
});
}
parseOgp($('.content'));
if (typeof mChat === 'object') {
$(mChat).on('mchat_add_message_before', function(e, data) {
parseOgp(data.message);
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment