Skip to content

Commit

Permalink
解决五个阿姬倒地,添加类型注释
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave-12138 committed Oct 15, 2024
1 parent ae10acd commit 7288c45
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miyoushe-emot-to-github",
"version": "0.3.4",
"version": "0.3.5",
"type": "module",
"description": "在github使用米游社表情包",
"private": true,
Expand Down
23 changes: 14 additions & 9 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ useEventListener(document, "focusin", e => {
// 解决前进后退时浏览器还原 dom 却不还原 vue app 数据状态的问题——我把旧 dom 杀了不就好了?
document.querySelectorAll(".miyoushe-emots").forEach(e => { if (!e.isSameNode(_this.value)) e.remove(); });
});
function onInputEmot(src, name) {
/**
* @typedef {{id: number,src: string,name: string}} EmotImg
* @typedef {{[x: number]: EmotImg[]}} EmotTabs
*/
/**
*
* @param {EmotImg} param0
*/
function onInputEmot({ src, name }) {
inputEmot(currentInput.value, `<img src="${src}" alt="${name}" width="75" >`);
}
const tabs = computed(() => emotList.value?.map(t => ({ group: t.id, name: t.name, src: t.icon })) ?? [])
const currentTab = ref(tabs.value[0]?.group ?? "0");
const tabData = computed(() => emotList.value
.map(g => {
return {
[g.id]: g.list.map(im => ({ id: im.id, src: im.icon, name: im.name }))
}
}).reduce((pv, v) => Object.assign(pv, v), {})
);
/**
* @type {import('vue').ComputedRef<EmotTabs>}
*/
const tabData = computed(() => emotList.value.reduce((pv, g) => Object.assign(pv, { [g.id]: g.list.filter(v => v.is_available).map(im => ({ id: im.id, src: im.icon, name: im.name })) }), {}));
</script>
<template>
<Teleport :to="currentInput?.parentElement" :disabled="!currentInput || !currentInput.parentElement">
Expand All @@ -42,7 +47,7 @@ const tabData = computed(() => emotList.value
</div>
<div class="emot-icons">
<div>
<Lazy v-for="em in tabData[currentTab]" :key="em.name" :src="em.src" @click="onInputEmot(em.src, em.name)">
<Lazy v-for="em in tabData[currentTab]" :key="em.name" :src="em.src" @click="onInputEmot(em)">
<div>{{ em.name }}</div>
</Lazy>
</div>
Expand Down
36 changes: 36 additions & 0 deletions src/stronge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
import { ref } from "vue";
import { GM_registerMenuCommand, GM_getValue, GM_setValue } from '$';
import { GM_fetch } from "./tool";
/**
* @typedef {Object} Emot
* @prop {number} id
* @prop {string} name
* @prop {string} icon
* @prop {number} sort_order
* @prop {string} static_icon
* @prop {number} updated_at
* @prop {boolean} is_available
* @prop {string} status
* @prop {string[]} keywords
*/
/**
* @typedef {Object} EmotCate
* @prop {number} id
* @prop {string} name
* @prop {string} icon
* @prop {number} sort_order
* @prop {number} num
* @prop {string} status
* @prop {Emot[]} list
* @prop {number} updated_at
* @prop {boolean} is_available
*/
/**
* @type {import('vue').Ref<EmotCate[]>}
*/
const emotList = ref();
const now = 0 | (Date.now() / 1000);
const emotKey = 'miyoushe-emoticon';
Expand All @@ -16,6 +43,15 @@ function confirmList() {
confirmList();

function readList() {
/**
* @typedef {Object} ApiResp
* @prop {number} retcode
* @prop {string} message
* @prop {{list:EmotCate[]}} data
*/
/**
* @type {ApiResp}
*/
const resp = JSON.parse(GM_getValue(emotKey, null));
if (!resp) {
return fetchList();
Expand Down

0 comments on commit 7288c45

Please sign in to comment.