Skip to content

Instantly share code, notes, and snippets.

@linkelvin11 linkelvin11/jqbx_titan.js
Last active May 23, 2020

Embed
What would you like to do?
JQBX TItan Embed Chat Replacement Greasemonkey Script
// ==UserScript==
// @name JQBX Titan Embed
// @namespace https://app.jqbx.fm
// @version 0.1
// @description Embeds Titan Iframe into JQBX
// @author Kelvin Lin
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// @require http://code.jquery.com/jquery-3.5.1.slim.min.js
// @require https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/lodash.min.js
// @match <$JQBX_ROOM_URL>
// ==/UserScript==
var inline_src = (<><![CDATA[
var hasRenderedTitan = false;
function renderTitan() {
hasRenderedTitan = true;
$(document).ready(() => {
const titanLink = <$TITAN_EMBED_LINK>;
const titanIframe = `<iframe src="${titanLink}" style="width: 100%;height: 100%;">`;
const chatContainer = $('.chat-container');
const chat = $('.chat', chatContainer);
chat.hide();
chatContainer.append(titanIframe);
hasRenderedTitan = true;
observer.disconnect();
});
}
const debouncedRenderTitan = _.debounce(renderTitan, 100);
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (hasRenderedTitan) {
observer.disconnect();
return;
}
if (!mutation.addedNodes) return;
const mutationTarget = $(mutation.target);
if (!mutationTarget.hasClass('chat')) return;
debouncedRenderTitan();
})
})
observer.observe(document.body, {
childList: true
, subtree: true
})
]]></>).toString();
var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
eval(c.code);
@linkelvin11

This comment has been minimized.

Copy link
Owner Author

linkelvin11 commented May 23, 2020

Replace $JQBX_ROOM_URL with a link to your jqbx room
Replace $TITAN_EMBED_LINK with your titan embed link.

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.