Skip to content

Instantly share code, notes, and snippets.

@ookkoouu
ookkoouu / dom-observer.ts
Last active February 14, 2024 11:47
DOM Observer like as jQuery
function observeMutation(
target: Element,
callback: (muts: MutationRecord[]) => void,
options?: MutationObserverInit
) {
const obs = new window.MutationObserver(callback);
obs.observe(target, options);
return () => obs.disconnect();
}
@ookkoouu
ookkoouu / zenn-footnote-tooltip.js
Last active May 7, 2023 05:48
Zennの脚注をツールチップで表示
function addTooltip(noteref) {
const note = document.querySelector(noteref.getAttribute("href"));
const noteText = note.firstElementChild.innerText.slice(0, -3);
noteref.setAttribute("title", noteText);
}
const noterefs = [...document.querySelectorAll(".footnote-ref > a")];
noterefs.map((ref) => addTooltip(ref));