From e8b2a4cc717cf13acb25b875b04fa6ec15535e47 Mon Sep 17 00:00:00 2001 From: momochi29 <31027514+tjmtmmnk@users.noreply.github.com> Date: Fri, 9 Jul 2021 20:33:16 +0900 Subject: [PATCH] Revert "Support openrec" --- public/manifest.json | 2 +- src/config.ts | 3 +-- src/content_script.tsx | 3 +-- src/source/openrec.ts | 58 ------------------------------------------ src/source/source.ts | 10 +------- 5 files changed, 4 insertions(+), 72 deletions(-) delete mode 100644 src/source/openrec.ts diff --git a/public/manifest.json b/public/manifest.json index c3bf28a..2992d60 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -19,7 +19,7 @@ "content_scripts": [ { - "matches": ["https://www.youtube.com/*", "https://www.mildom.com/*", "https://www.twitch.tv/*", "https://www.openrec.tv/*"], + "matches": ["https://www.youtube.com/*", "https://www.mildom.com/*", "https://www.twitch.tv/*"], "js": ["js/content_script.js"] } ], diff --git a/src/config.ts b/src/config.ts index 829e2b0..c5e4f82 100644 --- a/src/config.ts +++ b/src/config.ts @@ -28,18 +28,17 @@ const DEFAULT_REPEAT_THROW_THRESHOLD = 2; const DEFAULT_REPEAT_WORD_THRESHOLD = 2; const DEFAULT_POST_FLOOD_THRESHOLD = 5; const DEFAULT_LENGTH_THRESHOLD = 200; +const DEFAULT_LOOK_CHATS = 50; const DEFAULT_NG_WORDS: string[] = []; const DEFAULT_IS_SHOW_REASON = false; const DEFAULT_IS_ACTIVATE = true; -export const DEFAULT_LOOK_CHATS = 50; export const DEFAULT_EXECUTION_INTERVAL_MS = 3000; export const OBSERVATION_INTERVAL_MS = 5000; export const YOUTUBE_REGEX = /https:\/\/www\.youtube\.com.*/; export const MILDOM_REGEX = /https:\/\/www\.mildom\.com.*/; export const TWITCH_REGEX = /https:\/\/www\.twitch\.tv.*/; -export const OPENREC_REGEX = /https:\/\/www\.openrec\.tv.*/; export const defaultParams: IParameter = { [KEY_REPEAT_THROW]: DEFAULT_REPEAT_THROW_THRESHOLD, diff --git a/src/content_script.tsx b/src/content_script.tsx index 1d020a1..5c83e41 100644 --- a/src/content_script.tsx +++ b/src/content_script.tsx @@ -6,7 +6,6 @@ import { } from "./moderate"; import { DEFAULT_EXECUTION_INTERVAL_MS, - DEFAULT_LOOK_CHATS, getParams, OBSERVATION_INTERVAL_MS, } from "./config"; @@ -17,7 +16,7 @@ import { selectSource } from "./source/source"; let worker: Worker | null; let api: IKuromojiWorker | null; -let lookChats = DEFAULT_LOOK_CHATS; +let lookChats = 0; let timerId: number; diff --git a/src/source/openrec.ts b/src/source/openrec.ts deleted file mode 100644 index c00c8ba..0000000 --- a/src/source/openrec.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { ISource } from "./source"; -import { IChat } from "../chat"; -import { kanaToHiragana, removeSymbols } from "../util"; - -const chatSelector = { - section: ".page-wrapper", -}; - -const chatRegex = { - chatBlock: /ChatCell__Box-.*/, - message: /ChatCell__InlineMessage-.*/, - author: /UserName__Wrapper-.*/, -}; - -// each class name has random value which may be changed by release. -export const Openrec: ISource = { - extractChats(lookNum: number): IChat[] { - const section = document.querySelector(chatSelector.section); - if (!section) return []; - - const blocks = section.querySelectorAll("*"); - const chatBlocks: HTMLElement[] = []; - for (const block of blocks) { - if (chatRegex.chatBlock.test(block.className)) { - chatBlocks.push(block); - } - } - const chats: IChat[] = []; - for (const chatBlock of chatBlocks) { - const elements = chatBlock.querySelectorAll("*"); - let author, message; - for (const element of elements) { - if (chatRegex.author.test(element.className)) { - author = element.innerText; - } - if (chatRegex.message.test(element.className)) { - message = element.innerText; - } - if (author && message) break; - } - - if (!author || !message) continue; - - if (chats.length < lookNum) { - const key = removeSymbols(kanaToHiragana(author + message)); - chats.push({ - key: key, - author: author, - message: message, - element: chatBlock, - }); - } else { - break; - } - } - return chats; - }, -}; diff --git a/src/source/source.ts b/src/source/source.ts index bd21e84..a76a267 100644 --- a/src/source/source.ts +++ b/src/source/source.ts @@ -1,14 +1,8 @@ import { IChat } from "../chat"; -import { - MILDOM_REGEX, - OPENREC_REGEX, - TWITCH_REGEX, - YOUTUBE_REGEX, -} from "../config"; +import { MILDOM_REGEX, TWITCH_REGEX, YOUTUBE_REGEX } from "../config"; import { Youtube } from "./youtube"; import { Mildom } from "./mildom"; import { Twitch } from "./twitch"; -import { Openrec } from "./openrec"; export interface ISource { extractChats: (lookNum: number) => IChat[]; @@ -21,8 +15,6 @@ export const selectSource = (url: string): ISource | null => { return Mildom; } else if (TWITCH_REGEX.test(url)) { return Twitch; - } else if (OPENREC_REGEX.test(url)) { - return Openrec; } return null; };