Mercurial > ec-userscripts
annotate surugaya-direct-image.user.js @ 147:15ec4ec958d7 default tip
Sentence case name and match filename (sort of)
author | nanaya <me@nanaya.net> |
---|---|
date | Sat, 27 Sep 2025 15:06:06 +0900 |
parents | 8de2d53a4cb1 |
children |
rev | line source |
---|---|
68 | 1 // ==UserScript== |
147
15ec4ec958d7
Sentence case name and match filename (sort of)
nanaya <me@nanaya.net>
parents:
118
diff
changeset
|
2 // @name Suruga-ya direct image |
118 | 3 // @namespace https://nanaya.net |
4 // @version 2.0.3 | |
5 // @description skip loading image through php which seems to take forever | |
6 // @author nanaya | |
7 // @match https://www.suruga-ya.jp/* | |
8 // @grant none | |
9 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/surugaya-direct-image.user.js | |
68 | 10 // ==/UserScript== |
11 | |
108 | 12 'use strict'; |
105 | 13 |
116 | 14 const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/; |
15 function fix (image) { | |
16 const origSrc = image.getAttribute('src'); | |
17 if (origSrc == null) return; | |
18 const found = origSrc.match(itemImageRegexp); | |
19 if (found == null) return; | |
20 | |
21 const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1].toLowerCase()}.jpg`; | |
22 const setNotFound = () => { | |
23 image.removeEventListener('error', setNotFound); | |
24 image.setAttribute('src', 'https://www.suruga-ya.jp/database/images/no_photo.jpg'); | |
25 }; | |
26 image.addEventListener('error', setNotFound); | |
27 image.setAttribute('src', src); | |
28 } | |
29 | |
30 function run (node) { | |
31 if (!(node instanceof window.HTMLElement)) return; | |
32 | |
33 fix(node); | |
34 for (const image of node.querySelectorAll('img')) { | |
35 fix(image); | |
105 | 36 } |
109 | 37 } |
68 | 38 |
116 | 39 function onMutate (mutations) { |
40 for (const mutation of mutations) { | |
41 for (const node of mutation.addedNodes) { | |
42 run(node); | |
105 | 43 } |
44 } | |
109 | 45 } |
46 | |
116 | 47 const observer = new window.MutationObserver(onMutate); |
48 observer.observe(document, { childList: true, subtree: true }); | |
49 run(document.body); |