diff options
Diffstat (limited to 'content/syoutube')
-rw-r--r-- | content/syoutube/index.json | 6 | ||||
-rw-r--r-- | content/syoutube/youtube.js | 61 | ||||
-rw-r--r-- | content/syoutube/youtube_yewtube_redirection.js | 19 |
3 files changed, 22 insertions, 64 deletions
diff --git a/content/syoutube/index.json b/content/syoutube/index.json index 0650c42..4a3171b 100644 --- a/content/syoutube/index.json +++ b/content/syoutube/index.json @@ -1,6 +1,6 @@ { "type" : "script", -"name" : "youtube->yewtu.be", -"sha256" : "8fade4c6d87cb717289c382f71f1aaa95f8122041eb173d5e1267c13e68c56e1", -"location" : "youtube.js" +"name" : "youtube_2_yewtube_redirection", +"sha256" : "5a6b0495f122459cae22d921c3719bc5c449f30eefcc070e8aa2b27cf4e01b70", +"location" : "youtube_yewtube_redirection.js" } diff --git a/content/syoutube/youtube.js b/content/syoutube/youtube.js deleted file mode 100644 index 2486bd4..0000000 --- a/content/syoutube/youtube.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright (C) 2021, Wojtek Kosior - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the CC0 1.0 Universal License as published by - * the Creative Commons Corporation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * CC0 1.0 Universal License for more details. - * Available under the terms of Creative Commons Zero. - */ - -/* Use with https://www.youtube.com/*** */ - -/* Redirect youtube.com to yewtu.be */ - -function decode_query_options(url) -{ - const query_options = {}; - const match = /^[^?]*\?(.*)/.exec(url); - if (!match) - return query_options; - - for (const opt of match[1].split("&")) { - const [key, val] = - /^([^=]*)=?(.*)/.exec(opt).splice(1, 2).map(decodeURIComponent); - query_options[key] = val; - } - - return query_options; -} - -function encode_query_options(query_options) -{ - return Object.entries(query_options) - .map(ar => ar.map(encodeURIComponent).join("=")).join("&"); -} - -function remake_url(youtube_url) -{ - const query_options = decode_query_options(youtube_url); - - let endpoint = ""; - - const match = /^(?:(?:https?)?\/\/)?[^/]*\/([^?]*)/.exec(youtube_url); - if (match) - endpoint = match[1]; - - if (/^embed\//.test(query_options.v)) - endpoint = query_options.v; - - if (/^embed\/.+/.test(endpoint)) - delete query_options.v - - const encoded_options = encode_query_options(query_options); - return `https://yewtu.be/${endpoint}?${encoded_options}`; -} - -window.location.href = remake_url(document.URL); diff --git a/content/syoutube/youtube_yewtube_redirection.js b/content/syoutube/youtube_yewtube_redirection.js new file mode 100644 index 0000000..308771e --- /dev/null +++ b/content/syoutube/youtube_yewtube_redirection.js @@ -0,0 +1,19 @@ +/** + * Copyright (C) 2021, Wojtek Kosior + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the CC0 1.0 Universal License as published by + * the Creative Commons Corporation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * CC0 1.0 Universal License for more details. + * Available under the terms of Creative Commons Zero. + */ + +/* Use with https://www.youtube.com/*** */ + +/* Redirect youtube.com to yewtu.be */ + +window.location.href = make_yewtube_url(document.URL); |