Skip to content

Commit

Permalink
1.0.0 (24121)
Browse files Browse the repository at this point in the history
  • Loading branch information
MStankiewiczOfficial committed Dec 14, 2024
1 parent 0ba059d commit 9101593
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.DS_Store
Binary file added out/RedirectTube-1.0.0.xpi
Binary file not shown.
11 changes: 11 additions & 0 deletions src/background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>background.js</title>
</head>
<body>
<script src="background.js"></script>
</body>
</html>
43 changes: 43 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
detectYT(changeInfo);
});

chrome.tabs.onActivated.addListener(function(activeInfo) {
chrome.tabs.get(activeInfo.tabId, function(tab) {
detectYT(tab);
});
});

function detectYT(changeInfo) {
openedUrl = changeInfo.url;
if (openedUrl) {
if (openedUrl.startsWith("https://www.youtube.com/watch?v=")) {
chrome.action.setIcon({ path: "img/icns/normal/64.png" });
} else {
chrome.action.setIcon({ path: "img/icns/grey/64.png" });
}
}
}

chrome.contextMenus.create({
id: "openInFreeTube",
title: "Open in FreeTube",
contexts: ["link"],
targetUrlPatterns: [
"*://www.youtube.com/*",
"*://youtube.com/*",
"*://youtu.be/*"
]
});

chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "openInFreeTube" && info.linkUrl) {
let newUrl = "freetube://" + info.linkUrl;
if (newUrl.includes("youtu.be")) {
const videoId = newUrl.split("/").pop();
newUrl = `freetube://https://www.youtube.com/watch?v=${videoId}`;
}
chrome.tabs.update({ url: newUrl });
console.log(newUrl);
}
});
Binary file added src/img/icns/grey/64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icns/normal/128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icns/normal/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icns/normal/256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icns/normal/32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icns/normal/48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icns/normal/512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icns/normal/64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/icns/normal/96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "RedirectTube",
"description": "Open YouTube links in FreeTube",
"author": "Michał Stankiewicz",
"version": "1.0.0",
"manifest_version": 3,
"icons": {
"16": "img/icns/normal/16.png",
"32": "img/icns/normal/32.png",
"48": "img/icns/normal/48.png",
"64": "img/icns/normal/64.png",
"96": "img/icns/normal/96.png",
"128": "img/icns/normal/128.png",
"256": "img/icns/normal/256.png",
"512": "img/icns/normal/512.png"
},
"background": {
"page": "background.html"
},
"permissions": [
"storage",
"tabs",
"activeTab",
"contextMenus"
],
"action": {
"default_popup": "popup.html"
},
"host_permissions": [
"http://*/*",
"https://*/*"
],
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "109.0"
}
}
}
12 changes: 12 additions & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<p id="errorText"></p>
<script src="popup.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions src/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var errorText = document.getElementById("errorText");

function openInFreeTube() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var url = tabs[0].url;
if (url.startsWith("https://www.youtube.com/watch?v=")) {
var freeTubeUrl = "freetube://" + url;
chrome.tabs.update(tabs[0].id, {url: freeTubeUrl});
window.close();
} else {
errorText.innerHTML = "Cannot open this page in FreeTube.";
}
});
}

document.addEventListener('DOMContentLoaded', function() {
openInFreeTube();
});

0 comments on commit 9101593

Please sign in to comment.