This commit is contained in:
goodtube4u
2025-06-14 12:46:52 +10:00
parent dcdd51fce2
commit 619724642c
2 changed files with 133 additions and 23 deletions

View File

@@ -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 @@
<div class='goodTube_title'>Settings</div>
<div class='goodTube_content'>
<div class='goodTube_setting'>
<input type='checkbox' class='goodTube_option_shorts' name='goodTube_option_shorts'`+ shortsEnabled + `>
<input type='checkbox' class='goodTube_option_shorts' name='goodTube_option_shorts' id='goodTube_option_shorts'`+ shortsEnabled + `>
<label for='goodTube_option_shorts'>Remove all Shorts from Youtube</label>
</div> <!-- .goodTube_setting -->
<button class='goodTube_button' id='goodTube_button_saveSettings'>Save and refresh</button>
@@ -1391,7 +1376,8 @@
<br>
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 :)
</div>
<a href='https://tiptopjar.com/goodtube' target='_blank' class='goodTube_button'>Donate now</a>
<!--<a href='https://tiptopjar.com/goodtube' target='_blank' rel='nofollow' class='goodTube_button'>Donate now</a>-->
<a href='https://www.paypal.com/donate/?hosted_button_id=37GNXSV27RZBS' target='_blank' rel='nofollow' class='goodTube_button'>Donate now</a>
</div> <!-- .goodTube_donation -->
</div> <!-- .goodTube_content -->
@@ -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 {

76
testing/goodtube.user.js Normal file
View File

@@ -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 <script> tag
let element = document.createElement('script');
element.innerHTML = data;
document.head.appendChild(element);
})
// Error
.catch((error) => {
// Try again after 500ms
setTimeout(function () {
goodTube_load(loadAttempts);
}, 500);
});
}
// Load GoodTube
goodTube_load(0);
})();