annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
1 // ==UserScript==
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
2 // @name suruga-ya fixes
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
3 // @namespace https://myconan.net
107
4bc5a633437c The urls need to be lowercased
nanaya <me@nanaya.net>
parents: 106
diff changeset
4 // @version 2.0.2
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
5 // @description Show all products with fast image
68
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
6 // @author nanaya
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
7 // @match https://www.suruga-ya.jp/*
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
8 // @grant none
82
86da34e62d29 Update url
nanaya <me@nanaya.pro>
parents: 77
diff changeset
9 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js
68
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
10 // ==/UserScript==
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
11
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
12 'use strict';
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
13
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
14 // always inject adult consent cookie
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
15 (function () {
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
16 const hasAdultCookie = document.cookie.split('; ').includes('adult=1');
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
17 if (!hasAdultCookie) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
18 const d = new Date();
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
19 d.setTime(d.getTime() + (100 * 24 * 60 * 60 * 1000));
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
20 document.cookie = `adult=1; expires=${d.toGMTString()}; path=/`;
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
21 window.location.reload();
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
22 }
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
23 })();
68
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
24
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
25 // skip loading image through php which seems to take forever
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
26 (function () {
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
27 const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/;
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
28 function fix (image) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
29 const origSrc = image.getAttribute('src');
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
30 if (origSrc == null) return;
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
31 const found = origSrc.match(itemImageRegexp);
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
32 if (found == null) return;
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
33
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
34 const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1].toLowerCase()}.jpg`;
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
35 const setNotFound = () => {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
36 image.removeEventListener('error', setNotFound);
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
37 image.setAttribute('src', 'https://www.suruga-ya.jp/database/images/no_photo.jpg');
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
38 };
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
39 image.addEventListener('error', setNotFound);
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
40 image.setAttribute('src', src);
68
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
41 }
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
42
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
43 function run (node) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
44 if (!(node instanceof window.HTMLElement)) return;
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
45
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
46 fix(node);
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
47 for (const image of node.querySelectorAll('img')) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
48 fix(image);
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
49 }
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
50 }
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
51
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
52 function onMutate (mutations) {
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
53 for (const mutation of mutations) {
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
54 for (const node of mutation.addedNodes) {
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
55 run(node);
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
56 }
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
57 }
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
58 }
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
59
108
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
60 const observer = new window.MutationObserver(onMutate);
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
61 observer.observe(document, { childList: true, subtree: true });
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
62 run(document.body);
2c4470b73ad9 Switch to semistandard
nanaya <me@nanaya.net>
parents: 107
diff changeset
63 })();