Files
background.js
content.css
content.js
manifest.json
popup.css
popup.html
popup.js
Code
7 304
content.js
let bonkModeActive = false;
let hoveredElement = null;
let lastBonk = null;
let undoNotice = null;
function clearHighlight() {
if (hoveredElement) {
hoveredElement.classList.remove("tinkaton-hammer-hovered");
hoveredElement = null;
}
}
function handlePointerOver(event) {
if (!bonkModeActive) return;
const element = event.target instanceof HTMLElement ? event.target : null;
if (!element || element.closest("[data-tinkaton-ui]")) return;
clearHighlight();
hoveredElement = element;
hoveredElement.classList.add("tinkaton-hammer-hovered");
}
function handlePointerOut(event) {
if (event.target === hoveredElement) {
clearHighlight();
}
}
function removeUndoNotice() {
undoNotice?.remove();
undoNotice = null;
}
function restoreLastBonk() {
if (!lastBonk) return;
const { element, parent, nextSibling } = lastBonk;
if (parent.isConnected) {
parent.insertBefore(element, nextSibling?.parentNode === parent ? nextSibling : null);
}
lastBonk = null;
removeUndoNotice();
}
function showUndoNotice() {
removeUndoNotice();
const notice = document.createElement("div");
notice.dataset.tinkatonUi = "undo";
notice.append(document.createTextNode("Bonk! Element removed."));
const undoButton = document.createElement("button");
undoButton.type = "button";
undoButton.textContent = "Undo";
undoButton.addEventListener("click", (event) => {
event.preventDefault();
event.stopPropagation();
restoreLastBonk();
});
notice.append(undoButton);
document.documentElement.append(notice);
undoNotice = notice;
}
function handleClick(event) {
if (!bonkModeActive) return;
const element = event.target instanceof HTMLElement ? event.target : null;
if (!element || element.closest("[data-tinkaton-ui]")) return;
if (element === document.documentElement || element === document.body) return;
event.preventDefault();
event.stopPropagation();
clearHighlight();
lastBonk = {
element,
parent: element.parentNode,
nextSibling: element.nextSibling
};
element.remove();
bonkModeActive = false;
showUndoNotice();
}
function handleKeyDown(event) {
if (event.key === "Escape" && bonkModeActive) {
bonkModeActive = false;
clearHighlight();
}
}
document.addEventListener("pointerover", handlePointerOver, true);
document.addEventListener("pointerout", handlePointerOut, true);
document.addEventListener("click", handleClick, true);
document.addEventListener("keydown", handleKeyDown, true);
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "tinkaton-status") {
sendResponse({ active: bonkModeActive });
return false;
}
if (message.type === "tinkaton-toggle") {
bonkModeActive = !bonkModeActive;
clearHighlight();
sendResponse({ active: bonkModeActive });
return false;
}
return false;
});