Added the base code for Beatbump #30
This commit is contained in:
parent
c5ef434b28
commit
39ee723245
|
@ -0,0 +1,117 @@
|
|||
"use strict";
|
||||
|
||||
import commonHelper from './common.js'
|
||||
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
||||
const targets = [
|
||||
/https?:\/\/music\.youtube\.com(\/.*|$)/,
|
||||
];
|
||||
let redirects = {
|
||||
"beatbump": {
|
||||
"normal": [
|
||||
"https://beatbump.ml"
|
||||
],
|
||||
"tor": []
|
||||
},
|
||||
};
|
||||
|
||||
const getRedirects = () => redirects;
|
||||
|
||||
function getCustomRedirects() {
|
||||
return {
|
||||
"beatbump": {
|
||||
"normal": [...beatbumpNormalRedirectsChecks, ...beatbumpNormalCustomRedirects]
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
function setYoutubeMusicRedirects(val) {
|
||||
redirects.beatbump = val;
|
||||
browser.storage.local.set({ youtubeMusicRedirects: redirects })
|
||||
console.log("youtubeMusicRedirects: ", val)
|
||||
}
|
||||
|
||||
let beatbumpNormalRedirectsChecks;
|
||||
const getBeatbumpNormalRedirectsChecks = () => beatbumpNormalRedirectsChecks;
|
||||
function setBeatbumpNormalRedirectsChecks(val) {
|
||||
beatbumpNormalRedirectsChecks = val;
|
||||
browser.storage.local.set({ beatbumpNormalRedirectsChecks })
|
||||
console.log("beatbumpNormalRedirectsChecks: ", val)
|
||||
}
|
||||
|
||||
let beatbumpNormalCustomRedirects = [];
|
||||
const getBeatbumpNormalCustomRedirects = () => beatbumpNormalCustomRedirects;
|
||||
function setBeatbumpNormalCustomRedirects(val) {
|
||||
beatbumpNormalCustomRedirects = val;
|
||||
browser.storage.local.set({ beatbumpNormalCustomRedirects })
|
||||
console.log("beatbumpNormalCustomRedirects: ", val)
|
||||
}
|
||||
|
||||
let disable;
|
||||
const getDisable = () => disable;
|
||||
function setDisable(val) {
|
||||
disable = val;
|
||||
browser.storage.local.set({ disableYoutubeMusic: disable })
|
||||
console.log("disableYoutubeMusic: ", disable)
|
||||
}
|
||||
|
||||
function isYoutubeMusic(url, initiator) {
|
||||
if (disable) return false
|
||||
return targets.some((rx) => rx.test(url.href));
|
||||
}
|
||||
|
||||
function redirect(url, type) {
|
||||
let instancesList = [...beatbumpNormalRedirectsChecks, ...beatbumpNormalCustomRedirects];
|
||||
if (instancesList.length === 0) return null;
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
|
||||
return `${randomInstance}${url.pathname}${url.search}`.replace("/watch?v=", "/listen?id=");
|
||||
}
|
||||
|
||||
async function init() {
|
||||
return new Promise((resolve) => {
|
||||
console.log("Init music")
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableYoutubeMusic",
|
||||
"youtubeMusicRedirects",
|
||||
|
||||
"beatbumpNormalRedirectsChecks",
|
||||
"beatbumpNormalCustomRedirects",
|
||||
|
||||
"youtubeMusicProtocol",
|
||||
],
|
||||
(result) => {
|
||||
disable = result.disableYoutubeMusic ?? false;
|
||||
|
||||
if (result.youtubeMusicRedirects) redirects = result.youtubeMusicRedirects;
|
||||
|
||||
beatbumpNormalRedirectsChecks = result.beatbumpNormalRedirectsChecks ?? [...redirects.beatbump.normal];
|
||||
console.log("beatbumpNormalRedirectsChecks", beatbumpNormalRedirectsChecks)
|
||||
beatbumpNormalCustomRedirects = result.beatbumpNormalCustomRedirects ?? [];
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
getRedirects,
|
||||
getCustomRedirects,
|
||||
setYoutubeMusicRedirects,
|
||||
|
||||
redirect,
|
||||
isYoutubeMusic,
|
||||
|
||||
getDisable,
|
||||
setDisable,
|
||||
|
||||
getBeatbumpNormalRedirectsChecks,
|
||||
setBeatbumpNormalRedirectsChecks,
|
||||
|
||||
getBeatbumpNormalCustomRedirects,
|
||||
setBeatbumpNormalCustomRedirects,
|
||||
|
||||
init,
|
||||
};
|
|
@ -12,11 +12,13 @@ import mediumHelper from "../../assets/javascripts/helpers/medium.js";
|
|||
import imgurHelper from "../../assets/javascripts/helpers/imgur.js";
|
||||
import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js";
|
||||
import exceptionsHelper from "../../assets/javascripts/helpers/exceptions.js";
|
||||
import youtubeMusicHelper from "../../assets/javascripts/helpers/youtubeMusic.js";
|
||||
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
||||
async function wholeInit() {
|
||||
youtubeHelper.init()
|
||||
youtubeMusicHelper.init()
|
||||
twitterHelper.init()
|
||||
instagramHelper.init()
|
||||
mapsHelper.init()
|
||||
|
@ -47,6 +49,8 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
|
||||
if (exceptionsHelper.isException(url, initiator)) newUrl = null;
|
||||
|
||||
else if (youtubeMusicHelper.isYoutubeMusic(url, initiator)) newUrl = youtubeMusicHelper.redirect(url, details.type)
|
||||
|
||||
else if (youtubeHelper.isYoutube(url, initiator)) newUrl = youtubeHelper.redirect(url, details.type)
|
||||
|
||||
else if (twitterHelper.isTwitter(url, initiator)) newUrl = twitterHelper.redirect(url);
|
||||
|
@ -156,18 +160,28 @@ function getMightyList() {
|
|||
return [
|
||||
...youtubeHelper.getCustomRedirects().invidious.normal,
|
||||
...youtubeHelper.getCustomRedirects().piped.normal,
|
||||
|
||||
...twitterHelper.getCustomRedirects().nitter.normal,
|
||||
|
||||
...youtubeMusicHelper.getCustomRedirects().beatbump.normal,
|
||||
|
||||
...instagramHelper.getCustomRedirects().bibliogram.normal,
|
||||
|
||||
...redditHelper.getCustomRedirects().libreddit.normal,
|
||||
...redditHelper.getCustomRedirects().teddit.normal,
|
||||
redditHelper.getCustomRedirects().desktop,
|
||||
redditHelper.getCustomRedirects().mobile,
|
||||
|
||||
...searchHelper.getCustomRedirects().searx.normal,
|
||||
...searchHelper.getCustomRedirects().whoogle.normal,
|
||||
|
||||
...translateHelper.getCustomRedirects().simplyTranslate.normal,
|
||||
...translateHelper.getCustomRedirects().lingva.normal,
|
||||
|
||||
...mediumHelper.getCustomRedirects().scribe.normal,
|
||||
|
||||
...imgurHelper.getCustomRedirects().rimgo.normal,
|
||||
|
||||
...wikipediaHelper.getCustomRedirects().wikiless.normal
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue