1
0
mirror of https://github.com/journey-ad/Moe-Counter.git synced 2024-11-30 18:24:28 +01:00

feat: Improve performance

feat: Add `prefix` param
feat: Theme supports `_start` and `_end` as padding image
This commit is contained in:
roffy3051 2024-11-02 21:44:48 +08:00
parent dbf98b4735
commit 1b4e98af4a
4 changed files with 30 additions and 5 deletions

View File

@ -12,7 +12,8 @@
scale: document.getElementById('scale'), scale: document.getElementById('scale'),
pixelated: document.getElementById('pixelated'), pixelated: document.getElementById('pixelated'),
darkmode: document.getElementById('darkmode'), darkmode: document.getElementById('darkmode'),
num: document.getElementById('num') num: document.getElementById('num'),
prefix: document.getElementById('prefix')
}; };
btn.addEventListener('click', throttle(handleButtonClick, 500)); btn.addEventListener('click', throttle(handleButtonClick, 500));
@ -48,6 +49,9 @@
if (num.value > 0) { if (num.value > 0) {
params.num = num.value; params.num = num.value;
} }
if (prefix.value !== '') {
params.prefix = prefix.value;
}
const query = new URLSearchParams(params).toString(); const query = new URLSearchParams(params).toString();
const imgSrc = `${__global_data.site}/@${nameValue}?${query}`; const imgSrc = `${__global_data.site}/@${nameValue}?${query}`;

View File

@ -35,13 +35,16 @@ app.get(["/@:name", "/get/@:name"],
}), }),
query: z.object({ query: z.object({
theme: z.string().default("moebooru"), theme: z.string().default("moebooru"),
num: z.coerce.number().int().min(0).max(1e15).default(0), // a carry-safe integer, less than `2^53-1`, and aesthetically pleasing in decimal.
padding: z.coerce.number().int().min(0).max(16).default(7), padding: z.coerce.number().int().min(0).max(16).default(7),
offset: z.coerce.number().min(-500).max(500).default(0), offset: z.coerce.number().min(-500).max(500).default(0),
align: z.enum(["top", "center", "bottom"]).default("top"), align: z.enum(["top", "center", "bottom"]).default("top"),
scale: z.coerce.number().min(0.1).max(2).default(1), scale: z.coerce.number().min(0.1).max(2).default(1),
pixelated: z.enum(["0", "1"]).default("1"), pixelated: z.enum(["0", "1"]).default("1"),
darkmode: z.enum(["0", "1", "auto"]).default("auto") darkmode: z.enum(["0", "1", "auto"]).default("auto"),
// Unusual Options
num: z.coerce.number().int().min(0).max(1e15).default(0), // a carry-safe integer, less than `2^53-1`, and aesthetically pleasing in decimal.
prefix: z.coerce.number().int().min(-1).max(999999).default(-1)
}) })
}), }),
async (req, res) => { async (req, res) => {

View File

@ -42,7 +42,7 @@ function convertToDatauri(path) {
} }
function getCountImage(params) { function getCountImage(params) {
let { count, theme = 'moebooru', padding = 7, offset = 0, align = 'top', scale = 1, pixelated = '1', darkmode = 'auto' } = params let { count, theme = 'moebooru', padding = 7, prefix = -1, offset = 0, align = 'top', scale = 1, pixelated = '1', darkmode = 'auto' } = params
if (!(theme in themeList)) theme = 'moebooru' if (!(theme in themeList)) theme = 'moebooru'
padding = parseInt(Number(padding), 10) padding = parseInt(Number(padding), 10)
@ -51,6 +51,20 @@ function getCountImage(params) {
// This is not the greatest way for generating an SVG but it'll do for now // This is not the greatest way for generating an SVG but it'll do for now
const countArray = count.toString().padStart(padding, '0').split('') const countArray = count.toString().padStart(padding, '0').split('')
// Add prefix if exist
if (prefix >= 0) {
countArray.unshift(...String(prefix).split(''))
}
// Add _start and _end if exist
if (themeList[theme]['_start']) {
countArray.unshift('_start')
}
if (themeList[theme]['_end']) {
countArray.push('_end')
}
const uniqueChar = [...new Set(countArray)] const uniqueChar = [...new Set(countArray)]
let x = 0, y = 0 let x = 0, y = 0

View File

@ -92,7 +92,7 @@ html
option(value=theme) #{theme} option(value=theme) #{theme}
tr tr
td: code padding td: code padding
td Set the minimum length, between 1-32, default is td Set the minimum length, between 1-16, default is
code 7 code 7
td: input#padding(type='number', value='7', min='1', max='32', step='1', oninput='this.value = this.value.replace(/[^0-9]/g, "")') td: input#padding(type='number', value='7', min='1', max='32', step='1', oninput='this.value = this.value.replace(/[^0-9]/g, "")')
tr tr
@ -136,6 +136,10 @@ html
td Set counter display number, 0 for disable, default is td Set counter display number, 0 for disable, default is
code 0 code 0
td: input#num(type='number', value='0', min='0', max='1e15', step='1', oninput='this.value = this.value.replace(/[^0-9]/g, "")') td: input#num(type='number', value='0', min='0', max='1e15', step='1', oninput='this.value = this.value.replace(/[^0-9]/g, "")')
tr
td: code prefix
td Set the prefix number, empty for disable
td: input#prefix(type='number', value='', min='0', max='999999', step='1', oninput='this.value = this.value.replace(/[^0-9]/g, "")')
button#get(onclick='_evt_push("click", "normal", "get_counter")') Generate button#get(onclick='_evt_push("click", "normal", "get_counter")') Generate