Skip to content

Commit

Permalink
在线词库完成
Browse files Browse the repository at this point in the history
  • Loading branch information
OToNaShiAKi committed Mar 17, 2023
1 parent 2983ee8 commit 459d09b
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 155 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "material-douden-tool",
"version": "1.2.0",
"version": "1.2.1",
"private": true,
"author": "濯墨",
"scripts": {
Expand Down
35 changes: 21 additions & 14 deletions src/ipc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, Baidu, Bilibili, Login } from "./plugins/headers";
import { API, Baidu, Bilibili, Login, MusicQQ } from "./plugins/headers";
import CreateWindow, { AllWindows } from "./background";
import { ipcMain, BrowserWindow, dialog, screen } from "electron";
import {
Expand All @@ -14,8 +14,7 @@ import {
SetUserRoomMode,
CheckLogin,
GetWebSocket,
SearchMusic163,
SearchMusicQQ,
SearchMusic,
SilentUser,
GetAuthen,
Translate,
Expand All @@ -24,6 +23,9 @@ import {
RemoveSilentUser,
GetUserRoomInfo,
GetDynamic,
LoginStatistics,
PubShield,
SubShield,
} from "./plugins/axios";
import { Stacks } from "./util/Stacks";
import { e, TranslateResult } from "./util/Translate";
Expand All @@ -33,6 +35,7 @@ import { Replies } from "./util/Replies";
import FontList from "font-list";
import MD5 from "blueimp-md5";
import OS from "os";
import Package from "../package.json";

const options = {
alwaysOnTop: false,
Expand Down Expand Up @@ -94,7 +97,7 @@ ipcMain.handle("BilibiliLogin", async () => {
return url;
});

ipcMain.handle("Cookie", async (event, cookie, csrf) => {
ipcMain.handle("Cookie", async (event, cookie, csrf, use = true) => {
Bilibili.defaults.headers.Cookie = cookie;
Login.defaults.headers.Cookie = cookie;
Bilibili.defaults.data = {
Expand All @@ -103,10 +106,14 @@ ipcMain.handle("Cookie", async (event, cookie, csrf) => {
rnd: Math.floor(Date.now() / 1000),
};
const result = await CheckLogin();
const equipment = `${OS.platform().toUpperCase()}:${OS.hostname()}`;
const crypto = MD5(`${result.mid}.${equipment}.${csrf}`);
API.defaults.headers.Cookie = `mid=${result.mid}; equipment=${equipment}; crypto=${crypto}`;
return result.avatar;
if (result.mid) {
const hostname = `${OS.platform().toUpperCase()}:${OS.hostname()}`;
const crypto = MD5(`${result.mid}.${hostname}.${csrf}`);
API.defaults.headers.Cookie = `mid=${result.mid}; hostname=${hostname}; crypto=${crypto};`;
await LoginStatistics(result.name, result.avatar, csrf, Package.version);
result.shields = await SubShield(use);
}
return result;
});

ipcMain.handle("SearchLive", async (event, keyword) => {
Expand Down Expand Up @@ -158,11 +165,7 @@ ipcMain.on("ChangeMedal", (event, model_id) =>

ipcMain.handle("GetMusic", async (event, keyword) => {
const match = /\[(\d{1,2}):([0-9.]{1,8})\](.*)\n?/g;
const [music163, musicQQ] = await Promise.all([
SearchMusic163(keyword),
SearchMusicQQ(keyword),
]);
const result = [...music163, ...musicQQ];
const result = await SearchMusic(keyword);
for (const item of result) {
if (item.lyric && match.test(item.lyric)) {
const lyric = [];
Expand Down Expand Up @@ -282,4 +285,8 @@ ipcMain.handle("GetDynamic", async (event, ids) => {
ipcMain.handle("GetFont", async (event) => {
const result = await FontList.getFonts();
return result.map((item) => item.replace(/^"|"$/g, ""));
});
});

ipcMain.on("PubShield", PubShield);

ipcMain.handle("SubShield", (event, use = true) => SubShield(use));
55 changes: 36 additions & 19 deletions src/pages/index/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from "vue";
import Vuex from "vuex";
import { ipcRenderer } from "electron";
import Socket from "../../plugins/socket";

Vue.use(Vuex);

Expand All @@ -16,14 +17,43 @@ const shields = JSON.parse(localStorage.getItem("shields")) || [];
const stamps = [];
stamps[-1] = { lyric: "", tlyric: "" };

const Handler = {
rooms: (config) =>
config.map((item) => ({
value: item.value,
text: item.text,
uid: item.uid,
avatar: item.avatar,
})),
shields: (config, mid) =>
config.filter((item) => !item.mid || item.mid == mid),
};

const ChangeConfig = (state, { key, config = [] }) => {
state[key] = [...config];
const mid = state.cookie.match(/DedeUserID=([^;]+);/);
config = Handler[key] ? Handler[key](config, mid && mid[1]) : config;
localStorage.setItem(key, JSON.stringify(config));
};

const ChangeCookie = async (state, cookie) => {
localStorage.setItem("cookie", cookie || "");
state.cookie = cookie || "";
if (cookie) {
const bili_jct = cookie.match(/bili_jct=([^;]+);/);
if (bili_jct) {
state.avatar = await ipcRenderer.invoke("Cookie", cookie, bili_jct[1]);
cookie = cookie || "";
localStorage.setItem("cookie", cookie);
state.cookie = cookie;
const bili_jct = cookie.match(/bili_jct=([^;]+);/);
if (bili_jct) {
const result = await ipcRenderer.invoke(
"Cookie",
cookie,
bili_jct[1],
Socket.UseShareShields
);
for (const v of state.shields) {
const find = result.shields.find((item) => item.shield === v.shield);
if (!find) result.shields.push(v);
}
ChangeConfig(state, { key: "shields", config: result.shields });
state.avatar = result.avatar;
}
};

Expand All @@ -37,19 +67,6 @@ const ChangeSelect = (state, select = []) => {
state.select = select.filter((v) => v);
};

const ChangeConfig = (state, { key, config = [] }) => {
state[key] = [...config];
if (key === "rooms") {
config = config.map((item) => ({
value: item.value,
text: item.text,
uid: item.uid,
avatar: item.avatar,
}));
}
localStorage.setItem(key, JSON.stringify(config));
};

const ChangeShortcuts = (state, { key, value }) => {
const shortcuts = state.shortcuts;
if (value) shortcuts[key] = value;
Expand Down
1 change: 1 addition & 0 deletions src/pages/index/views/Cookie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default {
this.cookie = result.query;
this.ChangeCookie(this.cookie);
this.Notify("登陆成功");
this.$router.push("/room")
} else if (result.data === -2) {
this.code = "";
}
Expand Down
22 changes: 18 additions & 4 deletions src/pages/index/views/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/>
</v-radio-group>
<v-divider vertical class="my-3" />
<v-item-group multiple @change="ChangeConfig" :value="config">
<v-item-group multiple @change="ChangeSetting" :value="config">
<v-item
v-for="v of auto"
:key="v.key"
Expand All @@ -42,13 +42,15 @@
import Socket from "../../../plugins/socket";
import Pack from "../../../components/Pack.vue";
import { ipcRenderer } from "electron";
import { mapMutations } from "vuex";
const Keys = [
const Keys = Object.freeze([
"AutoClickRedPocket",
"AutoCopyForbidWord",
"AutoChangeMedal",
"AutoTranslate",
];
"UseShareShields",
]);
export default {
name: "Setting",
Expand All @@ -70,22 +72,34 @@ export default {
{ key: "AutoCopyForbidWord", text: "自动复制屏蔽弹幕" },
{ key: "AutoChangeMedal", text: "自动换牌子" },
{ key: "AutoTranslate", text: "自动翻译非中文弹幕" },
{ key: "UseShareShields", text: "使用共享屏蔽词库" },
],
config: Keys.filter((v) => Socket[v]),
}),
methods: {
...mapMutations(["ChangeConfig"]),
ChangeColor(value) {
this.$vuetify.theme.themes.light.primary = value;
this.$vuetify.theme.themes.dark.primary = value;
ipcRenderer.send("Channel", "WindowStyle", value);
localStorage.setItem("primary", value);
},
ChangeConfig(config) {
async ChangeSetting(config) {
for (const key of Keys) {
const value = config.includes(key);
Socket[key] = value;
localStorage.setItem(key, value);
}
const result = await ipcRenderer.invoke(
"SubShield",
config.includes(Keys[4])
);
const shields = JSON.parse(localStorage.getItem("shields")) || [];
for (const v of shields) {
const find = result.find((item) => item.shield === v.shield);
if (!find) result.push(v);
}
this.ChangeConfig({ key: "shields", config: result });
},
},
};
Expand Down
18 changes: 16 additions & 2 deletions src/pages/index/views/Shield.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<Pack>屏蔽词</Pack>
<DataTable :items="shields" :headers="headers">
<template v-slot="{ item }">
<v-icon small @click="Remove" :data-key="item.shield">
<v-icon
v-if="!item.mid || item.mid == mid"
small
@click="Remove"
:data-key="item.shield"
>
mdi-delete
</v-icon>
</template>
Expand Down Expand Up @@ -39,6 +44,7 @@
import Pack from "../../../components/Pack.vue";
import DataTable from "../../../components/DataTable.vue";
import { mapMutations, mapState } from "vuex";
import { ipcRenderer } from "electron";
export default {
name: "Shield",
Expand All @@ -52,7 +58,13 @@ export default {
shield: "",
handle: "",
}),
computed: { ...mapState(["shields"]) },
computed: {
...mapState(["shields"]),
mid: ({ $store: { state } }) => {
const mid = state.cookie.match(/DedeUserID=([^;]+);/);
return mid && mid[1];
},
},
methods: {
...mapMutations(["ChangeConfig"]),
Add() {
Expand All @@ -65,6 +77,7 @@ export default {
} else {
find.handle = this.handle;
}
ipcRenderer.send("PubShield", this.shield, this.handle, true);
this.shield = "";
this.handle = "";
this.ChangeConfig({ key: "shields", config: this.shields });
Expand All @@ -73,6 +86,7 @@ export default {
const shields = this.shields.filter(
(item) => item.shield !== dataset.key
);
ipcRenderer.send("PubShield", dataset.key, "", false);
this.ChangeConfig({ key: "shields", config: shields });
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/pages/support/views/Video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ export default {
src.replace(/^data:image\/(png|gif|jpeg);base64,/, "")
);
ipcRenderer.send("SaveFiles", datas, Date.now().toString(), "base64");
this.images = [];
localStorage.setItem("screenshot", JSON.stringify([]));
},
Remove({ target: { dataset } }) {
const { key } = dataset;
Expand Down
Loading

0 comments on commit 459d09b

Please sign in to comment.