From ef222f354d5aaa1b6f22c991e0e0c5bdd12a5fdc Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 5 May 2024 07:20:07 +0700 Subject: [PATCH] sideleft: booru qol - '+' gives next page - tags now get appended instead of sent --- .config/ags/modules/sideleft/apis/booru.js | 45 ++++++++++++++++------ .config/ags/services/booru.js | 6 ++- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/.config/ags/modules/sideleft/apis/booru.js b/.config/ags/modules/sideleft/apis/booru.js index 1aa9eabca..dcd9545fc 100644 --- a/.config/ags/modules/sideleft/apis/booru.js +++ b/.config/ags/modules/sideleft/apis/booru.js @@ -19,12 +19,31 @@ 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/*'`); -const CommandButton = (command) => Button({ - className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small', - onClicked: () => sendMessage(command), - setup: setupCursorHover, - label: command, -}); +const TagButton = (command) => { + const plusSign = Revealer({ + transition: 'slide_right', + revealChild: false, + className: 'margin-right-5', + child: Label({ + label: '+', + }) + }); + return Button({ + className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small', + onClicked: () => { chatEntry.buffer.text += `${command} ` }, + onHover: () => plusSign.revealChild = true, + onHoverLost: () => plusSign.revealChild = false, + setup: setupCursorHover, + child: Box({ + children: [ + plusSign, + Label({ + label: command, + }), + ] + }) + }); +} export const booruTabIcon = Box({ hpack: 'center', @@ -271,7 +290,7 @@ const BooruPage = (taglist, serviceName = 'Booru') => { hpack: 'fill', className: 'spacing-h-5', children: [ - ...taglist.map((tag) => CommandButton(tag)), + ...taglist.map((tag) => TagButton(tag)), Box({ hexpand: true }), ] }) @@ -420,8 +439,8 @@ const booruTags = Revealer({ child: Box({ className: 'spacing-h-5', children: [ - CommandButton('*'), - CommandButton('hololive'), + TagButton('( * )'), + TagButton('hololive'), ] }) }), @@ -433,7 +452,7 @@ const booruTags = Revealer({ export const booruCommands = Box({ className: 'spacing-h-5', setup: (self) => { - self.pack_end(CommandButton('/clear'), false, false, 0); + self.pack_end(TagButton('/clear'), false, false, 0); self.pack_start(Button({ className: 'sidebar-chat-chip-toggle', setup: setupCursorHover, @@ -455,7 +474,11 @@ const clearChat = () => { // destroy!! export const sendMessage = (text) => { // Commands - if (text.startsWith('/')) { + if (text.startsWith('+')) { // Next page + const lastQuery = BooruService.queries.at(-1); + BooruService.fetch(`${lastQuery.realTagList.join(' ')} ${lastQuery.page + 1}`) + } + else if (text.startsWith('/')) { if (text.startsWith('/clear')) clearChat(); else if (text.startsWith('/safe')) { BooruService.nsfw = false; diff --git a/.config/ags/services/booru.js b/.config/ags/services/booru.js index b9b7aa53a..d00643e62 100644 --- a/.config/ags/services/booru.js +++ b/.config/ags/services/booru.js @@ -80,14 +80,14 @@ class BooruService extends Service { async fetch(msg) { // Init - const userArgs = `${msg}${this._nsfw ? '' : ' rating:safe'}`.split(/\s+/); + const userArgs = `${msg}${this._nsfw || !msg.includes('safe') ? '' : ' rating:safe'}`.split(/\s+/); let taglist = []; let page = 1; // Construct body/headers for (let i = 0; i < userArgs.length; i++) { const thisArg = userArgs[i].trim(); - if (thisArg.length == 0 || thisArg == '.' || thisArg == '*') continue; + if (thisArg.length == 0 || thisArg == '.' || thisArg.includes('*')) continue; else if(!isNaN(thisArg)) page = parseInt(thisArg); else taglist.push(thisArg); } @@ -95,6 +95,8 @@ class BooruService extends Service { this._queries.push({ providerName: APISERVICES[this._mode].name, taglist: taglist.length == 0 ? ['*', `${page}`] : [...taglist, `${page}`], + realTagList: taglist, + page: page, }); this.emit('newResponse', newMessageId); const params = {