Add files via upload

This commit is contained in:
kodxana 2019-10-19 23:51:45 +02:00 committed by GitHub
parent 4d52f72166
commit 271fca44fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 0 deletions

50
background.js Normal file
View file

@ -0,0 +1,50 @@
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(tab.url.includes('watch?')) {
let videoId = getVideoId(tab.url)
validateVideo(videoId)
}
});
function getVideoId(videoUrl) {
var videoId = videoUrl.split('v=')[1]
var ampersandPosition = videoId.indexOf('&')
if(ampersandPosition != -1) {
videoId = videoId.substring(0, ampersandPosition)
}
return videoId
}
chrome.runtime.onMessage.addListener(function(request, sender) {
chrome.tabs.update(sender.tab.id, {url: request.redirect});
});
function validateVideo (id) {
let url = 'https://cors-anywhere.herokuapp.com/https://api.lbry.com/yt/resolve?video_ids=' + id
console.log('Calling url: ' + url)
var request = new Request(
url,
{
method: 'GET',
headers: new Headers({ 'Content-Type': 'application/json' })
}
)
fetch(request)
.then(function(resp) {
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)
chrome.tabs.update({url: url});
}
});
}

16
manifest.json Normal file
View file

@ -0,0 +1,16 @@
{
"name": "Watch on LBRY",
"version": "1.0",
"permissions": [
"https://www.youtube.com/watch?v=*",
"tabs"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_title": "Test"
},
"manifest_version": 2
}