comparison mandarake-direct-link.user.js @ 109:ef21ef445fc6

Cleanups - wrap everything in function and call them last - fix namespace and update url
author nanaya <me@nanaya.net>
date Sun, 15 Jan 2023 23:33:41 +0900
parents 2c4470b73ad9
children d9dc190bccaf
comparison
equal deleted inserted replaced
108:2c4470b73ad9 109:ef21ef445fc6
1 // ==UserScript== 1 // ==UserScript==
2 // @name mandarake direct link 2 // @name mandarake direct link
3 // @namespace https://myconan.net 3 // @namespace https://nanaya.net
4 // @version 2.0.1 4 // @version 2.0.1
5 // @description Make proper link on mandarake pages 5 // @description Make proper link on mandarake pages
6 // @author nanaya 6 // @author nanaya
7 // @match https://order.mandarake.co.jp/* 7 // @match https://order.mandarake.co.jp/*
8 // @match http://order.mandarake.co.jp/* 8 // @match http://order.mandarake.co.jp/*
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 function directLink () {
17 function fixR18Link (link) { 17 const r18ConfirmLink = '#adult_confirm';
18 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return; 18 function fixR18Link (link) {
19 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return;
19 20
20 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`); 21 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`);
21 link.removeAttribute('class'); 22 link.removeAttribute('class');
23 }
24
25 function removeR18Mark (node) {
26 if (node.classList.contains('r18mark')) {
27 node.remove();
28 return true;
29 }
30
31 for (const mark of node.querySelectorAll('.r18mark')) {
32 mark.remove();
33 }
34 }
35
36 function run (node) {
37 if (!(node instanceof window.HTMLElement)) return;
38 if (removeR18Mark(node)) return;
39
40 fixR18Link(node);
41 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
42 fixR18Link(link);
43 }
44 }
45
46 function onMutate (mutations) {
47 for (const mutation of mutations) {
48 for (const node of mutation.addedNodes) {
49 run(node);
50 }
51 }
52 }
53
54 const observer = new window.MutationObserver(onMutate);
55 observer.observe(document, { childList: true, subtree: true });
56 run(document.body);
22 } 57 }
23 58
24 function removeR18Mark (node) { 59 directLink();
25 if (node.classList.contains('r18mark')) {
26 node.remove();
27 return true;
28 }
29
30 for (const mark of node.querySelectorAll('.r18mark')) {
31 mark.remove();
32 }
33 }
34
35 function run (node) {
36 if (!(node instanceof window.HTMLElement)) return;
37 if (removeR18Mark(node)) return;
38
39 fixR18Link(node);
40 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
41 fixR18Link(link);
42 }
43 }
44
45 function onMutate (mutations) {
46 for (const mutation of mutations) {
47 for (const node of mutation.addedNodes) {
48 run(node);
49 }
50 }
51 }
52
53 const observer = new window.MutationObserver(onMutate);
54 observer.observe(document, { childList: true, subtree: true });
55 run(document.body);