Skip to content

Commit

Permalink
Updated to latest js spec
Browse files Browse the repository at this point in the history
  • Loading branch information
suitangi committed Jan 27, 2024
1 parent 3a3030f commit 31bb70c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
35 changes: 15 additions & 20 deletions chrome-extension/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
var oldHref = document.location.href;
checkURL();


//function to check url and redirect if needed
function checkURL() {
let l = location.href;
if (l.startsWith('https://www.youtube.com/shorts/')) {
console.log('YTShorts2Vids (' + chrome.runtime.getManifest().version + ') URL Redirected');
console.log('Old URL: ' + l);
console.log(`YTShorts2Vids (${chrome.runtime.getManifest().version}) URL Redirected`);
console.log(`Old URL: ${l}`);
l = l.replace('https://www.youtube.com/shorts/', '');
l = 'https://www.youtube.com/watch?v=' + l;
console.log('New URL:' + l);
console.log(`New URL: ${l}`);
window.location.replace(l);
}
}

//on link change, check url again
window.onload = function() {
var bodyList = document.querySelector("body")

var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (oldHref != document.location.href) {
oldHref = document.location.href;
checkURL();
}
});
const observeUrlChange = () => {
let oldHref = document.location.href;
const body = document.querySelector("body");
const observer = new MutationObserver(mutations => {
if (oldHref !== document.location.href) {
oldHref = document.location.href;
checkURL();
}
});

var config = {
observer.observe(body, {
childList: true,
subtree: true
};

observer.observe(bodyList, config);
});
};

window.onload = observeUrlChange;
2 changes: 1 addition & 1 deletion chrome-extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Youtube Shorts to Videos",
"version": "1.0.0",
"version": "1.0.1",
"short_name": "YTShorts2Vids",
"description": "Automatically redirects Youtube shorts to videos.",
"manifest_version": 3,
Expand Down

0 comments on commit 31bb70c

Please sign in to comment.