mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
Added new things
- Turn ON/OFF Switch - Detection of channels pages
This commit is contained in:
parent
408773acd5
commit
b8c92bdbd0
1 changed files with 53 additions and 1 deletions
|
@ -1,14 +1,57 @@
|
||||||
var loaded = false;
|
var loaded = false;
|
||||||
|
var enable = false;
|
||||||
|
|
||||||
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
||||||
if (changeInfo.status == 'complete' && tab.status == 'complete' && tab.url != undefined) {
|
if (changeInfo.status == 'complete' && tab.status == 'complete' && tab.url != undefined && enable) {
|
||||||
if(tab.url.includes('watch?') && !loaded) {
|
if(tab.url.includes('watch?') && !loaded) {
|
||||||
loaded = true
|
loaded = true
|
||||||
let videoId = getVideoId(tab.url)
|
let videoId = getVideoId(tab.url)
|
||||||
validateVideo(videoId)
|
validateVideo(videoId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tab.url.includes('/channel/') && !loaded) {
|
||||||
|
loaded = true
|
||||||
|
//przypisujemy do zmiennej id kanału
|
||||||
|
let channelId = getChannelId(tab.url)
|
||||||
|
getInformationFromApi(channelId)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getChannelId(url) {
|
||||||
|
//pop obcina ostatni element z tablicy (zwraca ostatni element)
|
||||||
|
// to zwracam
|
||||||
|
// https://www.youtube.com/channel / UC-vYDJQiabg9BK8XTDPFspg
|
||||||
|
return url.split("/").pop()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getInformationFromApi(id) {
|
||||||
|
loaded = false
|
||||||
|
let url = 'https://cors-anywhere.herokuapp.com/https://api.lbry.com/yt/resolve?channel_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) {
|
||||||
|
let channel = data.data.channels[id]
|
||||||
|
if (channel != null) {
|
||||||
|
let url = "https://open.lbry.com/" + channel
|
||||||
|
chrome.tabs.update({url: url});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getVideoId(videoUrl) {
|
function getVideoId(videoUrl) {
|
||||||
var videoId = videoUrl.split('v=')[1]
|
var videoId = videoUrl.split('v=')[1]
|
||||||
var ampersandPosition = videoId.indexOf('&')
|
var ampersandPosition = videoId.indexOf('&')
|
||||||
|
@ -46,3 +89,12 @@ function validateVideo (id) {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chrome.browserAction.onClicked.addListener(function (tab) {
|
||||||
|
enable = enable ? false : true;
|
||||||
|
if(enable){
|
||||||
|
chrome.browserAction.setBadgeText({ text: 'ON' });
|
||||||
|
}else{
|
||||||
|
chrome.browserAction.setBadgeText({ text: 'OFF' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue