diff --git a/beta/test.user.js b/testing/goodtube.js similarity index 97% rename from beta/test.user.js rename to testing/goodtube.js index 89623af..7997719 100644 --- a/beta/test.user.js +++ b/testing/goodtube.js @@ -1,19 +1,3 @@ -// ==UserScript== -// @name GoodTube -// @namespace http://tampermonkey.net/ -// @version 2.010 -// @description Removes 100% of Youtube ads. -// @author GoodTube -// @updateURL https://github.com/goodtube4u/goodtube/raw/refs/heads/main/goodtube.user.js -// @downloadURL https://github.com/goodtube4u/goodtube/raw/refs/heads/main/goodtube.user.js -// @match *://m.youtube.com/* -// @match *://www.youtube.com/* -// @match *://youtube.com/* -// @match *://*.wikipedia.org/* -// @icon https://cdn-icons-png.flaticon.com/256/1384/1384060.png -// @run-at document-start -// ==/UserScript== - (function () { 'use strict'; @@ -211,7 +195,7 @@ ytd-merch-shelf-renderer, ytd-action-companion-ad-renderer, ytd-display-ad-renderer, - ytd-rich-section-renderer, + ytd-video-masthead-ad-advertiser-info-renderer, ytd-video-masthead-ad-primary-video-renderer, ytd-in-feed-ad-layout-renderer, @@ -279,7 +263,8 @@ if (goodTube_shorts === 'false') { let shortsStyle = document.createElement('style'); shortsStyle.textContent = ` - ytm-pivot-bar-item-renderer:has(> .pivot-shorts) { + ytm-pivot-bar-item-renderer:has(> .pivot-shorts), + ytd-rich-section-renderer { display: none !important; } `; @@ -583,7 +568,7 @@ } - // Set the video source (we need to use this weird method so it doesn't mess with browser history) + // Set the video source // This also tells the embed if it's mobile or not let mobileText = 'false'; if (goodTube_mobile) { @@ -1373,7 +1358,7 @@
Settings
- +
@@ -1391,7 +1376,8 @@
Any donation, no matter how small, helps to keep this project going and supports the community who use it. If you would like to say "thank you" and can spare even a single dollar, I would really appreciate it :)
- Donate now + + Donate now @@ -1936,10 +1922,48 @@ // Fix fullscreen button issues goodTube_iframe_fixFullScreenButton(); + // Fix end screen links + goodTube_iframe_fixEndScreenLinks(); + // Run actions again in 100ms to loop this function setTimeout(goodTube_iframe_actions, 100); } + // Fix end screen links (so they open in the same window) + function goodTube_iframe_fixEndScreenLinks() { + let endScreenLinks = document.querySelectorAll('.ytp-videowall-still'); + endScreenLinks.forEach(link => { + // Remove any event listeners that Youtube adds + link.addEventListener('click', (event) => { + event.preventDefault(); + event.stopImmediatePropagation(); + + // On click, redirect the top window to the correct location + window.top.location.href = link.href; + }, true); + + link.addEventListener('mousedown', (event) => { + event.preventDefault(); + event.stopImmediatePropagation(); + }, true); + + link.addEventListener('mouseup', (event) => { + event.preventDefault(); + event.stopImmediatePropagation(); + }, true); + + link.addEventListener('touchstart', (event) => { + event.preventDefault(); + event.stopImmediatePropagation(); + }, true); + + link.addEventListener('touchend', (event) => { + event.preventDefault(); + event.stopImmediatePropagation(); + }, true); + }); + } + // Style the iframe function goodTube_iframe_style() { let style = document.createElement('style'); @@ -1953,7 +1977,6 @@ .ytp-cued-thumbnail-overlay, .ytp-paid-content-overlay, .ytp-impression-link, - .ytp-endscreen-content, .ytp-ad-progress-list, .ytp-endscreen-next, .ytp-endscreen-previous, @@ -1962,6 +1985,10 @@ display: none !important; } + .html5-endscreen { + top: 0 !important; + } + /* Make next and prev buttons not disabled */ .ytp-prev-button, .ytp-next-button { @@ -2572,7 +2599,14 @@ if (youtubeIframe) { // Change the source of the youtube iframe if (event.data.indexOf('goodTube_src_') !== -1) { - youtubeIframe.src = event.data.replace('goodTube_src_', ''); + // First time just change the src + if (youtubeIframe.src === '' || youtubeIframe.src.indexOf('?goodTube=1') !== -1) { + youtubeIframe.src = event.data.replace('goodTube_src_', ''); + } + // All other times, we need to use this weird method so it doesn't mess with our browser history + else { + youtubeIframe.contentWindow.location.replace(event.data.replace('goodTube_src_', '')); + } } // Pass all other messages down to the youtube iframe else { diff --git a/testing/goodtube.user.js b/testing/goodtube.user.js new file mode 100644 index 0000000..198a962 --- /dev/null +++ b/testing/goodtube.user.js @@ -0,0 +1,76 @@ +// ==UserScript== +// @name GoodTube Testing +// @namespace http://tampermonkey.net/ +// @version 2.014 +// @description Removes 100% of Youtube ads. +// @author GoodTube +// @updateURL https://github.com/goodtube4u/goodtube/raw/refs/heads/main/goodtube.user.js +// @downloadURL https://github.com/goodtube4u/goodtube/raw/refs/heads/main/goodtube.user.js +// @match *://m.youtube.com/* +// @match *://www.youtube.com/* +// @match *://youtube.com/* +// @match *://*.wikipedia.org/* +// @icon https://cdn-icons-png.flaticon.com/256/1384/1384060.png +// @run-at document-start +// ==/UserScript== + +// This now automatically loads the latest version. This means that you will never need to update manually again :) +// To view the full source code go here: https://github.com/goodtube4u/goodtube/blob/main/goodtube.js + +(function () { + 'use strict'; + + // Bypass CSP restrictions, introduced by the latest Chrome updates + if (window.trustedTypes && window.trustedTypes.createPolicy && !window.trustedTypes.defaultPolicy) { + window.trustedTypes.createPolicy('default', { + createHTML: string => string, + createScriptURL: string => string, + createScript: string => string + }); + } + + // Define load function + function goodTube_load(loadAttempts) { + // If it's the first load attempt + if (loadAttempts === 0) { + // Debug message + console.log('\n==================================================\n ______ ________ __\n / ____/___ ____ ____/ /_ __/_ __/ /_ ___\n / / __/ __ \\/ __ \\/ __ / / / / / / / __ \\/ _ \\\n / /_/ / /_/ / /_/ / /_/ / / / / /_/ / /_/ / __/\n \\____/\\____/\\____/\\____/ /_/ \\____/_____/\\___/\n\n=================================================='); + console.log('[GoodTube] Initiating...'); + } + + // Only re-attempt to load the GoodTube 10 times + if (loadAttempts >= 9) { + // Debug message + console.log('[GoodTube] GoodTube could not be loaded'); + + // Show prompt + alert('GoodTube could not be loaded! Please refresh the page to try again.'); + + return; + } + + // Increment the load attempts + loadAttempts++; + + // Load GoodTube + fetch('https://raw.githubusercontent.com/goodtube4u/GoodTube/main/testing/goodtube.js?i=' + Date.now()) + // Success + .then(response => response.text()) + .then(data => { + // Put GoodTube code into a