Small fix

This commit is contained in:
kodxana 2019-10-20 00:16:01 +02:00 committed by GitHub
parent 9282d40674
commit eb8bdfab03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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});
}); });