Initial commit

This commit is contained in:
Andrew S. Rightenburg 2023-04-07 21:37:38 -04:00
commit e1a9675a93
6 changed files with 85 additions and 0 deletions

3
README.md Normal file
View File

@ -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

BIN
icon/128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
icon/256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
icon/48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

29
manifest.json Normal file
View File

@ -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>"
]
}

53
src/main.js Normal file
View File

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