* AutoPagerize LazyLoad Assistant

It fixes the lazy load image problem of some AutoPagerize scripts, extensions or add-ons, occuring on second or latter pages.

Stan na 17-01-2021. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        * AutoPagerize LazyLoad Assistant
// @name:ja     * AutoPagerize LazyLoad Assistant
// @name:zh-CN  * AutoPagerize LazyLoad Assistant
// @namespace   knoa.jp
// @description It fixes the lazy load image problem of some AutoPagerize scripts, extensions or add-ons, occuring on second or latter pages.
// @description:ja 一部の AutoPagerize スクリプト、拡張機能、アドオンで発生する、2ページ目以降の遅延読み込み画像の問題を修正します。
// @description:zh-CN 修复某些 AutoPagerize 脚本、扩展和附加中出现的第二页或更高版本的延迟加载图像问题。
// @include     *
// @version     1.1.3
// @grant       none
// ==/UserScript==

/*
[update]
Minor fix.
*/
(function() {
  const SCRIPTID = 'AutoPagerizeLazyLoadAssistant';
  const FLAGNAME = 'lazyLoadAssistant';
  const DATASETS = [
    'src',
    'lazySrc',
    'original',
    'delay',
    'img',
  ];
  let name = undefined; //そのページで使われている lazyload プロパティ名は一度確定したら変わらない
  document.addEventListener('GM_AutoPagerizeNextPageLoaded', e => {
    console.log(SCRIPTID, 'event:', e.type);
    const d = e.target; //残念ながら pageElement ではなく document になる
    const imgs = d.querySelectorAll('img'); //ここで FLAGNAME 付きを除外する処理は重いのでシンプルに全取得する
    for(let i = 0; imgs[i]; i++){
      if(name === undefined){
        name = DATASETS.find(n => imgs[i].dataset[n]);
        if(name) console.log(SCRIPTID, 'dataset:', name);
        else continue;
      }
      if(imgs[i].dataset[FLAGNAME]) continue; //処理済み
      else if(imgs[i].dataset[name]){
        imgs[i].src = imgs[i].dataset[name];
        imgs[i].style.opacity = 1; //一部のサイトに必要
        imgs[i].style.visibility = 'visible'; //一部のサイトに必要
        imgs[i].dataset[FLAGNAME] = 'true';
      }
    }
  });
})();