Skip to content
This repository has been archived by the owner on Dec 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #333 from BlueWorld1/log-refactoring
Browse files Browse the repository at this point in the history
Log refactoring
  • Loading branch information
TheRealJoelmatic authored Jan 19, 2024
2 parents 3f7aef8 + 1de8cb4 commit e3281ae
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions Youtube-Ad-blocker-Reminder-Remover.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
//

//Set everything up here
if (debugMessages) console.log("Remove Adblock Thing: Script started ");
log("Script started")

if (adblocker) removeAds();
if (removePopup) popupRemover();
Expand Down Expand Up @@ -121,7 +121,7 @@
}

if (popup) {
if (debugMessages) console.log("Remove Adblock Thing: Popup detected, removing...");
log("Popup detected, removing...")

if(popupButton) popupButton.click();

Expand All @@ -134,7 +134,7 @@
fullScreenButton.dispatchEvent(mouseEvent);
}, 500);

if (debugMessages) console.log("Remove Adblock Thing: Popup removed");
log("Popup removed")
}

// Check if the video is paused after removing the popup
Expand All @@ -149,7 +149,7 @@
// undetected adblocker method
function removeAds()
{
if (debugMessages) console.log("Remove Adblock Thing: removeAds()");
log('removeAds()')

setInterval(() =>{

Expand Down Expand Up @@ -204,7 +204,7 @@
//
// Speed Skip Method
//
if (debugMessages) console.log("Remove Adblock Thing: Found Ad");
log('Found Ad')


const skipButtons = ['ytp-ad-skip-button-container', 'ytp-ad-skip-button-modern', '.videoAdUiSkipButton', '.ytp-ad-skip-button', '.ytp-ad-skip-button-modern', '.ytp-ad-skip-button' ];
Expand Down Expand Up @@ -234,7 +234,7 @@
video.currentTime = video.duration + randomNumber || 0;
}

if (debugMessages) console.log("Remove Adblock Thing: skipped Ad (✔️)");
log('skipped Ad (✔️)')

} else {

Expand Down Expand Up @@ -321,7 +321,7 @@
}
});

if (debugMessages) console.log("Remove Adblock Thing: Removed page ads (✔️)");
log("Removed page ads (✔️)")
}

// Unpause the video Works most of the time
Expand All @@ -332,7 +332,7 @@
// Simulate pressing the "k" key to unpause the video
document.dispatchEvent(keyEvent);
unpausedAfterSkip = 0;
if (debugMessages) console.log("Remove Adblock Thing: Unpaused video using 'k' key");
log("Unpaused video using 'k' key")
} else if (unpausedAfterSkip > 0) unpausedAfterSkip--;
}

Expand Down Expand Up @@ -362,7 +362,7 @@
const currentVersion = parseFloat(GM_info.script.version);

if (githubVersion > currentVersion) {
console.log('Remove Adblock Thing: A new version is available. Please update your script.');
log("Please update your script.")

if(updateModal.enable){
// if a version is skipped, don't show the update message again until the next version
Expand Down Expand Up @@ -422,16 +422,46 @@


} else {
console.log('Remove Adblock Thing: You have the latest version of the script.');
log('You have the latest version of the script.')
}
} else {
console.error('Remove Adblock Thing: Unable to extract version from the GitHub script.');
log("Unable to extract version from the GitHub script.", "e")
}
})
.catch(error => {
hasIgnoredUpdate = true;
console.error('Remove Adblock Thing: Error checking for updates:', error);
log("Error checking for updates:", "e", error)
});
hasIgnoredUpdate = true;
}

function log(log, level = 'l', ...args) {
if (debugMessages) {
const prefix = 'Remove Adblock Thing:'
const message = `${prefix} ${log}`;
switch (level) {
case 'e':
case 'err':
case 'error':
console.error(message, ...args);
break;
case 'l':
case 'log':
console.log(message, ...args);
break;
case 'w':
case 'warn':
case 'warning':
console.warn(message, ...args);
break;
case 'i':
case 'info':
default:
console.info(message, ...args);
break

}
}

}
})();

0 comments on commit e3281ae

Please sign in to comment.