2023-05-19 15:02:25 -04:00
|
|
|
/* eslint strict: off */
|
|
|
|
'use strict';
|
|
|
|
(() => {
|
2024-10-09 17:09:09 -04:00
|
|
|
const browser = globalThis.browser ?? globalThis.chrome;
|
2023-05-19 15:02:25 -04:00
|
|
|
|
2024-10-09 17:09:09 -04:00
|
|
|
if (
|
|
|
|
// Don't run on certain sub-domains.
|
|
|
|
/^(?:localhost\.rig|blog|im|chatdepot|tmi|api|brand|dev|gql|passport)\./.test(location.hostname)
|
|
|
|
||
|
|
|
|
// Don't run on pages that have disabled FFZ.
|
|
|
|
/disable_frankerfacez/.test(location.search)
|
|
|
|
) {
|
|
|
|
// Tell the service worker we aren't injecting.
|
|
|
|
browser.runtime.sendMessage({
|
|
|
|
type: 'ffz_not_supported'
|
|
|
|
});
|
2023-11-06 20:47:19 -05:00
|
|
|
return;
|
2024-10-09 17:09:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure to wake the service worker up early.
|
|
|
|
browser.runtime.sendMessage({
|
|
|
|
type: 'ffz_injecting'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Set up the extension message bridge.
|
|
|
|
window.addEventListener('message', evt => {
|
|
|
|
if (evt.source !== window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (evt.data && evt.data.type === 'ffz_to_ext')
|
|
|
|
browser.runtime.sendMessage(evt.data.data, resp => {
|
2024-10-11 17:12:54 -04:00
|
|
|
if (resp?.type === 'ffz_to_page')
|
|
|
|
window.postMessage(resp.data, '*');
|
2024-10-09 17:09:09 -04:00
|
|
|
});
|
|
|
|
});
|
2023-11-06 20:47:19 -05:00
|
|
|
|
2024-10-09 17:09:09 -04:00
|
|
|
browser.runtime.onMessage.addListener((msg, sender) => {
|
2024-10-11 17:12:54 -04:00
|
|
|
if (msg?.type === 'ffz_to_page')
|
|
|
|
window.postMessage(msg.data, '*');
|
|
|
|
|
|
|
|
return false;
|
2024-10-09 17:09:09 -04:00
|
|
|
});
|
2023-09-09 17:43:51 -04:00
|
|
|
|
2024-10-09 17:09:09 -04:00
|
|
|
// Now, inject our script into the page context.
|
|
|
|
const HOST = location.hostname,
|
2023-09-07 14:05:10 -04:00
|
|
|
SERVER = browser.runtime.getURL("web"),
|
2023-05-19 15:02:25 -04:00
|
|
|
script = document.createElement('script');
|
|
|
|
|
|
|
|
let FLAVOR =
|
|
|
|
HOST.includes('player') ? 'player' :
|
|
|
|
HOST.includes('clips') ? 'clips' :
|
|
|
|
(location.pathname === '/p/ffz_bridge/' ? 'bridge' : 'avalon');
|
|
|
|
|
|
|
|
if (FLAVOR === 'clips' && location.pathname === '/embed')
|
|
|
|
FLAVOR = 'player';
|
|
|
|
|
|
|
|
script.id = 'ffz-script';
|
|
|
|
script.async = true;
|
|
|
|
script.crossOrigin = 'anonymous';
|
|
|
|
script.src = `${SERVER}/${FLAVOR}.js?_=${Date.now()}`;
|
2023-09-01 17:01:52 -04:00
|
|
|
script.dataset.path = SERVER;
|
2023-09-07 14:05:10 -04:00
|
|
|
|
2023-05-19 15:02:25 -04:00
|
|
|
document.head.appendChild(script);
|
|
|
|
})();
|