Mercurial > ec-userscripts
diff mandarake-direct-link.user.js @ 104:93e21738b588
Run fix on whole body on start
There's no guarantee the script loads before document.
author | nanaya <me@nanaya.net> |
---|---|
date | Sun, 25 Dec 2022 11:52:30 +0900 |
parents | b2d0b37f945f |
children | 2c4470b73ad9 |
line wrap: on
line diff
--- a/mandarake-direct-link.user.js Sat Dec 24 22:10:30 2022 +0900 +++ b/mandarake-direct-link.user.js Sun Dec 25 11:52:30 2022 +0900 @@ -1,7 +1,7 @@ // ==UserScript== // @name mandarake direct link // @namespace https://myconan.net -// @version 2.0.0 +// @version 2.0.1 // @description Make proper link on mandarake pages // @author nanaya // @match https://order.mandarake.co.jp/* @@ -32,20 +32,24 @@ } } +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) + } +} + function onMutate (mutations) { for (const mutation of mutations) { for (const node of mutation.addedNodes) { - if (node instanceof window.HTMLElement) { - if (removeR18Mark(node)) continue - - fixR18Link(node) - for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) { - fixR18Link(link) - } - } + run(node) } } } const observer = new window.MutationObserver(onMutate) observer.observe(document, { childList: true, subtree: true }) +run(document.body)