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 'mkdir -p ${USER_CACHE_DIR}/ags/media/waifus'`);
|
||||||
Utils.exec(`bash -c 'rm ${USER_CACHE_DIR}/ags/media/waifus/*'`);
|
Utils.exec(`bash -c 'rm ${USER_CACHE_DIR}/ags/media/waifus/*'`);
|
||||||
|
|
||||||
const CommandButton = (command) => Button({
|
const TagButton = (command) => {
|
||||||
className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small',
|
const plusSign = Revealer({
|
||||||
onClicked: () => sendMessage(command),
|
transition: 'slide_right',
|
||||||
setup: setupCursorHover,
|
revealChild: false,
|
||||||
label: command,
|
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({
|
export const booruTabIcon = Box({
|
||||||
hpack: 'center',
|
hpack: 'center',
|
||||||
@@ -271,7 +290,7 @@ const BooruPage = (taglist, serviceName = 'Booru') => {
|
|||||||
hpack: 'fill',
|
hpack: 'fill',
|
||||||
className: 'spacing-h-5',
|
className: 'spacing-h-5',
|
||||||
children: [
|
children: [
|
||||||
...taglist.map((tag) => CommandButton(tag)),
|
...taglist.map((tag) => TagButton(tag)),
|
||||||
Box({ hexpand: true }),
|
Box({ hexpand: true }),
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@@ -420,8 +439,8 @@ const booruTags = Revealer({
|
|||||||
child: Box({
|
child: Box({
|
||||||
className: 'spacing-h-5',
|
className: 'spacing-h-5',
|
||||||
children: [
|
children: [
|
||||||
CommandButton('*'),
|
TagButton('( * )'),
|
||||||
CommandButton('hololive'),
|
TagButton('hololive'),
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
@@ -433,7 +452,7 @@ const booruTags = Revealer({
|
|||||||
export const booruCommands = Box({
|
export const booruCommands = Box({
|
||||||
className: 'spacing-h-5',
|
className: 'spacing-h-5',
|
||||||
setup: (self) => {
|
setup: (self) => {
|
||||||
self.pack_end(CommandButton('/clear'), false, false, 0);
|
self.pack_end(TagButton('/clear'), false, false, 0);
|
||||||
self.pack_start(Button({
|
self.pack_start(Button({
|
||||||
className: 'sidebar-chat-chip-toggle',
|
className: 'sidebar-chat-chip-toggle',
|
||||||
setup: setupCursorHover,
|
setup: setupCursorHover,
|
||||||
@@ -455,7 +474,11 @@ const clearChat = () => { // destroy!!
|
|||||||
|
|
||||||
export const sendMessage = (text) => {
|
export const sendMessage = (text) => {
|
||||||
// Commands
|
// 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();
|
if (text.startsWith('/clear')) clearChat();
|
||||||
else if (text.startsWith('/safe')) {
|
else if (text.startsWith('/safe')) {
|
||||||
BooruService.nsfw = false;
|
BooruService.nsfw = false;
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ class BooruService extends Service {
|
|||||||
|
|
||||||
async fetch(msg) {
|
async fetch(msg) {
|
||||||
// Init
|
// 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 taglist = [];
|
||||||
let page = 1;
|
let page = 1;
|
||||||
// Construct body/headers
|
// Construct body/headers
|
||||||
for (let i = 0; i < userArgs.length; i++) {
|
for (let i = 0; i < userArgs.length; i++) {
|
||||||
const thisArg = userArgs[i].trim();
|
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 if(!isNaN(thisArg)) page = parseInt(thisArg);
|
||||||
else taglist.push(thisArg);
|
else taglist.push(thisArg);
|
||||||
}
|
}
|
||||||
@@ -95,6 +95,8 @@ class BooruService extends Service {
|
|||||||
this._queries.push({
|
this._queries.push({
|
||||||
providerName: APISERVICES[this._mode].name,
|
providerName: APISERVICES[this._mode].name,
|
||||||
taglist: taglist.length == 0 ? ['*', `${page}`] : [...taglist, `${page}`],
|
taglist: taglist.length == 0 ? ['*', `${page}`] : [...taglist, `${page}`],
|
||||||
|
realTagList: taglist,
|
||||||
|
page: page,
|
||||||
});
|
});
|
||||||
this.emit('newResponse', newMessageId);
|
this.emit('newResponse', newMessageId);
|
||||||
const params = {
|
const params = {
|
||||||
|
|||||||
Reference in New Issue
Block a user