Hider Bookmarklet

Code

Link: Hider Bookmarklet


javascript:(function() {
    function initElementRemover() {
        let removedElements = [];
        let removalActive = false;

        const css = `
          body.removalActive * {
            cursor: not-allowed !important;
          }
          #undoButton, #endButton {
            position: fixed;
            z-index: 99999;
            padding: 10px 20px;
            margin: 10px;
            border-radius: 5px;
            font-family: Verdana, sans-serif;
            color: white;
            font-size: 14px;
            background: #6c88f0;
            border: none;
            cursor: pointer;
          }
        `;

        const styleElement = document.createElement('style');
        styleElement.innerHTML = css;
        document.head.append(styleElement);

        const undoButton = document.createElement("a");
        undoButton.textContent = "UNDO";
        undoButton.id = "undoButton";
        undoButton.style.top = '0';
        undoButton.style.left = "0";
        document.body.appendChild(undoButton);

        const endButton = document.createElement("a");
        endButton.textContent = "END";
        endButton.id = "endButton";
        endButton.style.top = '0';
        endButton.style.right = "0";
        document.body.appendChild(endButton);

        function startRemovalProcess() {
            removalActive = true;
            document.addEventListener("click", removeElement);
            document.body.classList.add("removalActive");
        }

        function stopRemovalProcess() {
            removalActive = false;
            document.removeEventListener("click", removeElement);
            document.body.classList.remove("removalActive");
        }

        const undoRemoval = () => {
            const previousRemove = removedElements.pop();
            if (previousRemove) {
                previousRemove.parent.insertBefore(previousRemove.element, previousRemove.sibling);
            }
        };

        const endRemoval = () => {
            undoButton.remove();
            endButton.remove();
            stopRemovalProcess();
        };

        undoButton.addEventListener("click", undoRemoval);
        endButton.addEventListener("click", endRemoval);

        function removeElement(element) {
            if (!removalActive) {return;}
            else if (element.target !== undoButton && element.target !== endButton) {
                removedElements.push({
                    element: element.target,
                    parent: element.target.parentNode,
                    sibling: element.target.nextElementSibling
                });
                element.target.remove();
            }
            element.stopPropagation();
            element.preventDefault();
        }

        startRemovalProcess();
    }

    initElementRemover();
})();
	

Testing Websites