Greasy Fork is available in English.

TradingView Toast Ad Blocker

Blocks toast-ad scripts on TradingView

  1. // ==UserScript==
  2. // @name TradingView Toast Ad Blocker
  3. // @namespace https://greatest.deepsurf.us/tr/users/1461563-mehmet-kutup
  4. // @version 1.0
  5. // @description Blocks toast-ad scripts on TradingView
  6. // @author Mehmet Kutup
  7. // @match *://*.tradingview.com/*
  8. // @run-at document-start
  9. // @grant none
  10. // @license no license
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // toast-ad.* prevention files
  17. const observer = new MutationObserver(() => {
  18. const scripts = document.querySelectorAll('script[src*="toast-ad"]');
  19. scripts.forEach(script => {
  20. if (script.src.includes("https://static.tradingview.com/static/bundles/toast-ad")) {
  21. console.log("Blocked toast-ad script:", script.src);
  22. script.parentNode.removeChild(script);
  23. }
  24. });
  25. });
  26.  
  27. observer.observe(document.documentElement, {
  28. childList: true,
  29. subtree: true
  30. });
  31.  
  32. // createElement loading prevention
  33. const originalCreateElement = document.createElement;
  34. document.createElement = function(tagName) {
  35. const element = originalCreateElement.call(document, tagName);
  36. if (tagName.toLowerCase() === 'script') {
  37. Object.defineProperty(element, 'src', {
  38. set(value) {
  39. if (value.includes("https://static.tradingview.com/static/bundles/toast-ad")) {
  40. console.log("Blocked toast-ad script via createElement:", value);
  41. return;
  42. }
  43. element.setAttribute('src', value);
  44. },
  45. get() {
  46. return element.getAttribute('src');
  47. }
  48. });
  49. }
  50. return element;
  51. };
  52.  
  53. const checkAd = setInterval(() => {
  54. const adBox = document.getElementById('tv-toasts');
  55. if (adBox) {
  56. adBox.remove();
  57. console.log('tv-toasts element removed.');
  58. } else {
  59. console.log('tv-toasts element not present.');
  60. }
  61. }, 5000);
  62. })();