Mercurial > ec-userscripts
diff mandarake-direct-link.user.js @ 117:d9dc190bccaf
Undo combining fixes into single script per site
author | nanaya <me@nanaya.net> |
---|---|
date | Sun, 15 Jan 2023 23:49:35 +0900 |
parents | ef21ef445fc6 |
children | 8de2d53a4cb1 |
line wrap: on
line diff
--- a/mandarake-direct-link.user.js Sun Jan 15 23:46:56 2023 +0900 +++ b/mandarake-direct-link.user.js Sun Jan 15 23:49:35 2023 +0900 @@ -13,47 +13,43 @@ 'use strict'; -function directLink () { - const r18ConfirmLink = '#adult_confirm'; - function fixR18Link (link) { - if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return; - - link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`); - link.removeAttribute('class'); - } +const r18ConfirmLink = '#adult_confirm'; +function fixR18Link (link) { + if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return; - function removeR18Mark (node) { - if (node.classList.contains('r18mark')) { - node.remove(); - return true; - } + link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`); + link.removeAttribute('class'); +} - for (const mark of node.querySelectorAll('.r18mark')) { - mark.remove(); - } +function removeR18Mark (node) { + if (node.classList.contains('r18mark')) { + node.remove(); + return true; } - function run (node) { - if (!(node instanceof window.HTMLElement)) return; - if (removeR18Mark(node)) return; + for (const mark of node.querySelectorAll('.r18mark')) { + mark.remove(); + } +} + +function run (node) { + if (!(node instanceof window.HTMLElement)) return; + if (removeR18Mark(node)) return; - fixR18Link(node); - for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) { - fixR18Link(link); + fixR18Link(node); + for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) { + fixR18Link(link); + } +} + +function onMutate (mutations) { + for (const mutation of mutations) { + for (const node of mutation.addedNodes) { + run(node); } } - - function onMutate (mutations) { - for (const mutation of mutations) { - for (const node of mutation.addedNodes) { - run(node); - } - } - } - - const observer = new window.MutationObserver(onMutate); - observer.observe(document, { childList: true, subtree: true }); - run(document.body); } -directLink(); +const observer = new window.MutationObserver(onMutate); +observer.observe(document, { childList: true, subtree: true }); +run(document.body);