Tradingview Skip Ads (Cyber Monday sale and other annoyances)

Trying to skip Cyber Monday sale, Black Friday sale, and ads with a "Decline offer" or "Competition started" in them

当前为 2024-11-29 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Tradingview Skip Ads (Cyber Monday sale and other annoyances)
// @description   Trying to skip Cyber Monday sale, Black Friday sale, and ads with a "Decline offer" or "Competition started" in them
// @author        Konf
// @namespace     https://greasyfork.org/users/424058
// @icon          https://www.google.com/s2/favicons?sz=64&domain=tradingview.com
// @version       3.1.0
// @match         https://www.tradingview.com/*
// @require       https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js#sha512-wkU3qYWjenbM+t2cmvw2ADRRh4opbOYBjkhrPGHV7M6dcE/TR0oKpoDkWXfUs3HrulI2JFuTQyqPLRih1V54EQ==
// @run-at        document-start
// @grant         none
// @license MIT
// @noframes
// ==/UserScript==

/* jshint esversion: 8 */

(function() {
  'use strict';

  (function main() {
    if (!document.documentElement) return setTimeout(main);
  
    // Close Cyber Monday popup
    document.arrive(
      'div.tv-dialog__modal-body',
      { existing: true },
      (modal) => {
        for (const span of modal.querySelectorAll('span')) {
          if (span.innerText === 'Cyber Monday' || span.innerText.includes('Black Friday')) {
            modal.querySelector('div.tv-dialog__close').click();
            break;
          }
        }
      },
    );
  
    // Handle "Decline offer" in GoPro modals
    document.arrive(
      'div[data-dialog-name="gopro"]',
      { existing: true },
      (modal) => {
        findAndDeclineOffer(modal);
      },
    );
  
    document.arrive(
      'div[data-dialog-name="gopro-mobile"]',
      { existing: true },
      (modal) => {
        findAndDeclineOffer(modal);
  
        for (const p of modal.querySelectorAll('p')) {
          if (p.innerText === 'Competition started') {
            modal.querySelector('button[aria-label="Close"]').click();
            break;
          }
        }
      },
    );
  
    // Close Black Friday popup
    document.arrive(
      'div.banner-WnHzIH9Q',
      { existing: true },
      (popup) => {
        const closeButton = popup.closest('div.tv-dialog__modal-container')?.querySelector('.tv-dialog__close');
        if (closeButton) {
          closeButton.click();
        }
      },
    );
  
    // utils ----------------------------------------------------------
  
    function findAndDeclineOffer(goProModal) {
      for (const span of goProModal.querySelectorAll('span')) {
        if (span.innerText === 'Decline offer') {
          span.parentElement.click();
          break;
        }
      }
    }
    
    // ---------------------------------------------------------- utils
  }());  
})();