comparison mandarake-direct-link.user.js @ 108:2c4470b73ad9

Switch to semistandard No more `;` at the start of line.
author nanaya <me@nanaya.net>
date Sun, 15 Jan 2023 23:24:03 +0900
parents 93e21738b588
children ef21ef445fc6
comparison
equal deleted inserted replaced
107:4bc5a633437c 108:2c4470b73ad9
9 // @grant none 9 // @grant none
10 // @run-at document-start 10 // @run-at document-start
11 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js 11 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js
12 // ==/UserScript== 12 // ==/UserScript==
13 13
14 'use strict' 14 'use strict';
15 15
16 const r18ConfirmLink = '#adult_confirm' 16 const r18ConfirmLink = '#adult_confirm';
17 function fixR18Link (link) { 17 function fixR18Link (link) {
18 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return 18 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return;
19 19
20 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`) 20 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`);
21 link.removeAttribute('class') 21 link.removeAttribute('class');
22 } 22 }
23 23
24 function removeR18Mark (node) { 24 function removeR18Mark (node) {
25 if (node.classList.contains('r18mark')) { 25 if (node.classList.contains('r18mark')) {
26 node.remove() 26 node.remove();
27 return true 27 return true;
28 } 28 }
29 29
30 for (const mark of node.querySelectorAll('.r18mark')) { 30 for (const mark of node.querySelectorAll('.r18mark')) {
31 mark.remove() 31 mark.remove();
32 } 32 }
33 } 33 }
34 34
35 function run (node) { 35 function run (node) {
36 if (!(node instanceof window.HTMLElement)) return 36 if (!(node instanceof window.HTMLElement)) return;
37 if (removeR18Mark(node)) return 37 if (removeR18Mark(node)) return;
38 38
39 fixR18Link(node) 39 fixR18Link(node);
40 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) { 40 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
41 fixR18Link(link) 41 fixR18Link(link);
42 } 42 }
43 } 43 }
44 44
45 function onMutate (mutations) { 45 function onMutate (mutations) {
46 for (const mutation of mutations) { 46 for (const mutation of mutations) {
47 for (const node of mutation.addedNodes) { 47 for (const node of mutation.addedNodes) {
48 run(node) 48 run(node);
49 } 49 }
50 } 50 }
51 } 51 }
52 52
53 const observer = new window.MutationObserver(onMutate) 53 const observer = new window.MutationObserver(onMutate);
54 observer.observe(document, { childList: true, subtree: true }) 54 observer.observe(document, { childList: true, subtree: true });
55 run(document.body) 55 run(document.body);