Skip to content

Commit

Permalink
fix: use observer
Browse files Browse the repository at this point in the history
  • Loading branch information
seelx3 committed Aug 7, 2024
1 parent d3b8af1 commit 7f6618d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ OPENREC.tv上でのチャットを、画面上に表示するChrome拡張機能
yarn
yarn build
```

## ログ

- 2024/08/07 1.0.3
- コメントが表示されない不具合を修正しました
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "OPENREC.tv Chat on Screen",
"description": "OPENREC.tvのチャットを、スクリーン上に表示します。",
"version": "1.0.2",
"version": "1.0.3",
"manifest_version": 3,
"icons": {
"16": "icons/icon-16.png",
Expand Down
28 changes: 16 additions & 12 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ let context: CanvasRenderingContext2D | null;
let lines: ChatRecord[][] = [];
let fontsize: number;

// obserber
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach((node) => {
const target = node as HTMLElement;
let comment = site.getComments(target);
if (!comment) return;
core.modify();
core.attachComment(comment);
});
}
}
});

let core = {
init: () => {
// console.log(SCRIPTNAME, "init");
Expand All @@ -81,7 +96,7 @@ let core = {
context = canvas.getContext("2d");

core.addStyle();
core.listenComments();
observer.observe(board, { childList: true });
core.scrollComments();
},
addStyle: () => {
Expand Down Expand Up @@ -109,17 +124,6 @@ let core = {
"";
head.appendChild(style);
},
listenComments: () => {
// console.log(SCRIPTNAME, "listenComments");
if (!board) return;
board.addEventListener("DOMNodeInserted", (e) => {
const target = e.target as HTMLElement;
let comment = site.getComments(target);
if (!comment) return;
core.modify();
core.attachComment(comment);
});
},
modify: (flag = false) => {
// console.log(SCRIPTNAME, "modify");
if (!display || !context) return;
Expand Down

0 comments on commit 7f6618d

Please sign in to comment.