comparison surugaya-fixes.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 4bc5a633437c
children ef21ef445fc6
comparison
equal deleted inserted replaced
107:4bc5a633437c 108:2c4470b73ad9
7 // @match https://www.suruga-ya.jp/* 7 // @match https://www.suruga-ya.jp/*
8 // @grant none 8 // @grant none
9 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js 9 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js
10 // ==/UserScript== 10 // ==/UserScript==
11 11
12 'use strict' 12 'use strict';
13 13
14 // always inject adult consent cookie 14 // always inject adult consent cookie
15 ;(function () { 15 (function () {
16 const hasAdultCookie = document.cookie.split('; ').includes('adult=1') 16 const hasAdultCookie = document.cookie.split('; ').includes('adult=1');
17 if (!hasAdultCookie) { 17 if (!hasAdultCookie) {
18 const d = new Date() 18 const d = new Date();
19 d.setTime(d.getTime() + (100 * 24 * 60 * 60 * 1000)) 19 d.setTime(d.getTime() + (100 * 24 * 60 * 60 * 1000));
20 document.cookie = `adult=1; expires=${d.toGMTString()}; path=/` 20 document.cookie = `adult=1; expires=${d.toGMTString()}; path=/`;
21 window.location.reload() 21 window.location.reload();
22 } 22 }
23 })() 23 })();
24 24
25 // skip loading image through php which seems to take forever 25 // skip loading image through php which seems to take forever
26 ;(function () { 26 (function () {
27 const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/ 27 const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/;
28 function fix (image) { 28 function fix (image) {
29 const origSrc = image.getAttribute('src') 29 const origSrc = image.getAttribute('src');
30 if (origSrc == null) return 30 if (origSrc == null) return;
31 const found = origSrc.match(itemImageRegexp) 31 const found = origSrc.match(itemImageRegexp);
32 if (found == null) return 32 if (found == null) return;
33 33
34 const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1].toLowerCase()}.jpg` 34 const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1].toLowerCase()}.jpg`;
35 const setNotFound = () => { 35 const setNotFound = () => {
36 image.removeEventListener('error', setNotFound) 36 image.removeEventListener('error', setNotFound);
37 image.setAttribute('src', 'https://www.suruga-ya.jp/database/images/no_photo.jpg') 37 image.setAttribute('src', 'https://www.suruga-ya.jp/database/images/no_photo.jpg');
38 } 38 };
39 image.addEventListener('error', setNotFound) 39 image.addEventListener('error', setNotFound);
40 image.setAttribute('src', src) 40 image.setAttribute('src', src);
41 } 41 }
42 42
43 function run (node) { 43 function run (node) {
44 if (!(node instanceof window.HTMLElement)) return 44 if (!(node instanceof window.HTMLElement)) return;
45 45
46 fix(node) 46 fix(node);
47 for (const image of node.querySelectorAll('img')) { 47 for (const image of node.querySelectorAll('img')) {
48 fix(image) 48 fix(image);
49 } 49 }
50 } 50 }
51 51
52 function onMutate (mutations) { 52 function onMutate (mutations) {
53 for (const mutation of mutations) { 53 for (const mutation of mutations) {
54 for (const node of mutation.addedNodes) { 54 for (const node of mutation.addedNodes) {
55 run(node) 55 run(node);
56 } 56 }
57 } 57 }
58 } 58 }
59 59
60 const observer = new window.MutationObserver(onMutate) 60 const observer = new window.MutationObserver(onMutate);
61 observer.observe(document, { childList: true, subtree: true }) 61 observer.observe(document, { childList: true, subtree: true });
62 run(document.body) 62 run(document.body);
63 })() 63 })();