@overhyped-ai/connect
Version:
Embed Overhyped AI's widget seamlessly for user activation - Activate Every. Single. User.
60 lines (58 loc) • 2.02 kB
JavaScript
let OverhypedAI = typeof window !== 'undefined' ? window.OverhypedAI : undefined;
const methods = [
'initOrg',
'initUser',
'connect',
'disconnect'
];
function throwIfNotBrowser() {
if (typeof window === 'undefined') {
throw new Error('OverhypedAI methods cannot be called outside browser context.');
}
}
if (!OverhypedAI) {
const callMethod = function (m, args) {
throwIfNotBrowser();
// If window.OverhypedAI has been replaced, call that instead
if (window.OverhypedAI && window.OverhypedAI !== oai) {
return window.OverhypedAI(m, ...args);
}
// Otherwise push to the temporary queue
oai.q.push([m, [...args]]);
};
// Create the dummy module
const oai = function (m, ...args) {
return callMethod(m, args);
};
oai.q = [];
methods.forEach((m) => {
oai[m] = function (...args) {
return callMethod(m, args);
};
});
OverhypedAI = oai;
if (typeof window !== 'undefined') {
window.OverhypedAI = oai;
}
// const isDocument = typeof document !== 'undefined';
// const overhypedAIScript =
// isDocument && document.getElementById('overhyped-ai-script');
// if (!overhypedAIScript) {
// const firstScript = document.getElementsByTagName('script')[0];
// if (!overhypedAIScript) {
// const scriptElMain = document.createElement('script');
// scriptElMain.id = 'overhyped-ai-script';
// scriptElMain.src =
// 'https://pingbasecdn.blob.core.windows.net/pb-connect/prod/main.js';
// scriptElMain.type = 'text/javascript';
// scriptElMain.defer = true;
// if (firstScript && firstScript.parentNode) {
// firstScript.parentNode.insertBefore(scriptElMain, firstScript);
// } else {
// document.head.appendChild(scriptElMain);
// }
// }
// }
}
var OverhypedAI$1 = OverhypedAI;
export { OverhypedAI$1 as OverhypedAI };