gurufocus ad-free

Remove annoying ads from gurufocus :)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         gurufocus ad-free
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Remove annoying ads from gurufocus :)
// @author       https://github.com/KamilKoso
// @match        https://www.gurufocus.com/*
// @icon         https://www.google.com/s2/favicons?domain=gurufocus.com
// @grant        none
// @license      MIT
// ==/UserScript==

const observer = new MutationObserver(clearPage);

// This cookie is incremented each refresh, if value reaches 6 big ad shows and site is not being fully loaded
const pwcouCookie = {
  name: "pwcou1",
  domain: ".gurufocus.com",
  desiredValue: 0,
  expirationDays: 30,
};

// add here ads that are being displayed repeatedly
const adsToClear = ["div.el-dialog__wrapper.gf", "div.v-modal", "div.paywall-shadow", "div#business-description-non-logged", "section#notification-bar", "div#colorbox", "div#cboxOverlay", "div.ad-image-container"];

function clearPage() {
  let elems = document.querySelectorAll(adsToClear);
  setCookie(pwcouCookie.name, pwcouCookie.desiredValue, pwcouCookie.domain, pwcouCookie.expirationDays);
  elems.forEach((elem) => {
    elem.remove();
  });

  fixScroll();
}

function fixScroll() {
  const appContainer = document.querySelector(".app-wrapper .el-container");
  if (appContainer.getAttribute("style") == "height: auto;") {
    appContainer.setAttribute("style", "height: calc(100vh - 142px);");
  }
}

function setCookie(cName, cValue, cDomain, expDays) {
  let date = new Date();
  date.setTime(date.getTime() + expDays * 24 * 60 * 60 * 1000);
  const expires = "expires=" + date.toUTCString();
  document.cookie = cName + "=" + cValue + "; " + expires + "; domain=" + cDomain + "; path=/";
}

(function () {
  observer.observe(document.body, { subtree: true, childList: true });
})();