annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
Edho Arief <me@myconan.net>
parents:
diff changeset
1 // ==UserScript==
Edho Arief <me@myconan.net>
parents:
diff changeset
2 // @name mandarake direct link
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
3 // @namespace https://nanaya.net
104
93e21738b588 Run fix on whole body on start
nanaya <me@nanaya.net>
parents: 103
diff changeset
4 // @version 2.0.1
16
Edho Arief <me@myconan.net>
parents:
diff changeset
5 // @description Make proper link on mandarake pages
Edho Arief <me@myconan.net>
parents:
diff changeset
6 // @author nanaya
Edho Arief <me@myconan.net>
parents:
diff changeset
7 // @match https://order.mandarake.co.jp/*
18
Edho Arief <me@myconan.net>
parents: 17
diff changeset
8 // @match http://order.mandarake.co.jp/*
16
Edho Arief <me@myconan.net>
parents:
diff changeset
9 // @grant none
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
10 // @run-at document-start
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
11 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js
16
Edho Arief <me@myconan.net>
parents:
diff changeset
12 // ==/UserScript==
Edho Arief <me@myconan.net>
parents:
diff changeset
13
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 104
diff changeset
14 'use strict';
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
15
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
16 function directLink () {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
17 const r18ConfirmLink = '#adult_confirm';
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
18 function fixR18Link (link) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
19 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
20
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
21 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
22 link.removeAttribute('class');
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
23 }
51
f0d5a5d80bfd Remove extra element
nanaya <me@nanaya.pro>
parents: 49
diff changeset
24
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
25 function removeR18Mark (node) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
26 if (node.classList.contains('r18mark')) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
27 node.remove();
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
28 return true;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
29 }
51
f0d5a5d80bfd Remove extra element
nanaya <me@nanaya.pro>
parents: 49
diff changeset
30
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
31 for (const mark of node.querySelectorAll('.r18mark')) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
32 mark.remove();
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
33 }
66
444b17e657be Standardize code style
nanaya <me@nanaya.pro>
parents: 58
diff changeset
34 }
16
Edho Arief <me@myconan.net>
parents:
diff changeset
35
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
36 function run (node) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
37 if (!(node instanceof window.HTMLElement)) return;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
38 if (removeR18Mark(node)) return;
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
39
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
40 fixR18Link(node);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
41 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
42 fixR18Link(link);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
43 }
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
44 }
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
45
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
46 function onMutate (mutations) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
47 for (const mutation of mutations) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
48 for (const node of mutation.addedNodes) {
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
49 run(node);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
50 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
51 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
52 }
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
53
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
54 const observer = new window.MutationObserver(onMutate);
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
55 observer.observe(document, { childList: true, subtree: true });
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
56 run(document.body);
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
57 }
48
b60f0fd9c417 Update mandarake script
nanaya <me@nanaya.pro>
parents: 35
diff changeset
58
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
59 directLink();