ImageFap - Fix endless scrolling

ImageFap - Fix ImageFap endless scrolling to not load same posts multiple times.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         ImageFap - Fix endless scrolling
// @namespace    imagefap_endless_scroll
// @version      1.1
// @license      GNU AGPLv3
// @description  ImageFap - Fix ImageFap endless scrolling to not load same posts multiple times. 
// @author       marp
// @homepageURL  https://greasyfork.org/en/users/204542-marp
// @grant        none
// @match        https://www.imagefap.com/newsfeed.php*
// @run-at document-end
// ==/UserScript==


// This function will be injected and executed in the context of the page.
// As such it uses the same script libraries as thew page - for example the VERY old jQuery 1.4.2
function injectThis() {
  $(window).unbind("scroll");
  var oldts = Number.MAX_VALUE;
  $(window).scroll(function() {
    if ($(document).height() - $(window).height() - $(window).scrollTop() < 100)
    {
      if (oldts > ts) {
        oldts = ts;
        $('div#loadmoreajaxloader').show();
        $.ajax( {
          url: "/ajax/newsdata.php?userid=XXXuseridXXX&status=XXXstatusXXX&galleries=XXXgalleriesXXX&comments=XXXcommentsXXX&ts=" + ts + "",
          success: function(html)
          {
            if (html)
            {
              $("#postswrapper").append(html);
              $('div#loadmoreajaxloader').hide();
            } else {
              $('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
            }
          }
        });
      }  
    }
  });
}


// Get the nummerical UserID from the navigation header
var singlematch = document.evaluate("//div[@class='blk_header']//a[contains(@href,'usergallery.php?userid=')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
var singlenode = singlematch.singleNodeValue;

if (singlenode) {
  var userid = singlenode.getAttribute("href").substring(8 + singlenode.getAttribute("href").search(/\?userid\=/i));
//console.info("userid: ", userid);

  // Get the selected newsfeed categories (and use defaults to be on the safe side)
  // ImageFap ignores this after the first "page", but I'll still pass the correct params...
  //   ...maybe the site owners will repair it one day...
  var comments = "1";
  var galleries = "1";
  var status = "1";
  singlenode = document.getElementById('status');
  if (singlenode) {
    status = (!singlenode.checked ? "no" : "1");
  }
  singlenode = document.getElementById('galleries');
  if (singlenode) {
    galleries = (!singlenode.checked ? "no" : "1");
  }
  singlenode = document.getElementById('comments');
  if (singlenode) {
    comments = (!singlenode.checked ? "no" : "1");
  }
//console.info("status: ", status);
//console.info("galleries: ", galleries);
//console.info("comments: ", comments);

  var injectString = injectThis.toString();
  injectString = injectString.replaceAll("XXXuseridXXX", userid);
  injectString = injectString.replaceAll("XXXstatusXXX", status);
  injectString = injectString.replaceAll("XXXgalleriesXXX", galleries);
  injectString = injectString.replaceAll("XXXcommentsXXX", comments);
//console.info("function-to-string: ", injectString);

  var scriptnode = document.createElement("script");
  scriptnode.setAttribute("type", "text/javascript");
  scriptnode.textContent = "(" + injectString + ")()";
  document.body.appendChild(scriptnode);
}