From c7d8f32c54ca285aaa932d42c2d7236ab293ac43 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 6 Apr 2025 15:25:20 +0200 Subject: [PATCH] booru buttons: show domain name --- .config/ags/modules/sideleft/apis/booru.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.config/ags/modules/sideleft/apis/booru.js b/.config/ags/modules/sideleft/apis/booru.js index 5ce97957d..03c21be4e 100644 --- a/.config/ags/modules/sideleft/apis/booru.js +++ b/.config/ags/modules/sideleft/apis/booru.js @@ -18,6 +18,16 @@ const USER_CACHE_DIR = GLib.get_user_cache_dir(); Utils.exec(`bash -c 'mkdir -p ${USER_CACHE_DIR}/ags/media/waifus'`); Utils.exec(`bash -c 'rm ${USER_CACHE_DIR}/ags/media/waifus/*'`); +function getDomainName(url) { + try { + const match = url.match(/^(?:https?:\/\/)?(?:www\.)?([^\/]+)/i); + return match ? match[1] : null; // Extract the domain name + } catch (error) { + print(`Invalid URL: ${url}`); + return null; + } +} + const TagButton = (command, entry) => Button({ className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small', // Interactions disabled for now because they aren't working @@ -203,12 +213,12 @@ const BooruPage = (taglist, serviceName = 'Booru') => { children: [ Box({ hexpand: true }), ImageAction({ - name: getString('Go to file url'), + name: `${getString('Go to file url')} (${getDomainName(data.file_url)})`, icon: 'file_open', action: () => execAsync(['xdg-open', `${data.file_url}`]).catch(print), }), ImageAction({ - name: getString('Go to source'), + name: `${getString('Go to source')} (${getDomainName(data.source)})`, icon: 'open_in_new', action: () => execAsync(['xdg-open', `${data.source}`]).catch(print), }),