Add this code to the custom JS field in elfsight. Also disable MooTools on pages with elfsight widgets.
(function () {
var RESTORE_NATIVES = true;
var WATCH_MS = 5000;
var fnToString = Function.prototype.toString;
var getOwnNames = Object.getOwnPropertyNames;
var getDesc = Object.getOwnPropertyDescriptor;
var defineProp = Object.defineProperty;
function isNative(fn) {
try {
return /\{\s*\[native code\]\s*\}/.test(fnToString.call(fn));
} catch (e) {
return true;
}
}
function targets() {
var list = [
Object,
Array,
String,
Number,
Boolean,
Function,
Date,
RegExp,
Error,
typeof Element !== 'undefined' ? Element : null,
typeof HTMLElement !== 'undefined' ? HTMLElement : null,
typeof Node !== 'undefined' ? Node : null,
typeof NodeList !== 'undefined' ? NodeList : null,
typeof HTMLCollection !== 'undefined' ? HTMLCollection : null,
typeof DocumentFragment !== 'undefined' ? DocumentFragment : null,
typeof Document !== 'undefined' ? Document : null,
typeof Window !== 'undefined' ? Window : null,
typeof EventTarget !== 'undefined' ? EventTarget : null,
typeof Event !== 'undefined' ? Event : null,
typeof Text !== 'undefined' ? Text : null,
typeof HTMLFormElement !== 'undefined' ? HTMLFormElement : null,
typeof XMLHttpRequest !== 'undefined' ? XMLHttpRequest : null,
];
var out = [],
i;
for (i = 0; i < list.length; i++) {
if (list[i] && list[i].prototype) out.push(list[i]);
}
return out;
}
function hideEnumerable() {
targets().forEach(function (C) {
var proto = C.prototype,
keys,
i,
key,
d;
try {
keys = getOwnNames(proto);
} catch (e) {
return;
}
for (i = 0; i < keys.length; i++) {
key = keys[i];
if (key === 'constructor') continue;
try {
d = getDesc(proto, key);
} catch (e) {
continue;
}
if (!d || !d.enumerable || !d.configurable) continue;
d.enumerable = false;
try {
defineProp(proto, key, d);
} catch (e) {}
}
});
}
var cleanFrame = null;
function cleanRealm() {
if (cleanFrame && cleanFrame.contentWindow) return cleanFrame.contentWindow;
var host = document.body || document.documentElement;
if (!host) return null;
cleanFrame = document.createElement('iframe');
cleanFrame.setAttribute('aria-hidden', 'true');
cleanFrame.setAttribute('tabindex', '-1');
cleanFrame.style.cssText =
'position:absolute!important;width:0!important;height:0!important;' +
'border:0!important;opacity:0!important;pointer-events:none!important;' +
'left:-9999px!important;top:-9999px!important';
host.appendChild(cleanFrame);
return cleanFrame.contentWindow;
}
function restoreNatives() {
var W = cleanRealm();
if (!W) return;
var specs = [
['Object', false],
['Array', true],
['String', true],
['Number', true],
['Boolean', false],
['Function', false],
['Date', true],
['RegExp', false],
['JSON', true],
['Math', true],
];
function fix(mineObj, cleanObj) {
var keys, i, key;
try {
keys = getOwnNames(cleanObj);
} catch (e) {
return;
}
for (i = 0; i < keys.length; i++) {
key = keys[i];
if (key === 'constructor' || key === 'prototype') continue;
try {
var cd = getDesc(cleanObj, key);
if (!cd || typeof cd.value !== 'function') continue;
var md = getDesc(mineObj, key);
if (!md || typeof md.value !== 'function') continue;
if (isNative(md.value)) continue;
if (!md.configurable && !md.writable) continue;
defineProp(mineObj, key, {
value: cd.value,
writable: true,
configurable: true,
enumerable: false,
});
} catch (e) {}
}
}
specs.forEach(function (spec) {
var mine = window[spec[0]],
clean = W[spec[0]];
if (!mine || !clean) return;
if (mine.prototype && clean.prototype)
fix(mine.prototype, clean.prototype);
if (spec[1]) fix(mine, clean);
});
}
function onReady(fn) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', fn, false);
} else {
fn();
}
}
function watch() {
var started = Date.now();
if (typeof MutationObserver === 'function') {
var mo = new MutationObserver(function (records) {
for (var i = 0; i < records.length; i++) {
var added = records[i].addedNodes;
for (var j = 0; j < added.length; j++) {
var tag = added[j].nodeName;
if (tag === 'SCRIPT' || tag === 'IFRAME') {
hideEnumerable();
return;
}
}
}
});
onReady(function () {
try {
mo.observe(document.documentElement, {
childList: true,
subtree: true,
});
} catch (e) {}
});
setTimeout(function () {
try {
mo.disconnect();
} catch (e) {}
}, WATCH_MS);
}
var tick = setInterval(function () {
hideEnumerable();
if (Date.now() - started > WATCH_MS) clearInterval(tick);
}, 250);
}
hideEnumerable();
if (RESTORE_NATIVES) onReady(restoreNatives);
onReady(hideEnumerable);
window.addEventListener('load', hideEnumerable, false);
watch();
})();