From 7822515bc8d08b1be8b451bc206668c395a6c419 Mon Sep 17 00:00:00 2001 From: loma-one Date: Sun, 3 Dec 2023 13:07:45 +0100 Subject: [PATCH 1/4] Dateien nach "invidious" hochladen Replaces links to youtube.com to an invidious instance in all displays of postings on a node. --- invidious/invidious.php | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 invidious/invidious.php diff --git a/invidious/invidious.php b/invidious/invidious.php new file mode 100644 index 00000000..4ff57fc0 --- /dev/null +++ b/invidious/invidious.php @@ -0,0 +1,64 @@ + + * + */ + +use Friendica\App; +use Friendica\Core\Hook; +use Friendica\Core\Renderer; +use Friendica\DI; + +function invidious_install() +{ + Hook::register('prepare_body_final', 'addon/invidious/invidious.php', 'invidious_render'); +} + +/* Handle the send data from the admin settings + */ +function invidious_addon_admin_post() +{ + DI::config()->set('invidious', 'server', rtrim(trim($_POST['invidiousserver']), '/')); +} + +/* Hook into the admin settings to let the admin choose an + * invidious server to use for the replacement. + */ +function invidious_addon_admin(string &$o) +{ + $invidiousserver = DI::config()->get('invidious', 'server'); + $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/invidious/'); + $o = Renderer::replaceMacros($t, [ + '$settingdescription' => DI::l10n()->t('Which Invidious server shall be used for the replacements in the post bodies? Use the URL with servername and protocol. See %s for a list of available public Invidious servers.', 'https://redirect.invidious.io'), + '$invidiousserver' => ['invidiousserver', DI::l10n()->t('Invidious server'), $invidiousserver, 'https://example.com'], + '$submit' => DI::l10n()->t('Save Settings'), + ]); +} + +/* + * replace "youtube.com" with the chosen Invidious instance + */ +function invidious_render(array &$b) +{ + // this needs to be a system setting + $replaced = false; + $invidious = DI::config()->get('invidious', 'server', 'https://invidio.us'); + if (strstr($b['html'], 'https://www.youtube.com')) { + $b['html'] = str_replace('https://www.youtube.com', $invidious, $b['html']); + $replaced = true; + } + if (strstr($b['html'], 'https://youtube.com')) { + $b['html'] = str_replace('https://youtube.com', $invidious, $b['html']); + $replaced = true; + } + if (strstr($b['html'], 'https://youtu.be')) { + $b['html'] = str_replace('https://youtu.be', $invidious, $b['html']); + $replaced = true; + } + if ($replaced) { + $b['html'] .= '

' . DI::l10n()->t('(Invidious addon enabled: YouTube links via %s)', $invidious) . '

'; + } +} From dc2f7a7d74c3b7bdc6a522e527fdf5dbc14d9011 Mon Sep 17 00:00:00 2001 From: loma-one Date: Sun, 3 Dec 2023 13:09:02 +0100 Subject: [PATCH 2/4] Dateien nach "invidious/templates" hochladen --- invidious/templates/admin.tpl | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 invidious/templates/admin.tpl diff --git a/invidious/templates/admin.tpl b/invidious/templates/admin.tpl new file mode 100644 index 00000000..1db85ff9 --- /dev/null +++ b/invidious/templates/admin.tpl @@ -0,0 +1,5 @@ +

{{$settingdescription}}

+ +{{include file="field_input.tpl" field=$invidiousserver}} + +
From 4df65f0bafbcb1bb6f3c28b415065e6840efeb8d Mon Sep 17 00:00:00 2001 From: loma-one Date: Sun, 3 Dec 2023 13:11:50 +0100 Subject: [PATCH 3/4] Dateien nach "invidious/lang/C" hochladen --- invidious/lang/C/messages.po | 1 + 1 file changed, 1 insertion(+) create mode 100644 invidious/lang/C/messages.po diff --git a/invidious/lang/C/messages.po b/invidious/lang/C/messages.po new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/invidious/lang/C/messages.po @@ -0,0 +1 @@ + From 6b87c472da3b84d26c7fc90dd3a7f97b7b64f32a Mon Sep 17 00:00:00 2001 From: loma-one Date: Sun, 3 Dec 2023 13:12:19 +0100 Subject: [PATCH 4/4] Dateien nach "invidious" hochladen --- invidious/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 invidious/README.md diff --git a/invidious/README.md b/invidious/README.md new file mode 100644 index 00000000..0f91fa02 --- /dev/null +++ b/invidious/README.md @@ -0,0 +1,4 @@ +invidious Addon for Friendica +========================== + +This addon will replace "youtube.com" with the chosen Invidious instance