aboutsummaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-12-29 18:05:08 +0100
committerWojtek Kosior <koszko@koszko.org>2021-12-29 18:05:08 +0100
commitba1e6824e98c52e867d92cfdcb2a6d2a614fd67f (patch)
tree4b43f836336e8e5ea56023c161eb9bb0bd72c212 /content
parent7ccadc53efcc8919346a5be4a495fc95ad9db7b3 (diff)
downloadhaketilo-fixes-demo-ba1e6824e98c52e867d92cfdcb2a6d2a614fd67f.tar.gz
haketilo-fixes-demo-ba1e6824e98c52e867d92cfdcb2a6d2a614fd67f.zip
refactor yewtu.be URL generation into a js library
Diffstat (limited to 'content')
-rw-r--r--content/byoutube/index.json8
-rw-r--r--content/pyoutube/index.json2
-rw-r--r--content/syewtube_urls/index.json6
-rw-r--r--content/syewtube_urls/yewtube_urls.js (renamed from content/syoutube/youtube.js)10
-rw-r--r--content/syoutube/index.json6
-rw-r--r--content/syoutube/youtube_yewtube_redirection.js19
6 files changed, 40 insertions, 11 deletions
diff --git a/content/byoutube/index.json b/content/byoutube/index.json
new file mode 100644
index 0000000..2af4824
--- /dev/null
+++ b/content/byoutube/index.json
@@ -0,0 +1,8 @@
+{
+"type" : "bag",
+"name" : "youtube_2_yewtube_redirection",
+"components" : [
+["script", "youtube.com_2_yewtu.be_URL_converter"],
+["script", "youtube_2_yewtube_redirection"]
+]
+}
diff --git a/content/pyoutube/index.json b/content/pyoutube/index.json
index 89decd4..b33b736 100644
--- a/content/pyoutube/index.json
+++ b/content/pyoutube/index.json
@@ -1,5 +1,5 @@
{
"type" : "page",
"pattern" : "https://www.youtube.com/***",
-"payload" : ["script", "youtube->yewtu.be"]
+"payload" : ["bag", "youtube_2_yewtube_redirection"]
}
diff --git a/content/syewtube_urls/index.json b/content/syewtube_urls/index.json
new file mode 100644
index 0000000..df8330d
--- /dev/null
+++ b/content/syewtube_urls/index.json
@@ -0,0 +1,6 @@
+{
+"type" : "script",
+"name" : "youtube.com_2_yewtu.be_URL_converter",
+"sha256" : "ae2abac001a7256f4b4a66846264470b2898aa736a55f91022017ce7634dd1ae",
+"location" : "yewtube_urls.js"
+}
diff --git a/content/syoutube/youtube.js b/content/syewtube_urls/yewtube_urls.js
index 2486bd4..b013132 100644
--- a/content/syoutube/youtube.js
+++ b/content/syewtube_urls/yewtube_urls.js
@@ -12,9 +12,7 @@
* Available under the terms of Creative Commons Zero.
*/
-/* Use with https://www.youtube.com/*** */
-
-/* Redirect youtube.com to yewtu.be */
+/* Library to convert youtube.com URLs to yewtu.be URLs. */
function decode_query_options(url)
{
@@ -38,13 +36,13 @@ function encode_query_options(query_options)
.map(ar => ar.map(encodeURIComponent).join("=")).join("&");
}
-function remake_url(youtube_url)
+function make_yewtube_url(youtube_url)
{
const query_options = decode_query_options(youtube_url);
let endpoint = "";
- const match = /^(?:(?:https?)?\/\/)?[^/]*\/([^?]*)/.exec(youtube_url);
+ const match = /^(?:(?:https?:)?\/\/)?[^/]*\/([^?]*)/.exec(youtube_url);
if (match)
endpoint = match[1];
@@ -57,5 +55,3 @@ function remake_url(youtube_url)
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/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_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);