From 84ae535756a7823a533d6f281aa81bb86eec062c Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 4 May 2025 20:44:37 +0200 Subject: [PATCH] booru: add domain name to go to source button --- .../quickshell/modules/common/functions/string_utils.js | 5 +++++ .../quickshell/modules/sidebarLeft/anime/BooruImage.qml | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.config/quickshell/modules/common/functions/string_utils.js b/.config/quickshell/modules/common/functions/string_utils.js index 82cae4e72..c3884e5d9 100644 --- a/.config/quickshell/modules/common/functions/string_utils.js +++ b/.config/quickshell/modules/common/functions/string_utils.js @@ -3,3 +3,8 @@ function format(str, ...args) { typeof args[index] !== 'undefined' ? args[index] : match ); } + +function getDomain(url) { + const match = url.match(/^(?:https?:\/\/)?(?:www\.)?([^\/]+)/); + return match ? match[1] : null; +} diff --git a/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml b/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml index 38a20ed13..6c3b00b51 100644 --- a/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml +++ b/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml @@ -1,6 +1,7 @@ import "root:/" import "root:/modules/common" import "root:/modules/common/widgets" +import "root:/modules/common/functions/string_utils.js" as StringUtils import Qt.labs.platform import QtQuick import QtQuick.Controls @@ -147,17 +148,17 @@ Button { MenuButton { id: openFileLinkButton Layout.fillWidth: true - buttonText: "Open file link" + buttonText: qsTr("Open file link") onClicked: { root.showActions = false - // Hyprland.dispatch("global quickshell:sidebarLeftClose") Hyprland.dispatch(`exec xdg-open '${root.imageData.file_url}'`) } } MenuButton { id: sourceButton + visible: root.imageData.source && root.imageData.source.length > 0 Layout.fillWidth: true - buttonText: "Go to source" + buttonText: StringUtils.format(qsTr("Go to source ({0})"), StringUtils.getDomain(root.imageData.source)) enabled: root.imageData.source && root.imageData.source.length > 0 onClicked: { root.showActions = false @@ -171,7 +172,6 @@ Button { buttonText: "Download" onClicked: { root.showActions = false - // Hyprland.dispatch("global quickshell:sidebarLeftClose") Hyprland.dispatch(`exec curl '${root.imageData.file_url}' -o '${root.imageData.is_nsfw ? root.nsfwPath : root.downloadPath}/${root.fileName}' && notify-send '${qsTr("Download complete")}' '${root.downloadPath}/${root.fileName}'`) } }