mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
Fix off switch not working
This commit is contained in:
parent
c155eeb4a7
commit
345bf471d9
3 changed files with 23 additions and 26 deletions
|
@ -9,7 +9,6 @@
|
||||||
],
|
],
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": [
|
"scripts": [
|
||||||
"scripts/browserActionOnClicked.js",
|
|
||||||
"scripts/runtimeOnStartup.js",
|
"scripts/runtimeOnStartup.js",
|
||||||
"scripts/storageOnChanged.js",
|
"scripts/storageOnChanged.js",
|
||||||
"scripts/tabOnUpdated.js"
|
"scripts/tabOnUpdated.js"
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
chrome.browserAction.onClicked.addListener(() => {
|
|
||||||
chrome.storage.local.get('enabled', ({ enabled }) => {
|
|
||||||
chrome.storage.local.set({ enabled: !enabled });
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,25 +1,28 @@
|
||||||
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
|
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||||
if (!changeInfo.url) return;
|
chrome.storage.local.get(async ({ enabled }) => {
|
||||||
const { id, type } = getId(tab.url);
|
if (!enabled) return;
|
||||||
if (!id) return;
|
if (!changeInfo.url) return;
|
||||||
|
const { id, type } = getId(tab.url);
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
const url = `https://cors-anywhere.herokuapp.com/https://api.lbry.com/yt/resolve?${type}_ids=${id}`;
|
const url = `https://cors-anywhere.herokuapp.com/https://api.lbry.com/yt/resolve?${type}_ids=${id}`;
|
||||||
const response = await fetch(url, { headers: { 'Content-Type': 'application/json' } });
|
const response = await fetch(url, { headers: { 'Content-Type': 'application/json' } });
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
console.log(json);
|
console.log(json);
|
||||||
const title = json.data[`${type}s`][id];
|
const title = json.data[`${type}s`][id];
|
||||||
if (!title) return;
|
if (!title) return;
|
||||||
console.log(title);
|
console.log(title);
|
||||||
|
|
||||||
chrome.storage.local.get('redirect', ({ redirect }) => {
|
chrome.storage.local.get('redirect', ({ redirect }) => {
|
||||||
console.log(redirect);
|
console.log(redirect);
|
||||||
let newUrl;
|
let newUrl;
|
||||||
if (redirect === "lbry.tv") {
|
if (redirect === "lbry.tv") {
|
||||||
newUrl = `https://lbry.tv/${title.replace(/^lbry:\/\//, "").replace(/#/g, ":")}`;
|
newUrl = `https://lbry.tv/${title.replace(/^lbry:\/\//, "").replace(/#/g, ":")}`;
|
||||||
} else if (redirect === "app") {
|
} else if (redirect === "app") {
|
||||||
newUrl = `lbry://${title.replace(/^lbry:\/\//, "")}`;
|
newUrl = `lbry://${title.replace(/^lbry:\/\//, "")}`;
|
||||||
}
|
}
|
||||||
chrome.tabs.update(tabId, { url: newUrl });
|
chrome.tabs.update(tabId, { url: newUrl });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue