* AutoPagerize Lazy Load Assistant

修复某些 AutoPagerize 脚本、扩展和附加中出现的第二页或更高版本的延迟加载图像问题。

当前为 2020-11-25 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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.0
// @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;
    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';
      }
    });
  });
})();