Skip to content

Instantly share code, notes, and snippets.

@jickoo
Last active June 27, 2023 04:37
Show Gist options
  • Save jickoo/7b4122829240cc415c098aab89d6f49d to your computer and use it in GitHub Desktop.
Save jickoo/7b4122829240cc415c098aab89d6f49d to your computer and use it in GitHub Desktop.
append, prepend polyfill
// Source: https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md
(function (arr) {
arr.forEach(function (item) {
if (item.hasOwnProperty('append')) {
return;
}
Object.defineProperty(item, 'append', {
configurable: true,
enumerable: true,
writable: true,
value: function append() {
var argArr = Array.prototype.slice.call(arguments),
docFrag = document.createDocumentFragment();
argArr.forEach(function (argItem) {
var isNode = argItem instanceof Node;
docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem)));
});
this.appendChild(docFrag);
}
});
});
})([Element.prototype, Document.prototype, DocumentFragment.prototype]);
// Source: https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/prepend()/prepend().md
(function (arr) {
arr.forEach(function (item) {
if (item.hasOwnProperty('prepend')) {
return;
}
Object.defineProperty(item, 'prepend', {
configurable: true,
enumerable: true,
writable: true,
value: function prepend() {
var argArr = Array.prototype.slice.call(arguments),
docFrag = document.createDocumentFragment();
argArr.forEach(function (argItem) {
var isNode = argItem instanceof Node;
docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem)));
});
this.insertBefore(docFrag, this.firstChild);
}
});
});
})([Element.prototype, Document.prototype, DocumentFragment.prototype]);
const p = document.createElement("p");
const t = document.querySelector(".vod_player_wrap video") as any;
if (!t) return;
p.append(`${corePlayer.clientWidth} / ${corePlayer.clientHeight} vs ${t.offsetWidth} / ${t.offsetHeight} - ${window.outerWidth} / ${window.outerHeight}`);
document.getElementById("div-console")?.prepend(p);
// NOTE :: (debounce: IE11이나 느린 환경에서 뒷배경이 보임, 보기 안좋음, throttle: IE11에서 동작제대로 안함...)
checkIEBrowser() ? window.addEventListener('resize', () => {
setTimeout(resizeAd, 72);
}) : window.addEventListener('resize', resizeAd);
<div style={{position: "absolute", color: 'black', zIndex: 10000}} id="div-console"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment