mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
Small fix
This commit is contained in:
parent
9282d40674
commit
eb8bdfab03
1 changed files with 9 additions and 10 deletions
|
@ -1,7 +1,11 @@
|
||||||
|
var loaded = false;
|
||||||
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
||||||
if(tab.url.includes('watch?')) {
|
if (changeInfo.status == 'complete' && tab.status == 'complete' && tab.url != undefined) {
|
||||||
let videoId = getVideoId(tab.url)
|
if(tab.url.includes('watch?') && !loaded) {
|
||||||
validateVideo(videoId)
|
loaded = true
|
||||||
|
let videoId = getVideoId(tab.url)
|
||||||
|
validateVideo(videoId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -14,11 +18,9 @@ function getVideoId(videoUrl) {
|
||||||
return videoId
|
return videoId
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function(request, sender) {
|
|
||||||
chrome.tabs.update(sender.tab.id, {url: request.redirect});
|
|
||||||
});
|
|
||||||
|
|
||||||
function validateVideo (id) {
|
function validateVideo (id) {
|
||||||
|
loaded = false
|
||||||
let url = 'https://cors-anywhere.herokuapp.com/https://api.lbry.com/yt/resolve?video_ids=' + id
|
let url = 'https://cors-anywhere.herokuapp.com/https://api.lbry.com/yt/resolve?video_ids=' + id
|
||||||
console.log('Calling url: ' + url)
|
console.log('Calling url: ' + url)
|
||||||
|
|
||||||
|
@ -35,13 +37,10 @@ function validateVideo (id) {
|
||||||
return resp.json();
|
return resp.json();
|
||||||
})
|
})
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
console.log('Success!')
|
|
||||||
let title = data.data.videos[id]
|
let title = data.data.videos[id]
|
||||||
|
|
||||||
|
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
let url = "https://open.lbry.com/" + title
|
let url = "https://open.lbry.tv/" + title
|
||||||
console.log(url)
|
|
||||||
chrome.tabs.update({url: url});
|
chrome.tabs.update({url: url});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue