Initial commit
This commit is contained in:
commit
e1a9675a93
|
@ -0,0 +1,3 @@
|
|||
# Open With FreeTube
|
||||
|
||||
This extension adds a **right-click menu item** to YouTube (or Invidious) links which will open them with FreeTube
|
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 769 B |
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
|
||||
"manifest_version": 2,
|
||||
"name": "Open with FreeTube",
|
||||
"description": "Adds a context menu item to open YouTube links in FreeTube",
|
||||
"author": "rail5",
|
||||
"version": "1.0",
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"strict_min_version": "60.0a1",
|
||||
"id": "open-with-freetube@rail5.org"
|
||||
}
|
||||
},
|
||||
"icons": {
|
||||
"48": "icon/48.png",
|
||||
"128": "icon/128.png",
|
||||
"256": "icon/256.png"
|
||||
},
|
||||
|
||||
"background": {
|
||||
"scripts": ["src/main.js"]
|
||||
},
|
||||
|
||||
"permissions": [
|
||||
"menus",
|
||||
"<all_urls>"
|
||||
]
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
'use strict';
|
||||
|
||||
const itemId = "open-with-freetube";
|
||||
|
||||
browser.menus.onClicked.addListener((info, tab) => {
|
||||
if (info.menuItemId === itemId) {
|
||||
// Append 'freetube:' to the beginning of the link & trim everything before "/watch?v="
|
||||
let freetubelink = "freetube:" + info.linkUrl.slice(info.linkUrl.indexOf("/watch?v="));
|
||||
// Open the new link
|
||||
browser.tabs.update(tab.id, {
|
||||
url: freetubelink
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function createMenuItem() {
|
||||
browser.menus.create({
|
||||
id: itemId,
|
||||
title: "Open with FreeTube",
|
||||
contexts: ["link"]
|
||||
});
|
||||
browser.menus.refresh();
|
||||
}
|
||||
|
||||
function destroyMenuItem() {
|
||||
browser.menus.remove(itemId);
|
||||
browser.menus.refresh();
|
||||
}
|
||||
|
||||
browser.menus.onShown.addListener(info => {
|
||||
if (!info.linkUrl) {
|
||||
// Destroy if not a link
|
||||
destroyMenuItem();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(info.linkUrl.includes("/watch?v="))) {
|
||||
// Destroy if not a YouTube watch link
|
||||
destroyMenuItem();
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.linkUrl.includes("freetube:/")) {
|
||||
// Destroy if already a FreeTube link
|
||||
destroyMenuItem();
|
||||
return;
|
||||
}
|
||||
// Add the menu item if we've passed the checks so far without returning
|
||||
createMenuItem();
|
||||
|
||||
let linkElement = document.createElement("a");
|
||||
linkElement.href = info.linkUrl;
|
||||
});
|
Loading…
Reference in New Issue