comparison melonbooks-unlazy.user.js @ 96:368035f2213b

Use builtin framework for document ready
author nanaya <me@nanaya.net>
date Fri, 23 Dec 2022 19:14:04 +0900
parents afad36fddb64
children c8f9350c5307
comparison
equal deleted inserted replaced
95:afad36fddb64 96:368035f2213b
1 // ==UserScript== 1 // ==UserScript==
2 // @name melonbooks unlazy 2 // @name melonbooks unlazy
3 // @namespace https://nanaya.net 3 // @namespace https://nanaya.net
4 // @match https://www.melonbooks.co.jp/* 4 // @match https://www.melonbooks.co.jp/*
5 // @grant none 5 // @grant none
6 // @version 1.0.0 6 // @run-at document-end
7 // @version 1.0.1
7 // @author nanaya 8 // @author nanaya
8 // @description replace lazy loaded images with just images 9 // @description replace lazy loaded images with just images
9 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js 10 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js
10 // ==/UserScript== 11 // ==/UserScript==
11 12
12 'use strict' 13 'use strict'
13 14
14 function unlazy () { 15 for (const img of document.querySelectorAll('.lazyload')) {
15 for (const img of document.querySelectorAll('.lazyload')) { 16 const src = img.dataset.src
16 const src = img.dataset.src
17 17
18 if (src != null) { 18 if (src != null) {
19 img.src = src 19 img.src = src
20 img.classList.remove('lazyload') 20 img.classList.remove('lazyload')
21 img.classList.add('unlazied') 21 img.classList.add('unlazied')
22 delete img.dataset.src 22 delete img.dataset.src
23 }
24 } 23 }
25 } 24 }
26
27 if (document.readyState === 'loading') {
28 document.addEventListener('DOMContentLoaded', unlazy)
29 } else {
30 unlazy()
31 }