first commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.idea/
|
||||||
24
background.js
Normal file
24
background.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* chrome.runtime.onInstalled.addListener(() => {
|
||||||
|
chrome.action.setBadgeBackgroundColor({ color: '#FF0000' });
|
||||||
|
chrome.action.setBadgeText({text: 'ON'});
|
||||||
|
}); */
|
||||||
|
|
||||||
|
chrome.action.onClicked.addListener((tab) => {
|
||||||
|
// Ensure we have a valid tab ID
|
||||||
|
if (tab.id !== undefined) {
|
||||||
|
chrome.tabs.get(tab.id, (currentTab) => {
|
||||||
|
if (currentTab.url.includes('youtube.com/watch?v=')) {
|
||||||
|
const videoID = new URL(currentTab.url).searchParams.get('v');
|
||||||
|
if (videoID) {
|
||||||
|
const newURL = 'https://pip.turtel.xyz/watch?v=' + videoID;
|
||||||
|
chrome.tabs.update(currentTab.id, { url: newURL });
|
||||||
|
} else {
|
||||||
|
alert("This doesn't seem to be a valid YouTube video URL.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert("Please navigate to a YouTube video before clicking the extension icon.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
30
content.js
Normal file
30
content.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const button = document.createElement('button');
|
||||||
|
button.id = 'redirectBtn';
|
||||||
|
button.innerText = 'Watch on Pipet';
|
||||||
|
button.classList.add('main-button');
|
||||||
|
|
||||||
|
button.addEventListener('click', function() {
|
||||||
|
const videoID = window.location.search.match(/v=([a-zA-Z0-9_-]+)/);
|
||||||
|
|
||||||
|
if (videoID && videoID[1]) {
|
||||||
|
const newURL = 'https://pip.turtel.xyz/watch?v=' + videoID[1];
|
||||||
|
window.location.href = newURL;
|
||||||
|
} else {
|
||||||
|
alert("This doesn't seem to be a valid YouTube video URL.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function insertButtonIfTargetExists() {
|
||||||
|
const targetElement = document.getElementById('masthead').querySelector('ytd-topbar-menu-button-renderer');
|
||||||
|
if (targetElement && targetElement.parentElement) {
|
||||||
|
targetElement.parentElement.insertBefore(button, targetElement);
|
||||||
|
// If found and added, disconnect the observer
|
||||||
|
observer.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const observer = new MutationObserver(insertButtonIfTargetExists);
|
||||||
|
observer.observe(document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
BIN
icon128.png
Normal file
BIN
icon128.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
BIN
icon16.png
Normal file
BIN
icon16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
BIN
icon48.png
Normal file
BIN
icon48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
27
manifest.json
Normal file
27
manifest.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"manifest_version": 3,
|
||||||
|
"name": "Pipet redirector XD",
|
||||||
|
"version": "1.0",
|
||||||
|
"description": "Redirects from YouTube to Piped.video using the video's ID",
|
||||||
|
"permissions": ["tabs"],
|
||||||
|
"content_scripts": [{
|
||||||
|
"matches": ["https://www.youtube.com/watch*"],
|
||||||
|
"css": ["styles.css"],
|
||||||
|
"js": ["content.js"]
|
||||||
|
}],
|
||||||
|
"background": {
|
||||||
|
"service_worker": "background.js"
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"default_icon": {
|
||||||
|
"16": "icon16.png",
|
||||||
|
"48": "icon48.png",
|
||||||
|
"128": "icon128.png"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"icons": {
|
||||||
|
"16": "icon16.png",
|
||||||
|
"48": "icon48.png",
|
||||||
|
"128": "icon128.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
16
popup.html
Normal file
16
popup.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Redirect to Piped.video</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
width: 200px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<button id="redirectBtn">Redirect to Pipet</button>
|
||||||
|
<script src="popup.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
popup.js
Normal file
13
popup.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
document.getElementById('redirectBtn').addEventListener('click', function() {
|
||||||
|
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||||
|
var currentTab = tabs[0];
|
||||||
|
var videoID = currentTab.url.match(/watch\?v=([a-zA-Z0-9_-]+)/);
|
||||||
|
|
||||||
|
if(videoID && videoID[1]) {
|
||||||
|
var newURL = 'https://piped.video/watch?v=' + videoID[1];
|
||||||
|
chrome.tabs.update(currentTab.id, {url: newURL});
|
||||||
|
} else {
|
||||||
|
alert("This doesn't seem to be a valid YouTube video URL.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
12
styles.css
Normal file
12
styles.css
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
.main-button {
|
||||||
|
background: #FF0000;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 10px 15px;
|
||||||
|
font-size: 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
z-index: 9999;
|
||||||
|
box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user