Wirecutter Anti-modal

Stop modals asking you to register before viewing articles

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Wirecutter Anti-modal
// @namespace https://github.com/bricemciver/GreasemonekeyScripts
// @description Stop modals asking you to register before viewing articles
// @license MIT
// @version 0.0.2
// @match https://www.nytimes.com/wirecutter/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=nytimes.com
// @grant none
// ==/UserScript==



/* jshint esversion: 6 */
"use strict";
(() => {
  // src/main/wirecutter-anti-modal/wirecutter-anti-modal.user.ts
  (() => {
    let modalRemoved = false;
    let overflowFixed = false;
    const config = {
      attributes: true,
      childList: true,
      subtree: true
    };
    const elementToObserve = document.querySelector("body");
    const removePaywallModal = (mutation) => {
      if (!modalRemoved && mutation.type === "childList") {
        mutation.addedNodes.forEach((item) => {
          const element = item;
          if (element.id === "modal-portal-regiwall") {
            element.remove();
            modalRemoved = true;
          }
        });
      }
    };
    const removeScrollLock = (mutation) => {
      if (!overflowFixed && mutation.type === "attributes" && mutation.attributeName === "class") {
        const element = mutation.target;
        if (element.tagName === "BODY") {
          element.className = "";
          overflowFixed = true;
        }
      }
    };
    const startObserver = () => {
      const callback = (mutationsList, observer) => {
        mutationsList.forEach((mutation) => {
          removePaywallModal(mutation);
          removeScrollLock(mutation);
          if (modalRemoved && overflowFixed) {
            observer.disconnect();
          }
        });
      };
      if (elementToObserve) {
        new MutationObserver(callback).observe(elementToObserve, config);
      }
    };
    startObserver();
  })();
})();
//# sourceMappingURL=wirecutter-anti-modal.user.js.map