mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-30 17:01:30 +00:00
Add files via upload
This commit is contained in:
parent
4d52f72166
commit
271fca44fb
2 changed files with 66 additions and 0 deletions
50
background.js
Normal file
50
background.js
Normal 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
16
manifest.json
Normal 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
|
||||
}
|
Loading…
Add table
Reference in a new issue