-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
64 lines (49 loc) · 2.15 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.OLSKFigures = global.OLSKFigures || {})));
}(this, (function(exports) { 'use strict';
const mod = {
OLSKFiguresEndpointURL () {
return 'https://old-fire-5813.dash-cloudflare-com7350.workers.dev/js/script.js';
},
OLSKFiguresLoad (inputData) {
// https://stackoverflow.com/questions/925039/detect-iframe-embedding-in-javascript
if (window !== window.top) {
return;
}
const target = document.createElement('div');
document.body.appendChild(target);
// https://stackoverflow.com/questions/2592092/executing-script-elements-inserted-with-innerhtml
var setInnerHTML = function(elm, html) {
elm.innerHTML = html;
Array.from(elm.querySelectorAll("script")).forEach( oldScript => {
const newScript = document.createElement("script");
Array.from(oldScript.attributes)
.forEach( attr => newScript.setAttribute(attr.name, attr.value) );
newScript.appendChild(document.createTextNode(oldScript.innerHTML));
oldScript.parentNode.replaceChild(newScript, oldScript);
});
}
// target.innerHTML = `<script class="OLSKFigures" defer data-domain="${ location.host }" src="${ window.location.host.match('loc.tests') ? '' : mod.OLSKFiguresEndpointURL() }"></script>`;
setInnerHTML(target, `<script class="OLSKFigures" defer data-domain="${ window.OLSKFiguresDomain || location.host }" src="${ window.location.host.match('loc.tests') ? '' : mod.OLSKFiguresEndpointURL() }"></script>`);
},
// MESSAGE
DOMContentLoaded () {
const _mod = (typeof process !== 'undefined' && process.env.npm_lifecycle_script === 'olsk-spec') ? this : mod;
_mod.OLSKFiguresLoad();
},
// LIFECYCLE
LifecycleModuleDidLoad (debug) {
return;
(debug || window).document.addEventListener('DOMContentLoaded', mod.DOMContentLoaded);
},
};
Object.assign(exports, mod);
if (typeof window === 'object') {
mod.LifecycleModuleDidLoad();
}
Object.defineProperty(exports, '__esModule', {
value: true
});
})));