Updates minor

This commit is contained in:
goodtube4u
2024-07-22 15:09:41 +10:00
parent a962874fab
commit 45c4e45cbd

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name GoodTube
// @namespace http://tampermonkey.net/
// @version 5.002
// @version 5.003
// @description Loads Youtube videos from different sources. Also removes ads, shorts, etc.
// @author GoodTube
// @match https://*.youtube.com/*
@@ -18,22 +18,17 @@
(function() {
'use strict';
// Create variables
let goodTube_loadAttempts = 0;
let goodTube_loadTimeout = false;
// Define load function
function goodTube_load() {
function goodTube_load(loadAttempts) {
// If it's the first load attempt
if (goodTube_loadAttempts === 0) {
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
goodTube_loadAttempts++;
if (goodTube_loadAttempts >= 9) {
if (loadAttempts >= 9) {
// Debug message
console.log('[GoodTube] GoodTube could not be loaded');
@@ -43,30 +38,28 @@
return;
}
// Increment the load attempts
loadAttempts++;
// Load GoodTube
fetch('https://raw.githubusercontent.com/goodtube4u/GoodTube/main/goodtube.min.js')
// Success
.then(response => response.text())
// If we got a response
.then(data => {
// Put GoodTube code into a <script> tag
let element = document.createElement('script');
element.innerHTML = data;
document.head.appendChild(element);
})
// If anything went wrong
// Error
.catch((error) => {
// Clear the load timeout
if (goodTube_loadTimeout) {
clearTimeout(goodTube_loadTimeout);
}
// Try again after 500ms
goodTube_loadTimeout = setTimeout(function() {
goodTube_load();
setTimeout(function() {
goodTube_load(loadAttempts);
}, 500);
});
}
// Load GoodTube
goodTube_load();
goodTube_load(0);
})();