Skip to content

Commit e28e21d

Browse files
authored
Merge pull request #81 from tjmtmmnk/parameter
set parameter by streamer
2 parents 633fab1 + 6fe9141 commit e28e21d

25 files changed

Lines changed: 695 additions & 158 deletions

.vscode/settings.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
2-
"typescript.tsdk": "./node_modules/typescript/lib",
3-
"files.eol": "\n",
4-
"json.schemas": [
5-
{
6-
"fileMatch": [
7-
"/manifest.json"
8-
],
9-
"url": "http://json.schemastore.org/chrome-manifest"
10-
}
11-
]
12-
}
2+
"typescript.tsdk": "./node_modules/typescript/lib",
3+
"files.eol": "\n",
4+
"json.schemas": [
5+
{
6+
"fileMatch": ["/manifest.json"],
7+
"url": "http://json.schemastore.org/chrome-manifest"
8+
}
9+
],
10+
"editor.formatOnSave": true,
11+
"[typescript]": {
12+
"editor.defaultFormatter": "esbenp.prettier-vscode"
13+
},
14+
}

package-lock.json

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@types/chrome": "0.0.154",
2222
"@types/jest": "27.0.1",
2323
"@types/kuromoji": "0.1.1",
24+
"@types/md5": "2.3.1",
2425
"@types/react": "17.0.19",
2526
"@types/react-dom": "17.0.9",
2627
"@types/react-router-dom": "5.1.8",
@@ -31,6 +32,7 @@
3132
"glob": "7.1.7",
3233
"jest": "27.1.0",
3334
"kuromojin": "3.0.0",
35+
"md5": "2.3.0",
3436
"path-browserify": "1.0.1",
3537
"prettier": "2.3.2",
3638
"react": "17.0.2",

public/manifest.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
}
2929
],
3030

31-
"permissions": ["activeTab", "storage"],
31+
"background": {
32+
"scripts": ["js/background.js"],
33+
"persistent": false
34+
},
35+
36+
"permissions": ["activeTab", "storage", "tabs"],
3237

3338
"web_accessible_resources": ["kuromoji/dict/*", "js/worker.js"],
3439

src/__tests__/moderate.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
hideRepeatThrow,
1212
hideRepeatWords,
1313
} from "../moderate";
14-
import { IParameter } from "../config";
14+
import { IParameterV2 } from "../config";
1515
import { KuromojiToken } from "kuromojin";
1616
import { IKuromojiWorker } from "../kuromoji";
1717

@@ -25,19 +25,19 @@ describe("moderate", () => {
2525
},
2626
};
2727

28-
const params: IParameter = {
29-
repeat_throw_threshold: 2,
30-
repeat_word_threshold: 2,
31-
post_flood_threshold: 2,
32-
length_threshold: 3,
33-
look_chats: 10,
34-
execution_interval: 1000,
35-
ng_words: ["なう"],
36-
is_show_reason: false,
37-
is_activate_modekun: true,
38-
consider_author_length: false,
39-
consider_author_ngword: false,
40-
is_hide_completely: false,
28+
const params: IParameterV2 = {
29+
repeatPostThreshold: 2,
30+
repeatWordThreshold: 2,
31+
postFrequencyThreshold: 2,
32+
lengthThreshold: 3,
33+
lookChats: 10,
34+
executionInterval: 1000,
35+
ngWords: ["なう"],
36+
isShowReason: false,
37+
isActivateModekun: true,
38+
considerAuthorLength: false,
39+
considerAuthorNgWord: false,
40+
isHideCompletely: false,
4141
};
4242
describe("hideRepeatWords", () => {
4343
const chats: IChat[] = [
@@ -156,9 +156,9 @@ describe("moderate", () => {
156156
element: document.createElement("div"),
157157
},
158158
];
159-
const param: IParameter = {
159+
const param: IParameterV2 = {
160160
...params,
161-
consider_author_ngword: true,
161+
considerAuthorNgWord: true,
162162
};
163163
hideNgWords(param, chats);
164164
expect(chats[0].element.dataset.isHiddenByModekun).toBeFalsy();
@@ -260,10 +260,10 @@ describe("moderate", () => {
260260
element: document.createElement("div"),
261261
},
262262
];
263-
const param: IParameter = {
263+
const param: IParameterV2 = {
264264
...params,
265-
length_threshold: 5,
266-
consider_author_length: true,
265+
lengthThreshold: 5,
266+
considerAuthorLength: true,
267267
};
268268
hideByLength(param, chats);
269269
expect(chats[0].element.dataset.isHiddenByModekun).toBeTruthy();
@@ -291,10 +291,10 @@ describe("moderate", () => {
291291
element: document.createElement("div"),
292292
},
293293
];
294-
const param: IParameter = {
294+
const param: IParameterV2 = {
295295
...params,
296-
repeat_throw_threshold: 2,
297-
post_flood_threshold: 3,
296+
repeatPostThreshold: 2,
297+
postFrequencyThreshold: 3,
298298
};
299299
test("can hide by both filter", () => {
300300
hideRepeatThrow(param, chats);
@@ -317,9 +317,9 @@ describe("moderate", () => {
317317
expect(chat.element.style.display).not.toBe("none");
318318
});
319319
test("can hide with display none", () => {
320-
const param: IParameter = {
320+
const param: IParameterV2 = {
321321
...params,
322-
is_hide_completely: true,
322+
isHideCompletely: true,
323323
};
324324
const chat: IChat = {
325325
key: "test1aaa",
@@ -332,9 +332,9 @@ describe("moderate", () => {
332332
expect(chat.element.style.display).toBe("none");
333333
});
334334
test("can hide associated elements with display none", () => {
335-
const param: IParameter = {
335+
const param: IParameterV2 = {
336336
...params,
337-
is_hide_completely: true,
337+
isHideCompletely: true,
338338
};
339339
const chat: IChat = {
340340
key: "test1aaa",

src/__tests__/source.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { selectSource } from "../source/source";
22
import { Youtube } from "../source/youtube";
33
import { Mildom } from "../source/mildom";
44
import { Twitch } from "../source/twitch";
5+
import { Mock } from "../source/mock";
56

67
describe("selectSource", () => {
78
test("youtube", () => {
@@ -21,6 +22,6 @@ describe("selectSource", () => {
2122

2223
test("none", () => {
2324
const source = selectSource("https://www.none.com");
24-
expect(source).toBeNull();
25+
expect(source).toEqual(Mock);
2526
});
2627
});

src/api.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defaultParamsV2, IParameterV2 } from "./config";
2+
import {
3+
NetworkNode,
4+
receiveRequest,
5+
sendRequest,
6+
sendRequestToContent,
7+
} from "./message";
8+
9+
const sleep = async (ms: number) => {
10+
return new Promise((resolve) => setTimeout(resolve, ms));
11+
};
12+
13+
export const getParam = async (from: NetworkNode): Promise<IParameterV2> => {
14+
if (from === "POPUP") {
15+
sendRequestToContent({
16+
type: "UPDATE_PARAM_KEY",
17+
from: from,
18+
to: "CONTENT_SCRIPT",
19+
});
20+
}
21+
22+
/* XXX: assure order
23+
1. update param key
24+
2. get param by using updated param key
25+
*/
26+
await sleep(500);
27+
28+
sendRequest({
29+
type: "GET_PARAM",
30+
from: from,
31+
to: "BACKGROUND",
32+
});
33+
const res = await receiveRequest("RECEIVE_PARAM");
34+
return res.data?.param ?? defaultParamsV2;
35+
};

0 commit comments

Comments
 (0)