annotate surugaya-direct-image.user.js @ 129:dc960ef1248b

Add lashinbang always consent script
author nanaya <me@nanaya.net>
date Tue, 07 Feb 2023 21:51:34 +0900
parents 8de2d53a4cb1
children
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==
118
8de2d53a4cb1 Fix metadata
nanaya <me@nanaya.net>
parents: 116
diff changeset
2 // @name suruga-ya direct image
8de2d53a4cb1 Fix metadata
nanaya <me@nanaya.net>
parents: 116
diff changeset
3 // @namespace https://nanaya.net
8de2d53a4cb1 Fix metadata
nanaya <me@nanaya.net>
parents: 116
diff changeset
4 // @version 2.0.3
8de2d53a4cb1 Fix metadata
nanaya <me@nanaya.net>
parents: 116
diff changeset
5 // @description skip loading image through php which seems to take forever
8de2d53a4cb1 Fix metadata
nanaya <me@nanaya.net>
parents: 116
diff changeset
6 // @author nanaya
8de2d53a4cb1 Fix metadata
nanaya <me@nanaya.net>
parents: 116
diff changeset
7 // @match https://www.suruga-ya.jp/*
8de2d53a4cb1 Fix metadata
nanaya <me@nanaya.net>
parents: 116
diff changeset
8 // @grant none
8de2d53a4cb1 Fix metadata
nanaya <me@nanaya.net>
parents: 116
diff changeset
9 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/surugaya-direct-image.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
116
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
14 const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/;
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
15 function fix (image) {
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
16 const origSrc = image.getAttribute('src');
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
17 if (origSrc == null) return;
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
18 const found = origSrc.match(itemImageRegexp);
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
19 if (found == null) return;
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
20
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
21 const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1].toLowerCase()}.jpg`;
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
22 const setNotFound = () => {
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
23 image.removeEventListener('error', setNotFound);
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
24 image.setAttribute('src', 'https://www.suruga-ya.jp/database/images/no_photo.jpg');
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
25 };
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
26 image.addEventListener('error', setNotFound);
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
27 image.setAttribute('src', src);
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
28 }
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
29
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
30 function run (node) {
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
31 if (!(node instanceof window.HTMLElement)) return;
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
32
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
33 fix(node);
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
34 for (const image of node.querySelectorAll('img')) {
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
35 fix(image);
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
36 }
109
ef21ef445fc6 Cleanups
nanaya <me@nanaya.net>
parents: 108
diff changeset
37 }
68
7784a39c891b Add script to fix suruga-ya display
nanaya <me@nanaya.pro>
parents:
diff changeset
38
116
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
39 function onMutate (mutations) {
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
40 for (const mutation of mutations) {
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
41 for (const node of mutation.addedNodes) {
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
42 run(node);
105
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
diff changeset
43 }
6b354277f2d1 [surugaya-fixes] faster image load
nanaya <me@nanaya.net>
parents: 82
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
116
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
47 const observer = new window.MutationObserver(onMutate);
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
48 observer.observe(document, { childList: true, subtree: true });
0e108a9dc6d7 Split suruga-ya scripts
nanaya <me@nanaya.net>
parents: 109
diff changeset
49 run(document.body);