forked from Shinonome/dots-hyprland
sideleft: booru qol
- '+' gives next page - tags now get appended instead of sent
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user