-
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
Showing
2 changed files
with
16 additions
and
21 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 |
---|---|---|
@@ -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; |
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