-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sjehuda/patch-1
Use URL Interface
- Loading branch information
Showing
1 changed file
with
27 additions
and
13 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,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 | ||
} |