TradingView: hide disconnected session popup for a mobile

Hides "Session disconnected" popup. Reconnect is triggered by a touch

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          TradingView: hide disconnected session popup for a mobile
// @description   Hides "Session disconnected" popup. Reconnect is triggered by a touch
// @author        Konf
// @namespace     https://greasyfork.org/users/424058
// @icon          https://www.google.com/s2/favicons?sz=64&domain=tradingview.com
// @version       1.0.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-body
// @grant         none
// @noframes
// ==/UserScript==

/* jshint esversion: 8 */

(function() {
  'use strict';

  let isConnected = true;
  let popupContainer = null;
  let reconnectBtn = null;

  document.addEventListener('touchstart', () => {
    if (isConnected) return;

    isConnected = true;
    popupContainer.style.display = '';
    reconnectBtn.click();
  });

  document.arrive(
    'div[data-dialog-name="gopro-mobile"]', {
      existing: true,
    },
    (popup) => {
      // skip a container with exact same selector.
      // the popup has two of them, no need to run twice for the same one
      if (popup.querySelector('div[data-dialog-name="gopro-mobile"]')) return;

      popupContainer = document.querySelector('div#overlap-manager-root');

      if (popupContainer.contains(popup) === false) return;

      for (const p of popup.querySelectorAll('p')) {
        if (
          p.childElementCount === 0 &&
          p.innerText === 'Session disconnected' &&
          /title.+/.test(p.className) === true
        ) {
          isConnected = false;
          reconnectBtn = popup.querySelector(
            'button[data-overflow-tooltip-text*="Connect"]'
          );

          popupContainer.style.display = 'none';

          break;
        }
      }
    }
  );
}());