Skip to content

Commit

Permalink
Merge pull request #1 from sjehuda/patch-1
Browse files Browse the repository at this point in the history
Use URL Interface
  • Loading branch information
glitsj16 authored Feb 28, 2023
2 parents e640c86 + fd06d9e commit dae799a
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions fjyt.user.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
// ==UserScript==
// @name Firejail :: YT Handler
// @name Firejail :: YT Handler
// @description Relay Youtube URL's to external firejailed media player.
// @include *
// @grant none
// @include *
// @grant none
// ==/UserScript==

(function() {
const keywords = [
'.youtube.com',
'.youtu.be']

// turn YT links into custom fjyt protocol URL's
for(var i = 0; i < document.links.length; i++) {
var elem = document.links[i];

// https://gist.github.com/brunodles/927fd8feaaccdbb9d02b
if (elem.href.match((?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([\w\-_]+)\&?)) {
var orig_url = elem.href;
elem.href = "fjyt://" + orig_url;
for (let i = 0; i < keywords.length; i++) {
// TODO regex
for (const elem of document.querySelectorAll('a[href*="' + keywords[i] + '"]')) {
url = new URL(elem.href);
if (url.origin.endsWith('.com')) {
//elem.href = 'fjyt://' + elem.href
elem.href = fjURL(url);
} else {
// TODO regex
if (url.pathname.includes('embed') ||
url.pathname.includes('watch')) {
//elem.href = 'fjyt://' + elem.href
elem.href = fjURL(url);
}
}
}
}

})();
// Turn YT links into custom fjyt protocol URL's
function fjURL(url) {
url.protocol = 'fjyt:';
url.toString();
return url
}

0 comments on commit dae799a

Please sign in to comment.