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) {
|
||||
if(tab.url.includes('watch?')) {
|
||||
let videoId = getVideoId(tab.url)
|
||||
validateVideo(videoId)
|
||||
if (changeInfo.status == 'complete' && tab.status == 'complete' && tab.url != undefined) {
|
||||
if(tab.url.includes('watch?') && !loaded) {
|
||||
loaded = true
|
||||
let videoId = getVideoId(tab.url)
|
||||
validateVideo(videoId)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -14,11 +18,9 @@ function getVideoId(videoUrl) {
|
|||
return videoId
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener(function(request, sender) {
|
||||
chrome.tabs.update(sender.tab.id, {url: request.redirect});
|
||||
});
|
||||
|
||||
function validateVideo (id) {
|
||||
loaded = false
|
||||
let url = 'https://cors-anywhere.herokuapp.com/https://api.lbry.com/yt/resolve?video_ids=' + id
|
||||
console.log('Calling url: ' + url)
|
||||
|
||||
|
@ -35,13 +37,10 @@ function validateVideo (id) {
|
|||
return resp.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
console.log('Success!')
|
||||
let title = data.data.videos[id]
|
||||
|
||||
|
||||
if (title != null) {
|
||||
let url = "https://open.lbry.com/" + title
|
||||
console.log(url)
|
||||
let url = "https://open.lbry.tv/" + title
|
||||
chrome.tabs.update({url: url});
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue