|
| 1 | +// Performance optimization: Block slow external eclipse.org resources |
| 2 | +(function() { |
| 3 | + 'use strict'; |
| 4 | + |
| 5 | + // Block eclipse.org cookie consent requests immediately |
| 6 | + const blockedDomains = [ |
| 7 | + 'www.eclipse.org/eclipse.org-common/themes/solstice/public/stylesheets/vendor/cookieconsent/', |
| 8 | + 'www.eclipse.org/eclipse.org-common/themes/solstice/public/javascript/vendor/cookieconsent/' |
| 9 | + ]; |
| 10 | + |
| 11 | + // Override fetch to block requests |
| 12 | + const originalFetch = window.fetch; |
| 13 | + window.fetch = function(url, options) { |
| 14 | + const urlString = url.toString(); |
| 15 | + if (blockedDomains.some(domain => urlString.includes(domain))) { |
| 16 | + console.log('Blocked slow external request:', urlString); |
| 17 | + return Promise.reject(new Error('Blocked for performance')); |
| 18 | + } |
| 19 | + return originalFetch.apply(this, arguments); |
| 20 | + }; |
| 21 | + |
| 22 | + // Override XMLHttpRequest |
| 23 | + const originalXMLHttpRequest = window.XMLHttpRequest; |
| 24 | + window.XMLHttpRequest = function() { |
| 25 | + const xhr = new originalXMLHttpRequest(); |
| 26 | + const originalOpen = xhr.open; |
| 27 | + |
| 28 | + xhr.open = function(method, url) { |
| 29 | + const urlString = url.toString(); |
| 30 | + if (blockedDomains.some(domain => urlString.includes(domain))) { |
| 31 | + console.log('Blocked slow XHR request:', urlString); |
| 32 | + return; // Don't open the request |
| 33 | + } |
| 34 | + return originalOpen.apply(this, arguments); |
| 35 | + }; |
| 36 | + |
| 37 | + return xhr; |
| 38 | + }; |
| 39 | + |
| 40 | + // Remove existing elements immediately if they exist |
| 41 | + document.addEventListener('DOMContentLoaded', function() { |
| 42 | + // Remove cookie consent links |
| 43 | + const cookieLinks = document.querySelectorAll('link[href*="eclipse.org"][href*="cookieconsent"]'); |
| 44 | + cookieLinks.forEach(link => { |
| 45 | + console.log('Removing eclipse.org cookie consent CSS:', link.href); |
| 46 | + link.remove(); |
| 47 | + }); |
| 48 | + |
| 49 | + // Remove cookie consent scripts |
| 50 | + const cookieScripts = document.querySelectorAll('script[src*="eclipse.org"][src*="cookieconsent"]'); |
| 51 | + cookieScripts.forEach(script => { |
| 52 | + console.log('Removing eclipse.org cookie consent JS:', script.src); |
| 53 | + script.remove(); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + // Early removal - check immediately |
| 58 | + if (document.readyState === 'loading') { |
| 59 | + const observer = new MutationObserver(function(mutations) { |
| 60 | + mutations.forEach(function(mutation) { |
| 61 | + mutation.addedNodes.forEach(function(node) { |
| 62 | + if (node.nodeType === 1) { // Element node |
| 63 | + if (node.tagName === 'LINK' && node.href && node.href.includes('eclipse.org') && node.href.includes('cookieconsent')) { |
| 64 | + console.log('Blocked cookie consent CSS from loading:', node.href); |
| 65 | + node.remove(); |
| 66 | + } |
| 67 | + if (node.tagName === 'SCRIPT' && node.src && node.src.includes('eclipse.org') && node.src.includes('cookieconsent')) { |
| 68 | + console.log('Blocked cookie consent JS from loading:', node.src); |
| 69 | + node.remove(); |
| 70 | + } |
| 71 | + } |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + observer.observe(document.documentElement, { |
| 77 | + childList: true, |
| 78 | + subtree: true |
| 79 | + }); |
| 80 | + |
| 81 | + // Stop observing after page load |
| 82 | + window.addEventListener('load', function() { |
| 83 | + observer.disconnect(); |
| 84 | + }); |
| 85 | + } |
| 86 | +})(); |
0 commit comments