-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ba059d
commit 9101593
Showing
16 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
.DS_Store |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |