TradingView: hide disconnected session popup for a mobile

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

  1. // ==UserScript==
  2. // @name TradingView: hide disconnected session popup for a mobile
  3. // @description Hides "Session disconnected" popup. Reconnect is triggered by a touch
  4. // @author Konf
  5. // @namespace https://greasyfork.org/users/424058
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=tradingview.com
  7. // @version 1.0.0
  8. // @match https://www.tradingview.com/*
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js#sha512-wkU3qYWjenbM+t2cmvw2ADRRh4opbOYBjkhrPGHV7M6dcE/TR0oKpoDkWXfUs3HrulI2JFuTQyqPLRih1V54EQ==
  10. // @run-at document-body
  11. // @grant none
  12. // @noframes
  13. // ==/UserScript==
  14.  
  15. /* jshint esversion: 8 */
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. let isConnected = true;
  21. let popupContainer = null;
  22. let reconnectBtn = null;
  23.  
  24. document.addEventListener('touchstart', () => {
  25. if (isConnected) return;
  26.  
  27. isConnected = true;
  28. popupContainer.style.display = '';
  29. reconnectBtn.click();
  30. });
  31.  
  32. document.arrive(
  33. 'div[data-dialog-name="gopro-mobile"]', {
  34. existing: true,
  35. },
  36. (popup) => {
  37. // skip a container with exact same selector.
  38. // the popup has two of them, no need to run twice for the same one
  39. if (popup.querySelector('div[data-dialog-name="gopro-mobile"]')) return;
  40.  
  41. popupContainer = document.querySelector('div#overlap-manager-root');
  42.  
  43. if (popupContainer.contains(popup) === false) return;
  44.  
  45. for (const p of popup.querySelectorAll('p')) {
  46. if (
  47. p.childElementCount === 0 &&
  48. p.innerText === 'Session disconnected' &&
  49. /title.+/.test(p.className) === true
  50. ) {
  51. isConnected = false;
  52. reconnectBtn = popup.querySelector(
  53. 'button[data-overflow-tooltip-text*="Connect"]'
  54. );
  55.  
  56. popupContainer.style.display = 'none';
  57.  
  58. break;
  59. }
  60. }
  61. }
  62. );
  63. }());