* AutoPagerize Lazy Load Assistant

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

目前為 2020-11-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        * AutoPagerize Lazy Load Assistant
// @name:ja     * AutoPagerize Lazy Load Assistant
// @name:zh-CN  * AutoPagerize Lazy Load Assistant
// @namespace   knoa.jp
// @description It fixes the lazyload 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.1
// @grant       none
// ==/UserScript==

(function() {
  const SCRIPTNAME = 'AutoPagerize Lazy Load Assistant';
  const FLAGNAME = 'lazyLoadAssistant';
  const DATASETS = [
    'src',
    'lazySrc',
    'original',
  ];
  let name = undefined; //そのページで使われている lazyload プロパティ名は一度確定したら変わらない
  document.addEventListener('GM_AutoPagerizeNextPageLoaded', e => {
    console.log(SCRIPTNAME, 'event:', e.type);
    const d = e.target; //残念ながら pageElement ではなく document になる
    const imgs = d.querySelectorAll('img'); //ここでフィルタリングするよりは全取得したほうが処理は速い
    imgs.forEach(img => {
      if(name === undefined){
        name = DATASETS.find(n => img.dataset[n]);
        if(name) console.log(SCRIPTNAME, 'dataset:', name);
        else return;
      }
      if(img.dataset[FLAGNAME]) return; //処理済み
      else if(img.dataset[name]){
        img.src = img.dataset[name];
        img.dataset[FLAGNAME] = 'true';
        img.style.opacity = 1; //一部のサイトに必要
      }
    });
  });
})();