adblocking thanks to custom ad filters

derived from uBlock Origin: https://github.com/uBlockOrigin/uAssets/issues/17495
This commit is contained in:
Thanasis Trispiotis
2023-04-20 20:07:44 +03:00
parent eb93fbc35d
commit 26c8a38350
9 changed files with 39 additions and 66 deletions

View File

@@ -13,10 +13,9 @@ const settings = {
api: "api",
menuBar: "menuBar",
playBackControl: "playBackControl",
muteArtists: "muteArtists",
mutedArtists: "mutedArtists",
skipArtists: "skipArtists",
skippedArtists: "skippedArtists",
adBlock: "adBlock",
disableBackgroundThrottle: "disableBackgroundThrottle",
apiSettings: {
root: "apiSettings",

View File

@@ -1,5 +1,5 @@
require("@electron/remote/main").initialize();
const { app, BrowserWindow, components, globalShortcut, ipcMain, protocol } = require("electron");
const { app, BrowserWindow, components, globalShortcut, ipcMain, protocol, session } = require("electron");
const {
settings,
store,
@@ -146,6 +146,16 @@ function addGlobalShortcuts() {
app.on("ready", async () => {
if (isMainInstanceOrMultipleInstancesAllowed()) {
await components.whenReady();
// Adblock
if (store.get(settings.adBlock)) {
const filter = { urls: ["https://listen.tidal.com/*"] };
session.defaultSession.webRequest.onBeforeRequest(filter, (details, callback) => {
if (details.url.match(/\d\?country/)) callback({ cancel: true });
else callback({ cancel: false });
});
}
createWindow();
addMenu(mainWindow);
createSettingsWindow();

View File

@@ -3,15 +3,14 @@ let trayIcon,
mpris,
enableCustomHotkeys,
enableDiscord,
muteArtists,
skipArtists,
notifications,
playBackControl,
api,
port,
menuBar,
mutedArtists,
skippedArtists,
adBlock,
disableBackgroundThrottle,
singleInstance,
disableHardwareMediaKeys,
@@ -36,10 +35,9 @@ function refreshSettings() {
enableCustomHotkeys.checked = store.get(settings.enableCustomHotkeys);
enableDiscord.checked = store.get(settings.enableDiscord);
minimizeOnClose.checked = store.get(settings.minimizeOnClose);
muteArtists.checked = store.get(settings.muteArtists);
mutedArtists.value = store.get(settings.mutedArtists).join("\n");
skipArtists.checked = store.get(settings.skipArtists);
skippedArtists.value = store.get(settings.skippedArtists).join("\n");
adBlock.checked = store.get(settings.adBlock);
singleInstance.checked = store.get(settings.singleInstance);
disableHardwareMediaKeys.checked = store.get(settings.flags.disableHardwareMediaKeys);
gpuRasterization.checked = store.get(settings.flags.gpuRasterization);
@@ -121,10 +119,9 @@ window.addEventListener("DOMContentLoaded", () => {
mpris = get("mprisCheckbox");
enableCustomHotkeys = get("enableCustomHotkeys");
enableDiscord = get("enableDiscord");
muteArtists = get("muteArtists");
mutedArtists = get("mutedArtists");
skipArtists = get("skipArtists");
skippedArtists = get("skippedArtists");
adBlock = get("adBlock");
disableBackgroundThrottle = get("disableBackgroundThrottle");
singleInstance = get("singleInstance");
disableHardwareMediaKeys = get("disableHardwareMediaKeys");
@@ -142,10 +139,9 @@ window.addEventListener("DOMContentLoaded", () => {
addInputListener(enableCustomHotkeys, settings.enableCustomHotkeys);
addInputListener(enableDiscord, settings.enableDiscord);
addInputListener(minimizeOnClose, settings.minimizeOnClose);
addInputListener(muteArtists, settings.muteArtists);
addTextAreaListener(mutedArtists, settings.mutedArtists);
addInputListener(skipArtists, settings.skipArtists);
addTextAreaListener(skippedArtists, settings.skippedArtists);
addInputListener(adBlock, settings.adBlock);
addInputListener(disableBackgroundThrottle, settings.disableBackgroundThrottle);
addInputListener(singleInstance, settings.singleInstance);
addInputListener(disableHardwareMediaKeys, settings.flags.disableHardwareMediaKeys);

View File

@@ -52,17 +52,6 @@
<span class="switch__slider"></span>
</label>
</div>
<div class="group__option">
<div class="group__description">
<h4>Mute Artists automatically</h4>
<p>The following list of artists (1 per line) will be muted automatically.</p>
</div>
<label class="switch">
<input id="muteArtists" type="checkbox">
<span class="switch__slider"></span>
</label>
</div>
<textarea id="mutedArtists" class="textarea" cols="40" rows="5" spellcheck="false"></textarea>
<div class="group__option">
<div class="group__description">
<h4>Skip Artists automatically</h4>
@@ -74,6 +63,16 @@
</label>
</div>
<textarea id="skippedArtists" class="textarea" cols="40" rows="5" spellcheck="false"></textarea>
<div class="group__option">
<div class="group__description">
<h4>Block ads</h4>
<p>Enjoys ad-free playback with video feature enabled for free accounts.</p>
</div>
<label class="switch">
<input id="adBlock" type="checkbox">
<span class="switch__slider"></span>
</label>
</div>
</div>
<div class="group">

View File

@@ -13,7 +13,6 @@ const appName = "Tidal Hifi";
let currentSong = "";
let player;
let currentPlayStatus = statuses.paused;
let isMutedArtist = true;
const elements = {
play: '*[data-test="play"]',
@@ -329,7 +328,6 @@ setInterval(function () {
const title = elements.getText("title");
const artists = elements.getArtists();
skipArtistsIfFoundInSkippedArtistsList(artists);
muteArtistIfFoundInMutedArtistsList(artists); // doing this here so that nothing can possibly fail before we call this function
const album = elements.getAlbumName();
const current = elements.getText("current");
@@ -381,24 +379,6 @@ setInterval(function () {
() => {}
);
/**
* Checks whether the current artist is included in the "muted artists" list and if so it will automatically mute the player
*/
function muteArtistIfFoundInMutedArtistsList(artists) {
if (store.get(settings.muteArtists)) {
const mutedArtists = store.get(settings.mutedArtists);
if (mutedArtists.find((artist) => artist === artists) !== undefined) {
if (!elements.isMuted()) {
isMutedArtist = true;
elements.click("volume");
}
} else if (isMutedArtist && elements.isMuted()) {
elements.click("volume");
isMutedArtist = false;
}
}
}
/**
* automatically skip a song if the artists are found in the list of artists to skip
* @param {*} artists list of artists to skip

View File

@@ -10,10 +10,9 @@ const store = new Store({
notifications: true,
api: true,
playBackControl: true,
muteArtists: false,
mutedArtists: ["TIDAL"],
skipArtists: false,
skippedArtists: [""],
adBlock: false,
disableBackgroundThrottle: true,
menuBar: true,
apiSettings: {