Files
PipetRedirect/popup.js
2024-02-16 22:50:11 +01:00

14 lines
500 B
JavaScript

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.");
}
});
});