├── .gitignore
├── LICENSE
├── README.md
├── files
└── setting.html
├── icons
├── 128.png
├── 16.png
└── 48.png
├── index.js
├── lib
├── LICENSE
├── body-pix.js
├── load.svg
├── logo.png
├── logo2.png
├── logo3.png
├── logo4.png
├── niconicomments.js
├── tf.js
└── wave.png
└── manifest.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
26 | build
27 | comment-zouryou.code-workspace
28 | test/*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 tanbatu.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | コメント増量は、ニコニコ動画のコメント数を増量、及び全コメ表示がブラウザ上で出来る拡張機能です。
4 |
5 | ## プレビュー
6 | 
7 |
8 | 
9 | ## インストール
10 | 1.[リリースページより](https://github.com/tanbatu/comment-zouryou/releases)Source code (zip)をダウンロード、 展開する。
11 |
12 | 2.Chromeで「chrome://extensions」にアクセスする。
13 |
14 | 3.右上のデベロッパーモードをオンにして, 「パッケージ化されていない拡張機能を読み込む」を選択し、 1.でダウンロードしたフォルダを選択する。
15 |
16 | ## 使い方
17 | [note記事を御覧ください。](https://note.com/tanbatu/n/n3837f4137cd9)
18 |
19 | ## 注意
20 | 大量のコメントを処理する為、コンピューターのスペックによってはフリーズする恐れがあります。
21 |
22 | ## スペシャルサンクス
23 | XPAさんのコメント描画ライブラリ「niconicomments」を使用させて頂きました。
24 | https://github.com/xpadev-net/niconicomments
25 |
--------------------------------------------------------------------------------
/files/setting.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Document
7 |
8 |
9 |
10 |
418 |
696 |
697 |
698 |
699 |
700 |
703 |
704 |
705 |
706 |
--------------------------------------------------------------------------------
/icons/128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanbatu/comment-zouryou/ea3ed44f9da59fa3cc16a0a5ac5ec9b06d37aafe/icons/128.png
--------------------------------------------------------------------------------
/icons/16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanbatu/comment-zouryou/ea3ed44f9da59fa3cc16a0a5ac5ec9b06d37aafe/icons/16.png
--------------------------------------------------------------------------------
/icons/48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanbatu/comment-zouryou/ea3ed44f9da59fa3cc16a0a5ac5ec9b06d37aafe/icons/48.png
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | let CommentRenderer,
2 | zouryouCanvasElement,
3 | SuperDanmakuCanvasElement,
4 | videoElement,
5 | pipVideoElement,
6 | VideoSymbolContainer,
7 | CommentLoadingScreen,
8 | CustomVideoContainer,
9 | DefaultVideoContainer,
10 | PlayerContainer,
11 | CommentLoadingScreenWrapper,
12 | loading,
13 | loading_text,
14 | link,
15 | OLD_DATE,
16 | OLD_TIME,
17 | DRAW_,
18 | net,
19 | firstaccess,
20 | aspect,
21 | apiData;
22 | let COMMENT = [];
23 | let CommentLimit = 40;
24 |
25 | async function LOADCOMMENT(mode) {
26 | const commentRenderers = document.getElementsByClassName("CommentRenderer");
27 | if (commentRenderers.length === 0) {
28 | PlayerContainer = document.querySelector('[data-name="content"]');
29 | const CustomVideoContainer = document.createElement("div");
30 | CustomVideoContainer.classList.add("CustomVideoContainer", "InView");
31 | CustomVideoContainer.style.cssText =
32 | "display: none; z-index: 1; pointer-events: none;";
33 | CustomVideoContainer.innerHTML = ``;
38 | PlayerContainer.children[0].after(CustomVideoContainer);
39 | }
40 |
41 | logger("お待ち下さい");
42 | loading.style.display = "block";
43 | document.getElementsByClassName("loadbutton_text")[0].innerText =
44 | "読み込み中";
45 | let LoadedCommentCount = 1,
46 | FailCount = 0;
47 | const parser = new DOMParser();
48 |
49 | let match = location.href.match(/\/watch\/(sm\d+)/);
50 | if (match === null) {
51 | match = location.href.match(/\/watch\/(so\d+)/);
52 | }
53 |
54 | const req = await fetch(
55 | "https://www.nicovideo.jp/watch/" + match[1] + "?responseType=json"
56 | );
57 | apiData = (await req.json()).data.response;
58 |
59 | const joinObj = function (obj, fDelimiter, sDelimiter) {
60 | const tmpArr = [];
61 | if (typeof obj === "undefined") return "";
62 | if (typeof fDelimiter === "undefined") fDelimiter = "";
63 | if (typeof sDelimiter === "undefined") sDelimiter = "";
64 | for (let key in obj) {
65 | tmpArr.push(key + fDelimiter + obj[key]);
66 | }
67 | return tmpArr.join(sDelimiter);
68 | };
69 | //コメント取得
70 | const nvComment = apiData.comment.nvComment,
71 | threads = apiData.comment.threads;
72 | let totalThreadCount = nvComment.params.targets.length * CommentLimit;
73 | let fetchedThreadCount = 0;
74 | logger(
75 | `${nvComment.params.targets.length}スレッドをそれぞれ${CommentLimit}回読み込みます。`
76 | );
77 |
78 | const date =
79 | OLD_DATE.value === ""
80 | ? new Date()
81 | : new Date(OLD_DATE.value + " " + OLD_TIME.value);
82 | const ownerComments = [];
83 | const comments = [];
84 | let isLoggedIn = true,
85 | params = {
86 | version: "20090904",
87 | scores: "1",
88 | nicoru: "3",
89 | fork: 0,
90 | language: "0",
91 | thread: threads[2]["id"],
92 | };
93 | const prepareLegacy = async () => {
94 | let channel_URL =
95 | "https://flapi.nicovideo.jp/api/getthreadkey?thread=" + threads[2]["id"];
96 | const req = await fetch(channel_URL);
97 | const res = (await req.text()).split("&");
98 | if (res[0] !== "") {
99 | for (const item of res) {
100 | const param = item.split("=");
101 | params[param[0]] = param[1];
102 | }
103 | }
104 | };
105 | let threadKey = nvComment.threadKey;
106 | for (const i in nvComment.params.targets) {
107 | const thread = nvComment.params.targets[i];
108 | if (
109 | (document.getElementById("iseasy").checked || mode == "auto") &&
110 | thread.fork == "easy"
111 | ) {
112 | continue;
113 | }
114 | let baseData = {
115 | threadKey: threadKey,
116 | params: {
117 | language: nvComment.params.language,
118 | targets: [thread],
119 | },
120 | };
121 | let lastTime = Math.floor(date.getTime() / 1000);
122 | for (let j = 0; j < CommentLimit; j++) {
123 | //await sleep(1000);
124 | if (isLoggedIn) {
125 | const req = await fetch(`${nvComment.server}/v1/threads`, {
126 | method: "POST",
127 | headers: {
128 | "content-type": "text/plain;charset=UTF-8",
129 | "x-client-os-type": "others",
130 | "x-frontend-id": "6",
131 | "x-frontend-version": "0",
132 | },
133 | body: JSON.stringify({
134 | ...baseData,
135 | additionals: {
136 | res_from: -1000,
137 | when: lastTime,
138 | },
139 | }),
140 | });
141 | const res = await req.json();
142 | if (res?.meta?.errorCode === "TOO_MANY_REQUESTS") {
143 | for (let i = 0; i < 60; i++) {
144 | logger(
145 | `[${
146 | fetchedThreadCount + j
147 | }/${totalThreadCount}]: API呼び出しの回数制限を超えました。しばらくお待ち下さい。\n
148 | あと${60 - i}秒`
149 | );
150 | await sleep(1000);
151 | }
152 | j--;
153 | continue;
154 | }
155 | if (res?.meta?.errorCode === "EXPIRED_TOKEN") {
156 | logger(
157 | `[${
158 | fetchedThreadCount + j
159 | }/${totalThreadCount}]:threadKeyを新たに取得しています…`
160 | );
161 | await fetch(
162 | "https://nvapi.nicovideo.jp/v1/comment/keys/thread?videoId=" +
163 | apiData.video.id,
164 | {
165 | headers: {
166 | "X-Frontend-Id": "6",
167 | "X-Frontend-Version": "0",
168 | "Content-Type": "application/json",
169 | },
170 | credentials: "include",
171 | }
172 | )
173 | .then((r) => r.json())
174 | .then((j) => {
175 | console.log(j.data.threadKey);
176 | threadKey = j.data.threadKey;
177 | baseData.threadKey = j.data.threadKey;
178 | });
179 | j--;
180 | continue;
181 | }
182 | if (res?.meta?.errorCode === "INVALID_TOKEN") {
183 | logger("ログインしていません。");
184 | alert(
185 | "【コメント増量】ログアウト状態です。ログインをして再度実行してください。"
186 | );
187 | document.getElementById("loading").style.display = "none";
188 | document.getElementById("allcommentsetting").style.display = "none";
189 | isLoggedIn = false;
190 | j--;
191 | totalThreadCount /= 3;
192 | //await prepareLegacy();
193 | //continue;
194 | }
195 | (thread.fork === "owner" ? ownerComments : comments).push(
196 | ...res.data.threads[0].comments
197 | );
198 | if (
199 | res.data.threads[0].comments.length === 0 ||
200 | res.data.threads[0].comments[0].no < 5
201 | ) {
202 | logger(
203 | `[${
204 | fetchedThreadCount + j
205 | }/${totalThreadCount}]: スレッドの先頭まで読み込みました`
206 | );
207 | break;
208 | }
209 | lastTime = Math.floor(
210 | new Date(res.data.threads[0].comments[0].postedAt).getTime() / 1000
211 | );
212 | logger(
213 | `[${fetchedThreadCount + j}/${totalThreadCount}]: コメ番${
214 | res.data.threads[0].comments[0].no
215 | }まで読み込みました`
216 | );
217 | } else {
218 | let url = `${threads[1]["server"]}/api.json/thread?${joinObj(
219 | { ...params, when: lastTime, res_from: "-1000" },
220 | "=",
221 | "&"
222 | )}`;
223 | logger(
224 | `[${LoadedCommentCount}/${CommentLimit}]: ${url}を読み込んでいます...`,
225 | false
226 | );
227 | const req = await fetch(url);
228 | const res = await req.text();
229 | let comments_tmp;
230 | try {
231 | comments_tmp = JSON.parse(res).slice(2);
232 | lastTime = comments_tmp[0].chat.date;
233 | } catch (e) {
234 | lastTime -= 100;
235 | FailCount++;
236 | if (FailCount > 10) {
237 | logger(`コメントの取得に失敗しました`);
238 | break;
239 | }
240 | logger(
241 | `[${LoadedCommentCount}/${CommentLimit}]: コメントの参照に失敗しました。お待ち下さい。`
242 | );
243 | j--;
244 | await sleep(1000);
245 | continue;
246 | }
247 | for (const comment of comments_tmp) {
248 | //
249 | (!!comment.user_id ? comments : ownerComments).push({
250 | body: comment.chat.content,
251 | commands: comment.chat.mail?.split(/\s+/g),
252 | id: 0,
253 | isMyPost: false,
254 | isPremium: comment.chat.premium === 1,
255 | nicoruCount: 0,
256 | nicoruId: null,
257 | no: comment.chat.no,
258 | postedAt: `${comment.chat.date}`,
259 | score: 0,
260 | source: "",
261 | userId: comment.chat.user_id,
262 | vposMs: comment.chat.vpos * 10,
263 | });
264 | }
265 | if (comments_tmp.length === 0 || comments_tmp[0].chat.no < 5) {
266 | logger(
267 | `[${
268 | fetchedThreadCount + j
269 | }/${totalThreadCount}]: スレッドの先頭まで読み込みました`
270 | );
271 | break;
272 | }
273 | lastTime = comments_tmp[0].chat.date;
274 | logger(
275 | `[${fetchedThreadCount + j}/${totalThreadCount}]: コメ番${
276 | comments_tmp[0].chat.no
277 | }まで読み込みました`
278 | );
279 | }
280 | document.getElementById("progress_left").style.width =
281 | 100 -
282 | ((fetchedThreadCount + j) / totalThreadCount) * 100 +
283 | "%"; /*.background = `linear-gradient(90deg,rgb(0, 145, 255,0.9) 0%,#0ff ${
284 | ((fetchedThreadCount + j) / totalThreadCount) * 100
285 | }%,rgba(0, 0, 0, .9) ${
286 | ((fetchedThreadCount + j) / totalThreadCount) * 100
287 | }%,rgba(0, 0, 0, .9) 100%)`;*/
288 | let LimitRate = 20;
289 | if (NG_LIST_COMMAND.includes("speedmode")) {
290 | LimitRate = 1000;
291 | }
292 | if (CommentLimit > LimitRate) {
293 | await sleep(1000);
294 | }
295 | }
296 | if (!isLoggedIn) break;
297 | fetchedThreadCount += CommentLimit;
298 | }
299 | CommentLoadingScreenWrapper.style.background = `rgba(0, 0, 0, .9)`;
300 | logger(comments.length + "件のコメントを読み込みました");
301 | logger(`NG設定を適用しています`);
302 |
303 | COMMENT = [
304 | {
305 | commentCount: comments.length,
306 | comments: await COMMENT_CONTROL(comments),
307 | fork: "comment-zouryou",
308 | id: 0,
309 | },
310 | {
311 | commentCount: ownerComments.length,
312 | comments: ownerComments, //投稿者コメントにフィルターを適用する?
313 | fork: "owner",
314 | id: 1,
315 | },
316 | ];
317 | document.getElementById("reload_niconicomments").onclick = async () => {
318 | COMMENT = [
319 | {
320 | commentCount: comments.length,
321 | comments: await COMMENT_CONTROL(comments),
322 | fork: "comment-zouryou",
323 | id: 0,
324 | },
325 | {
326 | commentCount: ownerComments.length,
327 | comments: ownerComments, //投稿者コメントにフィルターを適用する?
328 | fork: "owner",
329 | id: 1,
330 | },
331 | ];
332 | load_NiconiComments();
333 | clearInterval(list_interval);
334 | LIST_COMMENT();
335 | };
336 |
337 | logger(`描画準備中`);
338 | document.getElementById("progress_left").style.width = "0%";
339 | PLAYCOMMENT();
340 | }
341 |
342 | let niconiComments, comment_list_active;
343 | let observer = new MutationObserver(function () {
344 | if (href.split("?")[0] !== location.href.split("?")[0]) {
345 | document.getElementById("loaded").style.zIndex = "0";
346 | document.getElementById("wrapper_buttons").style.height = "0px";
347 | document.getElementById("wrapper_buttons").style.opacity = "0";
348 | document.getElementsByClassName("scroll")[0].style.height =
349 | "calc(100% - 171px)";
350 | DRAW_ = false;
351 | document.getElementsByClassName("CommentRenderer")[0].style.display =
352 | "block";
353 | CustomVideoContainer.style.display = "none";
354 | //DefaultVideoContainer.style.display = "block";
355 | LoadedCommentCount = 1;
356 | link.style.visibility = "hidden";
357 | //CommentLoadingScreen.innerHTML = "";
358 | document.getElementById("loaded").style.visibility = "hidden";
359 | document.getElementById("zenkomebutton").disabled = false;
360 | pipVideoElement.style.display = "none";
361 | document.getElementById("reload_niconicomments").disabled = true;
362 | document.getElementsByClassName("loadbutton_text")[0].innerText =
363 | "読み込み開始!";
364 | document.getElementById("progress_left").style.width = "100%";
365 | href = location.href;
366 | COMMENT = [];
367 |
368 | setTimeout(() => {
369 | if (document.getElementById("isauto").checked == true) {
370 | document.getElementById("allcommentsetting").style.display = "block";
371 | CommentLimit = document.getElementById("auto_num").value;
372 | //CommentLimit = CommentLimit > 5 ? 5 : CommentLimit;
373 | LOADCOMMENT("auto");
374 | document.getElementById("zenkomebutton").disabled = true;
375 | }
376 | }, 1000);
377 | }
378 | });
379 | let href = location.href;
380 | function escapeHtml(text) {
381 | var map = {
382 | "&": "&",
383 | "<": "<",
384 | ">": ">",
385 | '"': """,
386 | "'": "'",
387 | };
388 |
389 | return text.replace(/[&<>"']/g, function (m) {
390 | return map[m];
391 | });
392 | }
393 | function getXMLString(json) {
394 | var parser = new DOMParser();
395 | var xml = '';
396 | xml += `
397 |
398 | `;
399 | for (const comments of json[0].comments) {
400 | xml += `${escapeHtml(comments.body)}
409 | `;
410 | }
411 | xml += "";
412 | var xmlDoc = parser.parseFromString(xml, "application/xml");
413 | return xml;
414 | }
415 | let download_comment;
416 | let blob;
417 | observer.observe(document, { childList: true, subtree: true });
418 |
419 | function load_NiconiComments() {
420 | console.log(COMMENT);
421 | niconiComments = new NiconiComments(zouryouCanvasElement, COMMENT, {
422 | video: document.getElementById("iscanvas").checked
423 | ? videoElement
424 | : undefined,
425 | enableLegacyPiP: true,
426 | scale: document.getElementById("bar_textsize").value * 0.01,
427 | keepCA: document.getElementById("checkbox4").checked,
428 | showCommentCount: document.getElementById("isdebug").checked,
429 | showFPS: document.getElementById("isdebug").checked,
430 | config: (Config = {
431 | contextStrokeOpacity: Number(document.getElementById("bar_stroke").value),
432 | contextLineWidth: 3.5,
433 | }),
434 | format: "v1",
435 | });
436 | }
437 | function ADDCOMMENT(val, pos, mail) {
438 | niconiComments.addComments({
439 | vpos: pos,
440 | content: val,
441 | owner: false,
442 | premium: true,
443 | mail: ["184", "nico:waku:#fff321"].concat(mail),
444 | layer: -1,
445 | });
446 | }
447 | function PLAYCOMMENT() {
448 | document.getElementsByClassName("CustomVideoContainer")[0].style.display =
449 | "block";
450 | const commentRenderers = document.getElementsByClassName("CommentRenderer");
451 | if (commentRenderers.length === 0) {
452 | PlayerContainer = document.querySelector('[data-name="content"]');
453 | PlayerContainer.children[0].after(CustomVideoContainer);
454 | }
455 |
456 | zouryouCanvasElement = document.getElementById("zouryou_comment");
457 |
458 | let draw;
459 | console.log(COMMENT);
460 | async function setup() {
461 | //DefaultVideoContainer.style.display = "block";
462 |
463 | if (document.getElementById("isxml").checked) {
464 | download_comment = getXMLString(COMMENT);
465 | link.download = apiData.video.id + ".xml";
466 | document.getElementsByClassName("loadbutton_text")[0].innerText =
467 | "XMLをダウンロード";
468 | } else {
469 | download_comment = [JSON.stringify(COMMENT)];
470 | link.download = apiData.video.id + ".json";
471 | document.getElementsByClassName("loadbutton_text")[0].innerText =
472 | "JSONをダウンロード";
473 | }
474 |
475 | blob = new Blob([download_comment], { type: "text/plain" });
476 |
477 | link.style.visibility = "visible";
478 | link.href = URL.createObjectURL(blob);
479 |
480 | videoElement = document.querySelector('[data-name="video-content"]');
481 | aspect = Number(videoElement.videoWidth) / Number(videoElement.videoHeight);
482 | console.log(aspect);
483 |
484 | zouryouCanvasElement.style.opacity =
485 | document.getElementById("bar_alpha").value * 0.01;
486 |
487 | load_NiconiComments();
488 | document.getElementById("reload_niconicomments").disabled = false;
489 |
490 | loading.style.display = "none";
491 | CustomVideoContainer.style.display = "block";
492 | console.log(niconiComments);
493 |
494 | DRAW_ = true;
495 | function draw() {
496 | niconiComments.drawCanvas(Math.floor(videoElement.currentTime * 100));
497 | if (DRAW_ == false) return;
498 |
499 | setTimeout(draw, 1000 / document.getElementById("bar_fps").value);
500 | }
501 | draw();
502 |
503 | console.log(videoElement);
504 | document.querySelector('[data-name="comment"]').style.display = "none";
505 | //document.getElementsByClassName("CommentRenderer")[0].style.display =
506 | // "none";
507 | //
508 | pipVideoElement.srcObject = zouryouCanvasElement.captureStream(60);
509 | pipVideoElement.muted = true;
510 | pipVideoElement.play();
511 |
512 | //void DANMAKU_SUPER();
513 | setTimeout(() => {
514 | document.getElementById("wrapper_buttons").style.height = "30px";
515 | document.getElementById("wrapper_buttons").style.opacity = "1";
516 | document.getElementsByClassName("scroll")[0].style.height =
517 | "calc(100% - 221px)";
518 | }, 200);
519 | }
520 | document.getElementById("loaded").style.zIndex = "2";
521 | const comment_list = document.getElementById("comment_list");
522 | document
523 | .getElementById("comment_list_open")
524 | .addEventListener("click", function () {
525 | comment_list.style.visibility = "visible";
526 | comment_list_active = true;
527 | });
528 | document
529 | .getElementById("comment_list_exit")
530 | .addEventListener("click", function () {
531 | comment_list.style.visibility = "hidden";
532 | comment_list_active = false;
533 | });
534 | LIST_COMMENT();
535 | let Comment_Show_Button = document.querySelector(
536 | "[aria-label='コメントを非表示にする']"
537 | );
538 | if (Comment_Show_Button == undefined) {
539 | Comment_Show_Button = document.querySelector(
540 | "[aria-label='コメントを表示する']"
541 | );
542 | }
543 | let Comment_SH = new MutationObserver(function () {
544 | console.log(Comment_Show_Button.getAttribute("data-state"));
545 | CustomVideoContainer.style.zIndex =
546 | Comment_Show_Button.getAttribute("aria-label") == "コメントを表示する"
547 | ? 0
548 | : 1;
549 | });
550 | Comment_SH.observe(Comment_Show_Button, { childList: true, subtree: true });
551 | pipVideoElement.style.display = document.getElementById("iscanvas").checked
552 | ? "block"
553 | : "none";
554 | zouryouCanvasElement.style.display = document.getElementById("iscanvas")
555 | .checked
556 | ? "none"
557 | : "block";
558 |
559 | //document
560 | // .getElementsByClassName("ActionButton CommentPostButton")[0]
561 | // .addEventListener("click", () => {
562 | // ADDCOMMENT(
563 | // document.querySelector(".CommentInput > textarea").value,
564 | // Math.floor(videoElement.currentTime * 100),
565 | // document
566 | // .getElementsByClassName("CommentCommandInput")[0]
567 | // .value.split(" ")
568 | // );
569 | // });
570 | //
571 | //document
572 | // .querySelector(".CommentInput > textarea")
573 | // .addEventListener("keydown", (e) => {
574 | // if (
575 | // e.keyCode === 13 &&
576 | // document.querySelector(".CommentInput > textarea").value != ""
577 | // ) {
578 | // ADDCOMMENT(
579 | // document.querySelector(".CommentInput > textarea").value,
580 | // Math.floor(videoElement.currentTime * 100),
581 | // document
582 | // .getElementsByClassName("CommentCommandInput")[0]
583 | // .value.split(" ")
584 | // );
585 | // }
586 | // });
587 | setTimeout(setup, 1000);
588 | }
589 | let lastCurrentTime = -1;
590 | /*
591 | async function DANMAKU_SUPER() {
592 | videoElement.setAttribute("width", 360 * aspect);
593 | videoElement.setAttribute("height", 360);
594 | let ismask = document.getElementById("ismask");
595 | let ctx = SuperDanmakuCanvasElement.getContext("2d");
596 | function mask(Imagedata) {
597 | zouryouCanvasElement.style.setProperty(
598 | "-webkit-mask-image",
599 | `url(${Imagedata})`
600 | );
601 | zouryouCanvasElement.style.setProperty(
602 | "-webkit-mask-size",
603 | `${videoElement.clientWidth}px ${videoElement.clientHeight}px `
604 | );
605 | zouryouCanvasElement.style.setProperty(
606 | "-webkit-mask-position-x",
607 | `${
608 | (videoElement.clientWidth - videoElement.clientHeight * aspect) / 2
609 | }px `
610 | );
611 | }
612 | function segmentPerson(img) {
613 | const option = {
614 | flipHorizontal: false,
615 | internalResolution: "high",
616 | segmentationThreshold: Number(
617 | document.getElementById("bar_segment").value
618 | ),
619 | maxDetections: 5,
620 | scoreThreshold: 0.3,
621 | nmsRadius: 20,
622 | minKeypointScore: 0.6,
623 | refineSteps: 10,
624 | };
625 |
626 | return net.segmentPerson(img, option);
627 | }
628 |
629 | async function drawCanvas() {
630 | if (!net || videoElement.currentTime === lastCurrentTime) return;
631 | lastCurrentTime = videoElement.currentTime;
632 | ctx.fillStyle = "rgb(0, 0, 0)";
633 | ctx.fillRect(360 * aspect, 0, 640 - 360 * aspect, 360);
634 | const segmentation = await segmentPerson(videoElement);
635 | const colorMask = bodyPix.toMask(segmentation, false);
636 | ctx.putImageData(colorMask, 0, 0);
637 |
638 | data = SuperDanmakuCanvasElement.toDataURL("image/png");
639 | mask(data);
640 | }
641 | if (net) return BodynetPix;
642 | net = await bodyPix.load();
643 | setInterval(() => {
644 | if (ismask.checked) {
645 | drawCanvas();
646 | }
647 | }, 100);
648 | }*/
649 | let list_interval;
650 | function LIST_COMMENT() {
651 | COMMENT[0].comments.sort(function (a, b) {
652 | if (a.vposMs < b.vposMs) return -1;
653 | if (a.vposMs > b.vposMs) return 1;
654 | return 0;
655 | });
656 |
657 | let now_comment_pos = document.getElementById("now_comment_pos");
658 | list_interval = setInterval(() => {
659 | if (videoElement.currentTime === lastCurrentTime) return;
660 | lastCurrentTime = videoElement.currentTime;
661 | if (!comment_list_active) return;
662 |
663 | let passIndex = COMMENT[0].comments.findIndex(function (element) {
664 | return element.vposMs > Math.floor(videoElement.currentTime * 1000);
665 | });
666 | now_comment_pos.innerText = `現在のコメント位置${passIndex}/${COMMENT[0].comments.length}`;
667 | document.getElementById("comment_list_comments").innerHTML = "";
668 | for (let i = 0; i < 30; i++) {
669 | let body = COMMENT[0].comments[passIndex - i]?.body;
670 | let nicoru = COMMENT[0].comments[passIndex - i]?.nicoruCount || "";
671 | if (body == undefined) body = "";
672 | let commentElement = document.createElement("div");
673 | commentElement.className = "list_comment";
674 | if (body != "") {
675 | commentElement.innerHTML = ``;
678 | document
679 | .getElementById("comment_list_comments")
680 | .prepend(commentElement);
681 | }
682 | }
683 | }, 50);
684 | }
685 |
686 | const logger = (msg, load) => {
687 | const p = document.createElement("p");
688 | p.innerText = msg;
689 | if (load != false) {
690 | loading_text.innerText = msg;
691 | }
692 |
693 | console.log(msg);
694 | CommentLoadingScreen.appendChild(p);
695 | CommentLoadingScreenWrapper.scrollBy(0, CommentLoadingScreen.clientHeight);
696 | };
697 |
698 | const sleep = (time) => {
699 | return new Promise((resolve) => {
700 | setTimeout(() => {
701 | resolve();
702 | }, time);
703 | });
704 | };
705 |
706 | let NG_LIST_COMMAND = [];
707 | let NG_LIST_COMMENT = [];
708 | const COMMENT_CONTROL = (comments) => {
709 | return new Promise((resolve) => {
710 | let ng_score = document.getElementById("ng_score").value;
711 | let nicoru_limit = document.getElementById("nicoru_num");
712 | let premium_filter = document.getElementById("premium_filter");
713 |
714 | console.log(ng_score);
715 | for (const i in comments) {
716 | const comment = comments[i];
717 | if (comment.commands === undefined) {
718 | comment.commands = [];
719 | } else {
720 | comment.commands = comment.commands.map((value) => value.toLowerCase());
721 | }
722 | }
723 | NG_LIST_COMMAND.forEach((NG) => {
724 | let commands = NG.toLowerCase().split(" ");
725 | comments = comments.filter((comment) => {
726 | let ng_point = commands.length;
727 | commands.forEach((command) => {
728 | if (comment.commands.includes(command)) {
729 | ng_point -= 1;
730 | }
731 | });
732 | return ng_point > 0;
733 | });
734 | });
735 | NG_LIST_COMMENT.forEach(
736 | (NG) =>
737 | (comments = comments.filter(
738 | (comment) => comment.body.includes(NG) === false
739 | ))
740 | );
741 | comments = comments.filter((comment) => comment.score >= ng_score);
742 | comments = comments.filter(
743 | (comment) => comment.nicoruCount >= nicoru_limit.value
744 | );
745 | if (premium_filter.checked) {
746 | comments = comments.filter((comment) => comment.isPremium === true);
747 | }
748 |
749 | logger(comments.length + "件に減りました");
750 | resolve(comments);
751 | });
752 | };
753 |
754 | function PREPARE(observe) {
755 | document
756 | .getElementsByClassName("grid-area_[sidebar]")[0]
757 | .insertAdjacentHTML("afterbegin", setting_html);
758 | let customStyle = document.createElement("style");
759 | customStyle.innerHTML =
760 | ".CustomVideoContainer{width: 100%;height:100%;position: absolute;top: 0;left: 0;}body.is-large:not(.is-fullscreen) .CustomVideoContainer {width: 854px;height: 480px;}body.is-fullscreen .CustomVideoContainer {width: 100vw !important;height: 100vh !important;}@media screen and (min-width: 1286px) and (min-height: 590px){body.is-autoResize:not(.is-fullscreen) .CustomVideoContainer {width: 854px;height: 480px;}@media screen and (min-width: 1392px) and (min-height: 650px){body.is-autoResize:not(.is-fullscreen) .CustomVideoContainer {width: 960px;height: 540px;}} @media screen and (min-width: 1736px) and (min-height: 850px) {body.is-autoResize:not(.is-fullscreen) .CustomVideoContainer {width: 1280px;height: 720px;}}}";
761 | document.body.appendChild(customStyle);
762 | CommentRenderer = document.getElementsByClassName("CommentRenderer")[0];
763 | VideoSymbolContainer = document.getElementsByClassName(
764 | "VideoSymbolContainer"
765 | )[0];
766 | PlayerContainer = document.querySelector('[data-name="content"]');
767 | //DefaultVideoContainer = document.getElementsByClassName(
768 | // "InView VideoContainer"
769 | //)[0];
770 | CustomVideoContainer = document.createElement("div");
771 | CustomVideoContainer.innerHTML = ``;
772 | CustomVideoContainer.classList.add("CustomVideoContainer", "InView");
773 | for (let i = 0; i < 2; i++) {
774 | document.getElementsByClassName("wave")[
775 | i
776 | ].style = `background:url(${wave_image});
777 | background-size: 1000px 50px;`;
778 | }
779 | document.getElementById("logo").src = logo_image;
780 | document.getElementById("loading_image").src = load_image;
781 |
782 | document
783 | .querySelector('[data-name="video-content"]')
784 | .after(CustomVideoContainer);
785 | zouryouCanvasElement = document.getElementById("zouryou_comment");
786 | SuperDanmakuCanvasElement = document.getElementById(
787 | "SuperDanmakuCanvasElement"
788 | );
789 | videoElement = document.querySelector('[data-name="video-content"]');
790 | //let seekBar = document.getElementsByClassName("SeekBar")[0];
791 | //if (seekBar.classList.contains("is-disabled")) {
792 | // seekBar.classList.remove("is-disabled");
793 | //}
794 |
795 | SuperDanmakuCanvasElement.width = 640;
796 | SuperDanmakuCanvasElement.height = 360;
797 |
798 | console.log(videoElement);
799 | pipVideoElement = document.getElementById("pipVideoElement");
800 | CommentLoadingScreenWrapper = document.createElement("div");
801 | CommentLoadingScreenWrapper.id = "CommentLoadingScreenWrapper";
802 | CommentLoadingScreenWrapper.innerHTML =
803 | '';
804 | document
805 | .getElementsByClassName("CustomVideoContainer InView")[0]
806 | .appendChild(CommentLoadingScreenWrapper);
807 |
808 | CommentLoadingScreen = document.getElementById("CommentLoadingScreen");
809 | link = document.getElementById("loaded");
810 | CustomVideoContainer.style.display = "none";
811 | CustomVideoContainer.style.zIndex = "1";
812 | CustomVideoContainer.style.pointerEvents = "none";
813 | zouryouCanvasElement.style = `position:absolute;top:0;left:0;width:100%;height:100%;z-index:0;display:block;object-fit:contain;`;
814 | SuperDanmakuCanvasElement.style =
815 | "position:absolute;top:0;left:0;width:100%;height:100%;z-index:1;display:block;opacity:0;";
816 | pipVideoElement.style =
817 | "position:absolute;top:0;left:0;width:100%;height:100%;z-index:1;pointer-events:all;display:none";
818 | pipVideoElement.onpause = () => {
819 | pipVideoElement.play();
820 | };
821 |
822 | OLD_DATE = document.getElementById("zenkome-date");
823 | OLD_TIME = document.getElementById("zenkome-time");
824 | const setting = document.getElementById("allcommentsetting");
825 |
826 | document.getElementsByClassName("ZenkomeCloseButton")[0].addEventListener(
827 | "click",
828 | () => {
829 | setting.style.display = "none";
830 | },
831 | false
832 | );
833 | OLD_DATE.min = "2007-03-03";
834 | OLD_DATE.max = new Date().getFullYear() + "-12-31";
835 | const val_stroke = document.getElementsByClassName("range_val");
836 | const bar_stroke = document.getElementsByClassName("range_bar");
837 | let get_zouryou_config = localStorage.getItem("zouryou_config");
838 | let zouryou_config;
839 | let comment_num,
840 | comment_size,
841 | stroke_opacity,
842 | comment_opacity,
843 | fps,
844 | pip,
845 | keepCA,
846 | auto,
847 | xml,
848 | ngscore,
849 | nicoru_limit,
850 | premium_filter,
851 | version;
852 | function CONFIG() {
853 | get_zouryou_config = localStorage.getItem("zouryou_config");
854 | if (get_zouryou_config == null || get_zouryou_config == "[null]") {
855 | localStorage.setItem(
856 | "zouryou_config",
857 | JSON.stringify({
858 | num: 5,
859 | bar_textsize: 100,
860 | bar_stroke: 0.35,
861 | bar_alpha: 100,
862 | bar_fps: 30,
863 | keepCA: false,
864 | mode: "html5",
865 | pip: false,
866 | auto: false,
867 | auto_num: 2,
868 | xml: false,
869 | ngscore: "-Infinity",
870 | nicoru_limit: 0,
871 | premium_filter: false,
872 | version: "7.3.3",
873 | })
874 | );
875 | } else {
876 | zouryou_config = JSON.parse(get_zouryou_config);
877 | comment_num = document.getElementById("load_num");
878 | comment_size = document.getElementById("bar_textsize");
879 | stroke_opacity = document.getElementById("bar_stroke");
880 | comment_opacity = document.getElementById("bar_alpha");
881 | fps = document.getElementById("bar_fps");
882 | pip = document.getElementById("iscanvas");
883 | keepCA = document.getElementById("checkbox4");
884 | auto = document.getElementById("isauto");
885 | auto_num = document.getElementById("auto_num");
886 | xml = document.getElementById("isxml");
887 | ngscore = document.getElementById("ng_score");
888 | nicoru_limit = document.getElementById("nicoru_num");
889 | premium_filter = document.getElementById("premium_filter");
890 | comment_num.value = zouryou_config.num;
891 | comment_size.value = zouryou_config.bar_textsize;
892 | stroke_opacity.value = zouryou_config.bar_stroke;
893 | comment_opacity.value = zouryou_config.bar_alpha;
894 | pip.checked = zouryou_config.pip;
895 | keepCA.checked = zouryou_config.keepCA;
896 | auto.checked = zouryou_config.auto;
897 | fps.value = zouryou_config.bar_fps;
898 | auto_num.value = zouryou_config.auto_num;
899 | xml.checked = zouryou_config.xml;
900 | nicoru_limit.value = zouryou_config.nicoru_limit || 0;
901 | premium_filter.checked = zouryou_config.premium_filter || false;
902 | ngscore.value = zouryou_config.ngscore || "-Infinity";
903 | for (let i = 0; i < val_stroke.length; i++) {
904 | val_stroke[i].innerText = bar_stroke[i].value;
905 | }
906 | }
907 | let l = document.getElementById("load_num");
908 | if (l.value.length >= 4) {
909 | l.style.width = "60%";
910 | } else {
911 | l.style.width = "50%";
912 | }
913 | }
914 |
915 | let ng_storage = localStorage.getItem("ng_storage");
916 | let ngarray,
917 | SETTING_NG_LIST_COMMENT,
918 | SETTING_NG_LIST_COMMAND,
919 | SETTING_NG_LIST_ISEASY;
920 |
921 | function NG_DELETE(type, i) {
922 | ngarray[type].splice(i, 1);
923 | localStorage.setItem("ng_storage", JSON.stringify(ngarray));
924 | setTimeout(() => {
925 | ng_element();
926 | }, 100);
927 | }
928 |
929 | function ng_element() {
930 | ng_storage = localStorage.getItem("ng_storage");
931 | NG_LIST_COMMAND = [];
932 | NG_LIST_COMMENT = [];
933 | SETTING_NG_LIST_ISEASY = document.getElementById("iseasy");
934 | SETTING_NG_LIST_COMMENT = document.getElementById("ng_comment");
935 | SETTING_NG_LIST_COMMAND = document.getElementById("ng_command");
936 | loading_text = document.getElementById("loading_text");
937 | loading = document.getElementById("loading");
938 | SETTING_NG_LIST_COMMAND.innerHTML = "";
939 | SETTING_NG_LIST_COMMENT.innerHTML = "";
940 |
941 | if (ng_storage == null || ng_storage == "[null]") {
942 | localStorage.setItem(
943 | "ng_storage",
944 | JSON.stringify({ command: [], comment: [], easy: false })
945 | );
946 | } else {
947 | ngarray = JSON.parse(ng_storage);
948 | ngarray.command.forEach((command) => NG_LIST_COMMAND.push(command));
949 | ngarray.comment.forEach((comment) => NG_LIST_COMMENT.push(comment));
950 |
951 | SETTING_NG_LIST_COMMENT.innerHTML = "";
952 | SETTING_NG_LIST_COMMAND.innerHTML = "";
953 | for (let i = 0; i < NG_LIST_COMMENT.length; i++) {
954 | SETTING_NG_LIST_COMMENT.innerHTML += `${NG_LIST_COMMENT[i]}
955 | `;
956 | }
957 | for (let i = 0; i < NG_LIST_COMMENT.length; i++) {
958 | document.getElementById(`del_e${i}`).onclick = function (e) {
959 | NG_DELETE("comment", i);
960 | };
961 | }
962 | for (let i = 0; i < NG_LIST_COMMAND.length; i++) {
963 | SETTING_NG_LIST_COMMAND.innerHTML += `${NG_LIST_COMMAND[i]}
964 | `;
965 | }
966 | for (let i = 0; i < NG_LIST_COMMAND.length; i++) {
967 | document.getElementById(`del_a${i}`).onclick = function (e) {
968 | NG_DELETE("command", i);
969 | };
970 | }
971 | SETTING_NG_LIST_ISEASY.checked = ngarray.easy;
972 | }
973 | }
974 |
975 | if (!observe) {
976 | ng_element();
977 | CONFIG();
978 | }
979 | document.getElementById("form_command").onclick = () => {
980 | ng_storage = localStorage.getItem("ng_storage");
981 | ngarray = JSON.parse(ng_storage);
982 | let ng_add = window.prompt("新たに追加するNGコマンドを入力してください。");
983 | ngarray.command.push(ng_add);
984 | localStorage.setItem("ng_storage", JSON.stringify(ngarray));
985 |
986 | setTimeout(() => {
987 | ng_element();
988 | }, 100);
989 | };
990 | document.getElementById("form_comment").onclick = () => {
991 | ng_storage = localStorage.getItem("ng_storage");
992 | ngarray = JSON.parse(ng_storage);
993 | let ng_add = window.prompt("新たに追加するNGコメントを入力してください。");
994 | ngarray.comment.push(ng_add);
995 | localStorage.setItem("ng_storage", JSON.stringify(ngarray));
996 |
997 | setTimeout(() => {
998 | ng_element();
999 | }, 100);
1000 | };
1001 | document.getElementById("iseasy").onclick = () => {
1002 | ng_storage = localStorage.getItem("ng_storage");
1003 | ngarray = JSON.parse(ng_storage);
1004 | ngarray.easy = !ngarray.easy;
1005 | localStorage.setItem("ng_storage", JSON.stringify(ngarray));
1006 | setTimeout(() => {
1007 | ng_element();
1008 | }, 100);
1009 | };
1010 | document.getElementById("load_num").oninput = () => {
1011 | let l = document.getElementById("load_num");
1012 | if (l.value.length >= 4) {
1013 | l.style.width = "60%";
1014 | } else {
1015 | l.style.width = "50%";
1016 | }
1017 |
1018 | get_zouryou_config = localStorage.getItem("zouryou_config");
1019 | zouryou_config = JSON.parse(get_zouryou_config);
1020 | zouryou_config.num = document.getElementById("load_num").value;
1021 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1022 | };
1023 | document.getElementById("checkbox4").onclick = () => {
1024 | get_zouryou_config = localStorage.getItem("zouryou_config");
1025 | zouryou_config = JSON.parse(get_zouryou_config);
1026 | zouryou_config.keepCA = !zouryou_config.keepCA;
1027 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1028 | };
1029 | document.getElementById("iscanvas").onclick = () => {
1030 | get_zouryou_config = localStorage.getItem("zouryou_config");
1031 | zouryou_config = JSON.parse(get_zouryou_config);
1032 | zouryou_config.pip = !zouryou_config.pip;
1033 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1034 | };
1035 | document.getElementById("isauto").onclick = () => {
1036 | get_zouryou_config = localStorage.getItem("zouryou_config");
1037 | zouryou_config = JSON.parse(get_zouryou_config);
1038 | zouryou_config.auto = !zouryou_config.auto;
1039 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1040 | };
1041 | document.getElementById("isxml").onclick = () => {
1042 | get_zouryou_config = localStorage.getItem("zouryou_config");
1043 | zouryou_config = JSON.parse(get_zouryou_config);
1044 | zouryou_config.xml = !zouryou_config.xml;
1045 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1046 | };
1047 | document.getElementById("auto_num").oninput = () => {
1048 | get_zouryou_config = localStorage.getItem("zouryou_config");
1049 | zouryou_config = JSON.parse(get_zouryou_config);
1050 | zouryou_config.auto_num = document.getElementById("auto_num").value;
1051 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1052 | };
1053 | document.getElementById("nicoru_num").oninput = () => {
1054 | get_zouryou_config = localStorage.getItem("zouryou_config");
1055 | zouryou_config = JSON.parse(get_zouryou_config);
1056 | zouryou_config.nicoru_limit = document.getElementById("nicoru_num").value;
1057 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1058 | };
1059 | document.getElementById("ng_score").onchange = () => {
1060 | get_zouryou_config = localStorage.getItem("zouryou_config");
1061 | zouryou_config = JSON.parse(get_zouryou_config);
1062 | zouryou_config.ngscore = document.getElementById("ng_score").value;
1063 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1064 | };
1065 | document.getElementById("premium_filter").onclick = () => {
1066 | get_zouryou_config = localStorage.getItem("zouryou_config");
1067 | zouryou_config = JSON.parse(get_zouryou_config);
1068 | zouryou_config.premium_filter = !zouryou_config.premium_filter;
1069 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1070 | };
1071 |
1072 | for (let i = 0; i < val_stroke.length; i++) {
1073 | bar_stroke[i].addEventListener(
1074 | "input",
1075 | function (e) {
1076 | val_stroke[i].innerText = e.target.value;
1077 | if (this.id == "bar_alpha") {
1078 | zouryouCanvasElement.style.opacity = e.target.value * 0.01;
1079 | }
1080 | get_zouryou_config = localStorage.getItem("zouryou_config");
1081 | zouryou_config = JSON.parse(get_zouryou_config);
1082 | zouryou_config[bar_stroke[i].id] = e.target.value;
1083 | localStorage.setItem("zouryou_config", JSON.stringify(zouryou_config));
1084 | },
1085 | false
1086 | );
1087 | }
1088 |
1089 | document.getElementById("islogger").addEventListener("change", function () {
1090 | CommentLoadingScreenWrapper.style.display = this.checked ? "block" : "none";
1091 | });
1092 | document.getElementById("isxml").addEventListener("change", function () {
1093 | if (document.getElementById("isxml").checked) {
1094 | download_comment = getXMLString(COMMENT);
1095 | link.download = apiData.video.id + ".xml";
1096 | document.getElementsByClassName("loadbutton_text")[0].innerText =
1097 | "XMLをダウンロード";
1098 | } else {
1099 | download_comment = [JSON.stringify(COMMENT)];
1100 | link.download = apiData.video.id + ".json";
1101 | document.getElementsByClassName("loadbutton_text")[0].innerText =
1102 | "JSONをダウンロード";
1103 | }
1104 |
1105 | blob = new Blob([download_comment], { type: "text/plain" });
1106 | link.style.visibility = "visible";
1107 | link.href = URL.createObjectURL(blob);
1108 | });
1109 | document.getElementById("ismask").addEventListener("change", function () {
1110 | if (!this.checked) {
1111 | setTimeout(() => {
1112 | zouryouCanvasElement.style.setProperty("-webkit-mask-image", ``);
1113 | }, 100);
1114 | }
1115 | });
1116 |
1117 | document.getElementById("iscanvas").addEventListener("change", function () {
1118 | niconiComments.video = this.checked ? videoElement : null;
1119 | pipVideoElement.style.display = this.checked ? "block" : "none";
1120 | zouryouCanvasElement.style.display = this.checked ? "none" : "block";
1121 | });
1122 |
1123 | document.getElementById("isdebug").addEventListener("change", function () {
1124 | niconiComments.showCommentCount =
1125 | document.getElementById("isdebug").checked;
1126 | });
1127 | if (document.getElementById("isauto").checked == true) {
1128 | setting.style.display = "block";
1129 | CommentLimit = document.getElementById("auto_num").value;
1130 | CommentLimit = CommentLimit > 5 ? 5 : CommentLimit;
1131 | LOADCOMMENT("auto");
1132 | document.getElementById("zenkomebutton").disabled = true;
1133 | }
1134 | document.getElementById("zenkomebutton").onclick = () => {
1135 | let num = document.getElementById("load_num").value;
1136 | CommentLimit = num !== "" ? Number(num) : 5;
1137 | document.getElementById("zenkomebutton").disabled = true;
1138 |
1139 | LOADCOMMENT();
1140 | };
1141 |
1142 | ////
1143 | let fullScreenButton = document.querySelector(
1144 | "[aria-label='全画面表示する']"
1145 | );
1146 | if (fullScreenButton == undefined) {
1147 | fullScreenButton = document.querySelector(
1148 | "[aria-label='全画面表示を終了']"
1149 | );
1150 | }
1151 | let fullScreen = new MutationObserver(function () {
1152 | console.log(fullScreenButton.getAttribute("data-state"));
1153 | document.getElementById("allcommentsetting").style.visibility =
1154 | fullScreenButton.getAttribute("aria-label") == "全画面表示する"
1155 | ? "visible"
1156 | : "hidden";
1157 | });
1158 | fullScreen.observe(fullScreenButton, { childList: true, subtree: true });
1159 |
1160 | setTimeout(function () {
1161 | function ShowButton() {
1162 | console.log(1);
1163 | if (document.getElementById("AllCommentViewButton") != undefined) return;
1164 | let settingButton = document.querySelector("[aria-label='設定']");
1165 | if (settingButton != undefined) {
1166 | document.querySelector("[aria-label='設定']").insertAdjacentHTML(
1167 | "beforebegin",
1168 | `
1169 |
1172 | `
1173 | );
1174 | document.getElementById("AllCommentViewButton").addEventListener(
1175 | "click",
1176 | () => {
1177 | setting.style.display = "block";
1178 | },
1179 | false
1180 | );
1181 | }
1182 | }
1183 |
1184 | ShowButton();
1185 | }, 1000);
1186 | }
1187 |
1188 | let index_html = chrome.runtime.getURL("files/setting.html");
1189 | let wave_image = chrome.runtime.getURL("lib/wave.png");
1190 | let logo_image = chrome.runtime.getURL("lib/logo4.png");
1191 | let load_image = chrome.runtime.getURL("lib/load.svg");
1192 | let setting_html;
1193 | fetch(index_html)
1194 | .then((r) => r.text())
1195 | .then((html) => {
1196 | setting_html = html;
1197 | });
1198 | const start = setInterval(() => {
1199 | if (document.getElementsByClassName("d_flex gap_base")[5] != undefined) {
1200 | PREPARE();
1201 | clearInterval(start);
1202 | }
1203 | }, 50);
1204 | console.log("✨コメント増量 v7.4\nCopyright (c) 2022 tanbatu.");
1205 |
--------------------------------------------------------------------------------
/lib/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 xpadev-net
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/lib/body-pix.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @license
3 | * Copyright 2020 Google LLC. All Rights Reserved.
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | * =============================================================================
16 | */
17 | !(function (t, e) {
18 | "object" == typeof exports && "undefined" != typeof module
19 | ? e(
20 | exports,
21 | require("@tensorflow/tfjs-core"),
22 | require("@tensorflow/tfjs-converter")
23 | )
24 | : "function" == typeof define && define.amd
25 | ? define(
26 | ["exports", "@tensorflow/tfjs-core", "@tensorflow/tfjs-converter"],
27 | e
28 | )
29 | : e((t.bodyPix = {}), t.tf, t.tf);
30 | })(this, function (t, e, n) {
31 | "use strict";
32 | var r = function (t, e) {
33 | return (r =
34 | Object.setPrototypeOf ||
35 | ({ __proto__: [] } instanceof Array &&
36 | function (t, e) {
37 | t.__proto__ = e;
38 | }) ||
39 | function (t, e) {
40 | for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]);
41 | })(t, e);
42 | };
43 | function o(t, e) {
44 | function n() {
45 | this.constructor = t;
46 | }
47 | r(t, e),
48 | (t.prototype =
49 | null === e ? Object.create(e) : ((n.prototype = e.prototype), new n()));
50 | }
51 | var i = function () {
52 | return (i =
53 | Object.assign ||
54 | function (t) {
55 | for (var e, n = 1, r = arguments.length; n < r; n++)
56 | for (var o in (e = arguments[n]))
57 | Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
58 | return t;
59 | }).apply(this, arguments);
60 | };
61 | function a(t, e, n, r) {
62 | return new (n || (n = Promise))(function (o, i) {
63 | function a(t) {
64 | try {
65 | u(r.next(t));
66 | } catch (t) {
67 | i(t);
68 | }
69 | }
70 | function s(t) {
71 | try {
72 | u(r.throw(t));
73 | } catch (t) {
74 | i(t);
75 | }
76 | }
77 | function u(t) {
78 | t.done
79 | ? o(t.value)
80 | : new n(function (e) {
81 | e(t.value);
82 | }).then(a, s);
83 | }
84 | u((r = r.apply(t, e || [])).next());
85 | });
86 | }
87 | function s(t, e) {
88 | var n,
89 | r,
90 | o,
91 | i,
92 | a = {
93 | label: 0,
94 | sent: function () {
95 | if (1 & o[0]) throw o[1];
96 | return o[1];
97 | },
98 | trys: [],
99 | ops: [],
100 | };
101 | return (
102 | (i = { next: s(0), throw: s(1), return: s(2) }),
103 | "function" == typeof Symbol &&
104 | (i[Symbol.iterator] = function () {
105 | return this;
106 | }),
107 | i
108 | );
109 | function s(i) {
110 | return function (s) {
111 | return (function (i) {
112 | if (n) throw new TypeError("Generator is already executing.");
113 | for (; a; )
114 | try {
115 | if (
116 | ((n = 1),
117 | r &&
118 | (o =
119 | 2 & i[0]
120 | ? r.return
121 | : i[0]
122 | ? r.throw || ((o = r.return) && o.call(r), 0)
123 | : r.next) &&
124 | !(o = o.call(r, i[1])).done)
125 | )
126 | return o;
127 | switch (((r = 0), o && (i = [2 & i[0], o.value]), i[0])) {
128 | case 0:
129 | case 1:
130 | o = i;
131 | break;
132 | case 4:
133 | return a.label++, { value: i[1], done: !1 };
134 | case 5:
135 | a.label++, (r = i[1]), (i = [0]);
136 | continue;
137 | case 7:
138 | (i = a.ops.pop()), a.trys.pop();
139 | continue;
140 | default:
141 | if (
142 | !(o = (o = a.trys).length > 0 && o[o.length - 1]) &&
143 | (6 === i[0] || 2 === i[0])
144 | ) {
145 | a = 0;
146 | continue;
147 | }
148 | if (3 === i[0] && (!o || (i[1] > o[0] && i[1] < o[3]))) {
149 | a.label = i[1];
150 | break;
151 | }
152 | if (6 === i[0] && a.label < o[1]) {
153 | (a.label = o[1]), (o = i);
154 | break;
155 | }
156 | if (o && a.label < o[2]) {
157 | (a.label = o[2]), a.ops.push(i);
158 | break;
159 | }
160 | o[2] && a.ops.pop(), a.trys.pop();
161 | continue;
162 | }
163 | i = e.call(t, a);
164 | } catch (t) {
165 | (i = [6, t]), (r = 0);
166 | } finally {
167 | n = o = 0;
168 | }
169 | if (5 & i[0]) throw i[1];
170 | return { value: i[0] ? i[1] : void 0, done: !0 };
171 | })([i, s]);
172 | };
173 | }
174 | }
175 | function u(t) {
176 | var n = t.shape[2],
177 | r = t.argMax(2).reshape([-1]);
178 | return e.oneHot(r, n);
179 | }
180 | function d(t, n) {
181 | return e.tidy(function () {
182 | return t.greater(e.scalar(n)).toInt();
183 | });
184 | }
185 | var f = (function () {
186 | function t(t, n) {
187 | (this.model = t), (this.outputStride = n);
188 | var r = this.model.inputs[0].shape;
189 | e.util.assert(-1 === r[1] && -1 === r[2], function () {
190 | return (
191 | "Input shape [" +
192 | r[1] +
193 | ", " +
194 | r[2] +
195 | "] must both be equal to or -1"
196 | );
197 | });
198 | }
199 | return (
200 | (t.prototype.predict = function (t) {
201 | var n = this;
202 | return e.tidy(function () {
203 | var e = n.preprocessInput(t.toFloat()).expandDims(0),
204 | r = n.model.predict(e).map(function (t) {
205 | return t.squeeze([0]);
206 | }),
207 | o = n.nameOutputResults(r);
208 | return {
209 | heatmapScores: o.heatmap.sigmoid(),
210 | offsets: o.offsets,
211 | displacementFwd: o.displacementFwd,
212 | displacementBwd: o.displacementBwd,
213 | segmentation: o.segmentation,
214 | partHeatmaps: o.partHeatmaps,
215 | longOffsets: o.longOffsets,
216 | partOffsets: o.partOffsets,
217 | };
218 | });
219 | }),
220 | (t.prototype.dispose = function () {
221 | this.model.dispose();
222 | }),
223 | t
224 | );
225 | })(),
226 | l = (function (t) {
227 | function n() {
228 | return (null !== t && t.apply(this, arguments)) || this;
229 | }
230 | return (
231 | o(n, t),
232 | (n.prototype.preprocessInput = function (t) {
233 | return e.tidy(function () {
234 | return e.div(t, 127.5).sub(1);
235 | });
236 | }),
237 | (n.prototype.nameOutputResults = function (t) {
238 | return {
239 | offsets: t[0],
240 | segmentation: t[1],
241 | partHeatmaps: t[2],
242 | longOffsets: t[3],
243 | heatmap: t[4],
244 | displacementFwd: t[5],
245 | displacementBwd: t[6],
246 | partOffsets: t[7],
247 | };
248 | }),
249 | n
250 | );
251 | })(f),
252 | c = [
253 | "nose",
254 | "leftEye",
255 | "rightEye",
256 | "leftEar",
257 | "rightEar",
258 | "leftShoulder",
259 | "rightShoulder",
260 | "leftElbow",
261 | "rightElbow",
262 | "leftWrist",
263 | "rightWrist",
264 | "leftHip",
265 | "rightHip",
266 | "leftKnee",
267 | "rightKnee",
268 | "leftAnkle",
269 | "rightAnkle",
270 | ],
271 | h = c.length,
272 | p = c.reduce(function (t, e, n) {
273 | return (t[e] = n), t;
274 | }, {});
275 | [
276 | ["leftHip", "leftShoulder"],
277 | ["leftElbow", "leftShoulder"],
278 | ["leftElbow", "leftWrist"],
279 | ["leftHip", "leftKnee"],
280 | ["leftKnee", "leftAnkle"],
281 | ["rightHip", "rightShoulder"],
282 | ["rightElbow", "rightShoulder"],
283 | ["rightElbow", "rightWrist"],
284 | ["rightHip", "rightKnee"],
285 | ["rightKnee", "rightAnkle"],
286 | ["leftShoulder", "rightShoulder"],
287 | ["leftHip", "rightHip"],
288 | ].map(function (t) {
289 | var e = t[0],
290 | n = t[1];
291 | return [p[e], p[n]];
292 | });
293 | function m(t, e, n) {
294 | var r = t[0],
295 | o = t[1],
296 | i = e[0],
297 | a = e[1],
298 | s = n.top,
299 | u = n.bottom;
300 | return [a / (n.left + n.right + o), i / (s + u + r)];
301 | }
302 | function g(t, e, n, r) {
303 | return { y: r.get(t, e, n), x: r.get(t, e, n + h) };
304 | }
305 | function v(t, e, n) {
306 | var r = g(t.heatmapY, t.heatmapX, t.id, n),
307 | o = r.y,
308 | i = r.x;
309 | return { x: t.heatmapX * e + i, y: t.heatmapY * e + o };
310 | }
311 | function w(t, e, n) {
312 | return t < e ? e : t > n ? n : t;
313 | }
314 | function y(t, e) {
315 | return { x: t.x + e.x, y: t.y + e.y };
316 | }
317 | function b(t, e, n) {
318 | void 0 === n && (n = 0.3);
319 | for (var r = 0, o = 0, i = 0; i < t.length; i++)
320 | e.keypoints[i].score > n &&
321 | ((o += 1),
322 | (r +=
323 | Math.pow(t[i].x - e.keypoints[i].position.x, 2) +
324 | Math.pow(t[i].y - e.keypoints[i].position.y, 2)));
325 | return 0 === o ? (r = 1 / 0) : (r /= o), r;
326 | }
327 | function x(t, e, n, r, o, i, a) {
328 | for (
329 | var s = a[0],
330 | u = a[1],
331 | d = n(t),
332 | f = d.y * r + d.x,
333 | l = o[h * (2 * f) + e],
334 | c = o[h * (2 * f + 1) + e],
335 | p = t.y + l,
336 | m = t.x + c,
337 | g = 0;
338 | g < i;
339 | g++
340 | ) {
341 | p = Math.min(p, s - 1);
342 | var v = n({ x: (m = Math.min(m, u - 1)), y: p }),
343 | w = v.y * r + v.x;
344 | (p += l = o[h * (2 * w) + e]), (m += c = o[h * (2 * w + 1) + e]);
345 | }
346 | return { x: m, y: p };
347 | }
348 | function S(t, e, n, r, o, i, a, s, u, d) {
349 | for (
350 | var f = o[0],
351 | l = o[1],
352 | c = i[0],
353 | h = i[1],
354 | p = s[0],
355 | m = s[1],
356 | g = [],
357 | v = function (t) {
358 | return (function (t, e, n, r) {
359 | var o = e[0],
360 | i = e[1],
361 | a = n[0],
362 | s = n[1],
363 | u = Math.round(((o + t.y + 1) * s - 1) / r);
364 | return { x: Math.round(((i + t.x + 1) * a - 1) / r), y: u };
365 | })(t, [f, l], [c, h], u);
366 | },
367 | w = 0;
368 | w < r;
369 | w++
370 | ) {
371 | var y = x(t, w, v, a, e, d, [p, m]);
372 | g.push(y);
373 | }
374 | for (var S = -1, M = 1 / 0, k = 0; k < n.length; k++) {
375 | var _ = b(g, n[k]);
376 | _ < M && ((S = k), (M = _));
377 | }
378 | return S;
379 | }
380 | function M(t, e) {
381 | var n = t[0],
382 | r = t[1];
383 | return [Math.round((r - 1) / e + 1), Math.round((n - 1) / e + 1)];
384 | }
385 | function k(t, n, r, o, i, a, s, u, d, f, l) {
386 | for (
387 | var c = s[0],
388 | p = s[1],
389 | g = t.shape,
390 | v = g[0],
391 | w = g[1],
392 | y = n.shape.slice(0, 2),
393 | b = y[0],
394 | x = y[1],
395 | S = n.reshape([b, x, 2, h]),
396 | M = new Float32Array(l * h * 3).fill(0),
397 | k = 0;
398 | k < r.length;
399 | k++
400 | )
401 | for (var _ = k * h * 3, E = r[k], P = 0; P < h; P++) {
402 | var O = E.keypoints[P],
403 | I = _ + 3 * P;
404 | (M[I] = O.score), (M[I + 1] = O.position.y), (M[I + 2] = O.position.x);
405 | }
406 | var A = m([o, i], [c, p], u),
407 | R = A[0],
408 | H = A[1],
409 | T = e.tensor(M, [l, h, 3]),
410 | B = u.top,
411 | F = u.left,
412 | D = {
413 | variableNames: ["segmentation", "longOffsets", "poses"],
414 | outputShape: [v, w],
415 | userCode:
416 | "\n int convertToPositionInOutput(int pos, int pad, float scale, int stride) {\n return round(((float(pos + pad) + 1.0) * scale - 1.0) / float(stride));\n }\n\n float convertToPositionInOutputFloat(\n int pos, int pad, float scale, int stride) {\n return ((float(pos + pad) + 1.0) * scale - 1.0) / float(stride);\n }\n\n float dist(float x1, float y1, float x2, float y2) {\n return pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0);\n }\n\n float sampleLongOffsets(float h, float w, int d, int k) {\n float fh = fract(h);\n float fw = fract(w);\n int clH = int(ceil(h));\n int clW = int(ceil(w));\n int flH = int(floor(h));\n int flW = int(floor(w));\n float o11 = getLongOffsets(flH, flW, d, k);\n float o12 = getLongOffsets(flH, clW, d, k);\n float o21 = getLongOffsets(clH, flW, d, k);\n float o22 = getLongOffsets(clH, clW, d, k);\n float o1 = mix(o11, o12, fw);\n float o2 = mix(o21, o22, fw);\n return mix(o1, o2, fh);\n }\n\n int findNearestPose(int h, int w) {\n float prob = getSegmentation(h, w);\n if (prob < 1.0) {\n return -1;\n }\n\n // Done(Tyler): convert from output space h/w to strided space.\n float stridedH = convertToPositionInOutputFloat(\n h, " +
417 | B +
418 | ", " +
419 | H +
420 | ", " +
421 | a +
422 | ");\n float stridedW = convertToPositionInOutputFloat(\n w, " +
423 | F +
424 | ", " +
425 | R +
426 | ", " +
427 | a +
428 | ");\n\n float minDist = 1000000.0;\n int iMin = -1;\n for (int i = 0; i < " +
429 | l +
430 | "; i++) {\n float curDistSum = 0.0;\n int numKpt = 0;\n for (int k = 0; k < " +
431 | h +
432 | "; k++) {\n float dy = sampleLongOffsets(stridedH, stridedW, 0, k);\n float dx = sampleLongOffsets(stridedH, stridedW, 1, k);\n\n float y = float(h) + dy;\n float x = float(w) + dx;\n\n for (int s = 0; s < " +
433 | d +
434 | "; s++) {\n int yRounded = round(min(y, float(" +
435 | (o - 1) +
436 | ")));\n int xRounded = round(min(x, float(" +
437 | (i - 1) +
438 | ")));\n\n float yStrided = convertToPositionInOutputFloat(\n yRounded, " +
439 | B +
440 | ", " +
441 | H +
442 | ", " +
443 | a +
444 | ");\n float xStrided = convertToPositionInOutputFloat(\n xRounded, " +
445 | F +
446 | ", " +
447 | R +
448 | ", " +
449 | a +
450 | ");\n\n float dy = sampleLongOffsets(yStrided, xStrided, 0, k);\n float dx = sampleLongOffsets(yStrided, xStrided, 1, k);\n\n y = y + dy;\n x = x + dx;\n }\n\n float poseScore = getPoses(i, k, 0);\n float poseY = getPoses(i, k, 1);\n float poseX = getPoses(i, k, 2);\n if (poseScore > " +
451 | f +
452 | ") {\n numKpt = numKpt + 1;\n curDistSum = curDistSum + dist(x, y, poseX, poseY);\n }\n }\n if (numKpt > 0 && curDistSum / float(numKpt) < minDist) {\n minDist = curDistSum / float(numKpt);\n iMin = i;\n }\n }\n return iMin;\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int nearestPose = findNearestPose(coords[0], coords[1]);\n setOutput(float(nearestPose));\n }\n ",
453 | };
454 | return e.backend().compileAndRun(D, [t, S, T]);
455 | }
456 | function _() {
457 | return "webgl" === e.getBackend();
458 | }
459 | function E(t, n, r, o, i, u, d, f, l, c, h, p) {
460 | var g = d[0],
461 | v = d[1];
462 | return (
463 | void 0 === l && (l = 0.2),
464 | void 0 === c && (c = 8),
465 | void 0 === h && (h = 0.3),
466 | void 0 === p && (p = 10),
467 | a(this, void 0, void 0, function () {
468 | var a, d, w, y, b;
469 | return s(this, function (s) {
470 | switch (s.label) {
471 | case 0:
472 | return (
473 | (a = r.filter(function (t) {
474 | return t.score >= l;
475 | })),
476 | _()
477 | ? ((w = e.tidy(function () {
478 | var r = k(t, n, a, o, i, u, [g, v], f, c, h, p);
479 | return a.map(function (t, n) {
480 | return (function (t, n) {
481 | return e.tidy(function () {
482 | return t.equal(e.scalar(n)).toInt();
483 | });
484 | })(r, n);
485 | });
486 | })),
487 | [
488 | 4,
489 | Promise.all(
490 | w.map(function (t) {
491 | return t.data();
492 | })
493 | ),
494 | ])
495 | : [3, 2]
496 | );
497 | case 1:
498 | return (
499 | (d = s.sent()),
500 | w.forEach(function (t) {
501 | return t.dispose();
502 | }),
503 | [3, 5]
504 | );
505 | case 2:
506 | return [4, t.data()];
507 | case 3:
508 | return (y = s.sent()), [4, n.data()];
509 | case 4:
510 | (b = s.sent()),
511 | (d = (function (t, e, n, r, o, i, a, s, u, d) {
512 | var f = a[0],
513 | l = a[1];
514 | void 0 === d && (d = 5);
515 | for (
516 | var c = n.map(function (t) {
517 | return new Uint8Array(r * o).fill(0);
518 | }),
519 | h = s.top,
520 | p = s.left,
521 | g = m([r, o], [f, l], s),
522 | v = g[0],
523 | w = g[1],
524 | y = M([f, l], i)[0],
525 | b = 0;
526 | b < r;
527 | b += 1
528 | )
529 | for (var x = 0; x < o; x += 1) {
530 | var k = b * o + x;
531 | if (1 === t[k]) {
532 | var _ = S(
533 | { x: x, y: b },
534 | e,
535 | n,
536 | d,
537 | [h, p],
538 | [v, w],
539 | y,
540 | [r, o],
541 | i,
542 | u
543 | );
544 | _ >= 0 && (c[_][k] = 1);
545 | }
546 | }
547 | return c;
548 | })(y, b, a, o, i, u, [g, v], f, c)),
549 | (s.label = 5);
550 | case 5:
551 | return [
552 | 2,
553 | d.map(function (t, e) {
554 | return { data: t, pose: a[e], width: i, height: o };
555 | }),
556 | ];
557 | }
558 | });
559 | })
560 | );
561 | }
562 | function P(t, n, r, o, i, u, d, f, l, c, h, p, g) {
563 | var v = f[0],
564 | w = f[1];
565 | return (
566 | void 0 === c && (c = 0.2),
567 | void 0 === h && (h = 8),
568 | void 0 === p && (p = 0.3),
569 | void 0 === g && (g = 10),
570 | a(this, void 0, void 0, function () {
571 | var a, f, y, b, x, E;
572 | return s(this, function (s) {
573 | switch (s.label) {
574 | case 0:
575 | return (
576 | (a = o.filter(function (t) {
577 | return t.score >= c;
578 | })),
579 | _()
580 | ? ((y = e.tidy(function () {
581 | var o = k(t, n, a, i, u, d, [v, w], l, h, p, g);
582 | return a.map(function (t, n) {
583 | return (function (t, n, r) {
584 | return e.tidy(function () {
585 | return t
586 | .equal(e.scalar(r))
587 | .toInt()
588 | .mul(n.add(1))
589 | .sub(1);
590 | });
591 | })(o, r, n);
592 | });
593 | })),
594 | [
595 | 4,
596 | Promise.all(
597 | y.map(function (t) {
598 | return t.data();
599 | })
600 | ),
601 | ])
602 | : [3, 2]
603 | );
604 | case 1:
605 | return (
606 | (f = s.sent()),
607 | y.forEach(function (t) {
608 | return t.dispose();
609 | }),
610 | [3, 6]
611 | );
612 | case 2:
613 | return [4, t.data()];
614 | case 3:
615 | return (b = s.sent()), [4, n.data()];
616 | case 4:
617 | return (x = s.sent()), [4, r.data()];
618 | case 5:
619 | (E = s.sent()),
620 | (f = (function (t, e, n, r, o, i, a, s, u, d, f) {
621 | var l = s[0],
622 | c = s[1];
623 | void 0 === f && (f = 5);
624 | for (
625 | var h = r.map(function (t) {
626 | return new Int32Array(o * i).fill(-1);
627 | }),
628 | p = u.top,
629 | g = u.left,
630 | v = m([o, i], [l, c], u),
631 | w = v[0],
632 | y = v[1],
633 | b = M([l, c], a)[0],
634 | x = 0;
635 | x < o;
636 | x += 1
637 | )
638 | for (var k = 0; k < i; k += 1) {
639 | var _ = x * i + k;
640 | if (1 === t[_]) {
641 | var E = S(
642 | { x: k, y: x },
643 | e,
644 | r,
645 | f,
646 | [p, g],
647 | [w, y],
648 | b,
649 | [o, i],
650 | a,
651 | d
652 | );
653 | E >= 0 && (h[E][_] = n[_]);
654 | }
655 | }
656 | return h;
657 | })(b, x, E, a, i, u, d, [v, w], l, h)),
658 | (s.label = 6);
659 | case 6:
660 | return [
661 | 2,
662 | f.map(function (t, e) {
663 | return { pose: a[e], data: t, height: i, width: u };
664 | }),
665 | ];
666 | }
667 | });
668 | })
669 | );
670 | }
671 | function O(t) {
672 | return Math.floor(t / 2);
673 | }
674 | var I = (function () {
675 | function t(t, e) {
676 | (this.priorityQueue = new Array(t)),
677 | (this.numberOfElements = -1),
678 | (this.getElementValue = e);
679 | }
680 | return (
681 | (t.prototype.enqueue = function (t) {
682 | (this.priorityQueue[++this.numberOfElements] = t),
683 | this.swim(this.numberOfElements);
684 | }),
685 | (t.prototype.dequeue = function () {
686 | var t = this.priorityQueue[0];
687 | return (
688 | this.exchange(0, this.numberOfElements--),
689 | this.sink(0),
690 | (this.priorityQueue[this.numberOfElements + 1] = null),
691 | t
692 | );
693 | }),
694 | (t.prototype.empty = function () {
695 | return -1 === this.numberOfElements;
696 | }),
697 | (t.prototype.size = function () {
698 | return this.numberOfElements + 1;
699 | }),
700 | (t.prototype.all = function () {
701 | return this.priorityQueue.slice(0, this.numberOfElements + 1);
702 | }),
703 | (t.prototype.max = function () {
704 | return this.priorityQueue[0];
705 | }),
706 | (t.prototype.swim = function (t) {
707 | for (; t > 0 && this.less(O(t), t); )
708 | this.exchange(t, O(t)), (t = O(t));
709 | }),
710 | (t.prototype.sink = function (t) {
711 | for (; 2 * t <= this.numberOfElements; ) {
712 | var e = 2 * t;
713 | if (
714 | (e < this.numberOfElements && this.less(e, e + 1) && e++,
715 | !this.less(t, e))
716 | )
717 | break;
718 | this.exchange(t, e), (t = e);
719 | }
720 | }),
721 | (t.prototype.getValueAt = function (t) {
722 | return this.getElementValue(this.priorityQueue[t]);
723 | }),
724 | (t.prototype.less = function (t, e) {
725 | return this.getValueAt(t) < this.getValueAt(e);
726 | }),
727 | (t.prototype.exchange = function (t, e) {
728 | var n = this.priorityQueue[t];
729 | (this.priorityQueue[t] = this.priorityQueue[e]),
730 | (this.priorityQueue[e] = n);
731 | }),
732 | t
733 | );
734 | })();
735 | function A(t, e, n, r, o, i) {
736 | for (
737 | var a = i.shape,
738 | s = a[0],
739 | u = a[1],
740 | d = !0,
741 | f = Math.max(n - o, 0),
742 | l = Math.min(n + o + 1, s),
743 | c = f;
744 | c < l;
745 | ++c
746 | ) {
747 | for (
748 | var h = Math.max(r - o, 0), p = Math.min(r + o + 1, u), m = h;
749 | m < p;
750 | ++m
751 | )
752 | if (i.get(c, m, t) > e) {
753 | d = !1;
754 | break;
755 | }
756 | if (!d) break;
757 | }
758 | return d;
759 | }
760 | var R = [
761 | ["nose", "leftEye"],
762 | ["leftEye", "leftEar"],
763 | ["nose", "rightEye"],
764 | ["rightEye", "rightEar"],
765 | ["nose", "leftShoulder"],
766 | ["leftShoulder", "leftElbow"],
767 | ["leftElbow", "leftWrist"],
768 | ["leftShoulder", "leftHip"],
769 | ["leftHip", "leftKnee"],
770 | ["leftKnee", "leftAnkle"],
771 | ["nose", "rightShoulder"],
772 | ["rightShoulder", "rightElbow"],
773 | ["rightElbow", "rightWrist"],
774 | ["rightShoulder", "rightHip"],
775 | ["rightHip", "rightKnee"],
776 | ["rightKnee", "rightAnkle"],
777 | ].map(function (t) {
778 | var e = t[0],
779 | n = t[1];
780 | return [p[e], p[n]];
781 | }),
782 | H = R.map(function (t) {
783 | return t[1];
784 | }),
785 | T = R.map(function (t) {
786 | return t[0];
787 | });
788 | function B(t, e, n, r) {
789 | return {
790 | y: w(Math.round(t.y / e), 0, n - 1),
791 | x: w(Math.round(t.x / e), 0, r - 1),
792 | };
793 | }
794 | function F(t, e, n, r, o, i, a, s) {
795 | void 0 === s && (s = 2);
796 | for (
797 | var u = r.shape,
798 | d = u[0],
799 | f = u[1],
800 | l = (function (t, e, n) {
801 | var r = n.shape[2] / 2;
802 | return { y: n.get(e.y, e.x, t), x: n.get(e.y, e.x, r + t) };
803 | })(t, B(e.position, i, d, f), a),
804 | h = y(e.position, l),
805 | p = 0;
806 | p < s;
807 | p++
808 | ) {
809 | var m = B(h, i, d, f),
810 | v = g(m.y, m.x, n, o);
811 | h = y({ x: m.x * i, y: m.y * i }, { x: v.x, y: v.y });
812 | }
813 | var w = B(h, i, d, f),
814 | b = r.get(w.y, w.x, n);
815 | return { position: h, part: c[n], score: b };
816 | }
817 | function D(t, e, n, r, o, i) {
818 | var a = e.shape[2],
819 | s = H.length,
820 | u = new Array(a),
821 | d = t.part,
822 | f = t.score,
823 | l = v(d, r, n);
824 | u[d.id] = { score: f, part: c[d.id], position: l };
825 | for (var h = s - 1; h >= 0; --h) {
826 | var p = H[h],
827 | m = T[h];
828 | u[p] && !u[m] && (u[m] = F(h, u[p], m, e, n, r, i));
829 | }
830 | for (h = 0; h < s; ++h) {
831 | (p = T[h]), (m = H[h]);
832 | u[p] && !u[m] && (u[m] = F(h, u[p], m, e, n, r, o));
833 | }
834 | return u;
835 | }
836 | function L(t, e, n, r) {
837 | var o = n.x,
838 | i = n.y;
839 | return t.some(function (t) {
840 | var n,
841 | a,
842 | s,
843 | u,
844 | d,
845 | f,
846 | l = t.keypoints[r].position;
847 | return (
848 | (n = i),
849 | (a = o),
850 | (s = l.y),
851 | (u = l.x),
852 | (d = s - n) * d + (f = u - a) * f <= e
853 | );
854 | });
855 | }
856 | function q(t, e, n) {
857 | return (
858 | n.reduce(function (n, r, o) {
859 | var i = r.position,
860 | a = r.score;
861 | return L(t, e, i, o) || (n += a), n;
862 | }, 0) / n.length
863 | );
864 | }
865 | var z = 1;
866 | function C(t, e, n, r, o, i, a, s) {
867 | void 0 === a && (a = 0.5), void 0 === s && (s = 20);
868 | for (
869 | var u = [],
870 | d = (function (t, e, n) {
871 | for (
872 | var r = n.shape,
873 | o = r[0],
874 | i = r[1],
875 | a = r[2],
876 | s = new I(o * i * a, function (t) {
877 | return t.score;
878 | }),
879 | u = 0;
880 | u < o;
881 | ++u
882 | )
883 | for (var d = 0; d < i; ++d)
884 | for (var f = 0; f < a; ++f) {
885 | var l = n.get(u, d, f);
886 | l < t ||
887 | (A(f, l, u, d, e, n) &&
888 | s.enqueue({
889 | score: l,
890 | part: { heatmapY: u, heatmapX: d, id: f },
891 | }));
892 | }
893 | return s;
894 | })(a, z, t),
895 | f = s * s;
896 | u.length < i && !d.empty();
897 |
898 | ) {
899 | var l = d.dequeue();
900 | if (!L(u, f, v(l.part, o, e), l.part.id)) {
901 | var c = D(l, t, e, o, n, r),
902 | h = q(u, f, c);
903 | u.push({ keypoints: c, score: h });
904 | }
905 | }
906 | return u;
907 | }
908 | var W,
909 | K = [-123.15, -115.9, -103.06],
910 | j = (function (t) {
911 | function e() {
912 | return (null !== t && t.apply(this, arguments)) || this;
913 | }
914 | return (
915 | o(e, t),
916 | (e.prototype.preprocessInput = function (t) {
917 | return t.add(K);
918 | }),
919 | (e.prototype.nameOutputResults = function (t) {
920 | var e = t[0],
921 | n = t[1],
922 | r = t[2],
923 | o = t[3],
924 | i = t[4],
925 | a = t[5];
926 | return {
927 | offsets: i,
928 | segmentation: t[6],
929 | partHeatmaps: a,
930 | longOffsets: o,
931 | heatmap: r,
932 | displacementFwd: n,
933 | displacementBwd: e,
934 | partOffsets: t[7],
935 | };
936 | }),
937 | e
938 | );
939 | })(f),
940 | N =
941 | "https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/",
942 | V =
943 | "https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/";
944 | function Q(t) {
945 | if (
946 | ("undefined" != typeof HTMLCanvasElement &&
947 | t instanceof HTMLCanvasElement) ||
948 | ("undefined" != typeof HTMLImageElement && t instanceof HTMLImageElement)
949 | )
950 | return (function (t) {
951 | if (0 !== t.offsetHeight && 0 !== t.offsetWidth)
952 | return [t.offsetHeight, t.offsetWidth];
953 | if (null != t.height && null != t.width) return [t.height, t.width];
954 | throw new Error(
955 | "HTMLImageElement must have height and width attributes set."
956 | );
957 | })(t);
958 | if ("undefined" != typeof ImageData && t instanceof ImageData)
959 | return [t.height, t.width];
960 | if ("undefined" != typeof HTMLVideoElement && t instanceof HTMLVideoElement)
961 | return (function (t) {
962 | return null != t.height && null != t.width
963 | ? [t.height, t.width]
964 | : [t.videoHeight, t.videoWidth];
965 | })(t);
966 | if (t instanceof e.Tensor) return [t.shape[0], t.shape[1]];
967 | throw new Error("error: Unknown input type: " + t + ".");
968 | }
969 | function U(t, e) {
970 | return (function (t, e) {
971 | return (t - 1) % e == 0;
972 | })(t, e)
973 | ? t
974 | : Math.floor(t / e) * e + 1;
975 | }
976 | var X = { low: "low", medium: "medium", high: "high", full: "full" },
977 | Y =
978 | (((W = {})[X.low] = 0.25),
979 | (W[X.medium] = 0.5),
980 | (W[X.high] = 0.75),
981 | (W[X.full] = 1),
982 | W),
983 | G = 0.1,
984 | J = 2;
985 | function Z(t, n, r) {
986 | var o = r[0],
987 | i = r[1],
988 | a = (function (t) {
989 | if ("string" == typeof t) {
990 | var n = Y[t];
991 | return (
992 | e.util.assert("number" == typeof n, function () {
993 | return (
994 | "string value of inputResolution must be one of " +
995 | Object.values(X).join(",") +
996 | " but was " +
997 | t +
998 | "."
999 | );
1000 | }),
1001 | n
1002 | );
1003 | }
1004 | return (
1005 | e.util.assert("number" == typeof t && t <= J && t >= G, function () {
1006 | return (
1007 | "inputResolution must be a string or number between " +
1008 | G +
1009 | " and " +
1010 | J +
1011 | ", but was " +
1012 | t
1013 | );
1014 | }),
1015 | t
1016 | );
1017 | })(t);
1018 | return [U(o * a, n), U(i * a, n)];
1019 | }
1020 | function $(t, n, r, o, i) {
1021 | var a = n[0],
1022 | s = n[1],
1023 | u = r[0],
1024 | d = r[1],
1025 | f = o[0],
1026 | l = f[0],
1027 | c = f[1],
1028 | h = o[1],
1029 | p = h[0],
1030 | m = h[1];
1031 | return (
1032 | void 0 === i && (i = !1),
1033 | e.tidy(function () {
1034 | var n = t.resizeBilinear([u, d], !0);
1035 | return (
1036 | i && (n = n.sigmoid()),
1037 | (function (t, n, r) {
1038 | var o = n[0],
1039 | i = n[1],
1040 | a = r[0],
1041 | s = a[0],
1042 | u = a[1],
1043 | d = r[1],
1044 | f = d[0],
1045 | l = d[1];
1046 | return e.tidy(function () {
1047 | return e.image
1048 | .cropAndResize(
1049 | t.expandDims(),
1050 | [
1051 | [
1052 | s / (o + s + u - 1),
1053 | f / (i + f + l - 1),
1054 | (s + o - 1) / (o + s + u - 1),
1055 | (f + i - 1) / (i + f + l - 1),
1056 | ],
1057 | ],
1058 | [0],
1059 | [o, i]
1060 | )
1061 | .squeeze([0]);
1062 | });
1063 | })(
1064 | n,
1065 | [a, s],
1066 | [
1067 | [l, c],
1068 | [p, m],
1069 | ]
1070 | )
1071 | );
1072 | })
1073 | );
1074 | }
1075 | function tt(t, n) {
1076 | var r = n[0],
1077 | o = n[1],
1078 | i = Q(t),
1079 | a = i[0],
1080 | s = i[1],
1081 | u = o / r,
1082 | d = [0, 0, 0, 0],
1083 | f = d[0],
1084 | l = d[1],
1085 | c = d[2],
1086 | h = d[3];
1087 | return (
1088 | s / a < u
1089 | ? ((f = 0),
1090 | (l = 0),
1091 | (c = Math.round(0.5 * (u * a - s))),
1092 | (h = Math.round(0.5 * (u * a - s))))
1093 | : ((f = Math.round(0.5 * ((1 / u) * s - a))),
1094 | (l = Math.round(0.5 * ((1 / u) * s - a))),
1095 | (c = 0),
1096 | (h = 0)),
1097 | {
1098 | resized: e.tidy(function () {
1099 | var n = (function (t) {
1100 | return t instanceof e.Tensor ? t : e.browser.fromPixels(t);
1101 | })(t);
1102 | return (n = e.pad3d(n, [
1103 | [f, l],
1104 | [c, h],
1105 | [0, 0],
1106 | ])).resizeBilinear([r, o]);
1107 | }),
1108 | padding: { top: f, left: c, right: h, bottom: l },
1109 | }
1110 | );
1111 | }
1112 | function et(t) {
1113 | return a(this, void 0, void 0, function () {
1114 | return s(this, function (e) {
1115 | return [
1116 | 2,
1117 | Promise.all(
1118 | t.map(function (t) {
1119 | return t.buffer();
1120 | })
1121 | ),
1122 | ];
1123 | });
1124 | });
1125 | }
1126 | function nt(t, e) {
1127 | return {
1128 | score: t.score,
1129 | keypoints: t.keypoints.map(function (t) {
1130 | var n = t.score,
1131 | r = t.part,
1132 | o = t.position;
1133 | return { score: n, part: r, position: { x: e - 1 - o.x, y: o.y } };
1134 | }),
1135 | };
1136 | }
1137 | function rt(t, e, n, r, o) {
1138 | var i = e[0],
1139 | a = e[1],
1140 | s = n[0],
1141 | u = n[1],
1142 | d = (function (t, e, n, r, o) {
1143 | return (
1144 | void 0 === r && (r = 0),
1145 | void 0 === o && (o = 0),
1146 | 1 === n && 1 === e && 0 === r && 0 === o
1147 | ? t
1148 | : t.map(function (t) {
1149 | return (function (t, e, n, r, o) {
1150 | return (
1151 | void 0 === r && (r = 0),
1152 | void 0 === o && (o = 0),
1153 | {
1154 | score: t.score,
1155 | keypoints: t.keypoints.map(function (t) {
1156 | var i = t.score,
1157 | a = t.part,
1158 | s = t.position;
1159 | return {
1160 | score: i,
1161 | part: a,
1162 | position: { x: s.x * n + o, y: s.y * e + r },
1163 | };
1164 | }),
1165 | }
1166 | );
1167 | })(t, e, n, r, o);
1168 | })
1169 | );
1170 | })(
1171 | t,
1172 | (i + r.top + r.bottom) / s,
1173 | (a + r.left + r.right) / u,
1174 | -r.top,
1175 | -r.left
1176 | );
1177 | return o
1178 | ? (function (t, e) {
1179 | return e <= 0
1180 | ? t
1181 | : t.map(function (t) {
1182 | return nt(t, e);
1183 | });
1184 | })(d, a)
1185 | : d;
1186 | }
1187 | var ot = {
1188 | architecture: "MobileNetV1",
1189 | outputStride: 16,
1190 | quantBytes: 4,
1191 | multiplier: 0.75,
1192 | },
1193 | it = ["MobileNetV1", "ResNet50"],
1194 | at = { MobileNetV1: [8, 16, 32], ResNet50: [32, 16] },
1195 | st = { MobileNetV1: [0.5, 0.75, 1], ResNet50: [1] },
1196 | ut = [1, 2, 4];
1197 | var dt = {
1198 | flipHorizontal: !1,
1199 | internalResolution: "medium",
1200 | segmentationThreshold: 0.7,
1201 | maxDetections: 10,
1202 | scoreThreshold: 0.4,
1203 | nmsRadius: 20,
1204 | },
1205 | ft = {
1206 | flipHorizontal: !1,
1207 | internalResolution: "medium",
1208 | segmentationThreshold: 0.7,
1209 | maxDetections: 10,
1210 | scoreThreshold: 0.4,
1211 | nmsRadius: 20,
1212 | minKeypointScore: 0.3,
1213 | refineSteps: 10,
1214 | };
1215 | function lt(t) {
1216 | var e = t.segmentationThreshold,
1217 | n = t.maxDetections,
1218 | r = t.scoreThreshold,
1219 | o = t.nmsRadius;
1220 | if (e < 0 || e > 1)
1221 | throw new Error(
1222 | "segmentationThreshold " + e + ". Should be in range [0.0, 1.0]"
1223 | );
1224 | if (n <= 0)
1225 | throw new Error("Invalid maxDetections " + n + ". Should be > 0");
1226 | if (r < 0 || r > 1)
1227 | throw new Error(
1228 | "Invalid scoreThreshold " + r + ". Should be in range [0.0, 1.0]"
1229 | );
1230 | if (o <= 0) throw new Error("Invalid nmsRadius " + o + ".");
1231 | }
1232 | function ct(t) {
1233 | var e = t.segmentationThreshold,
1234 | n = t.maxDetections,
1235 | r = t.scoreThreshold,
1236 | o = t.nmsRadius,
1237 | i = t.minKeypointScore,
1238 | a = t.refineSteps;
1239 | if (e < 0 || e > 1)
1240 | throw new Error(
1241 | "segmentationThreshold " + e + ". Should be in range [0.0, 1.0]"
1242 | );
1243 | if (n <= 0)
1244 | throw new Error("Invalid maxDetections " + n + ". Should be > 0");
1245 | if (r < 0 || r > 1)
1246 | throw new Error(
1247 | "Invalid scoreThreshold " + r + ". Should be in range [0.0, 1.0]"
1248 | );
1249 | if (o <= 0) throw new Error("Invalid nmsRadius " + o + ".");
1250 | if (i < 0 || i > 1)
1251 | throw new Error(
1252 | "Invalid minKeypointScore " + i + ".Should be in range [0.0, 1.0]"
1253 | );
1254 | if (a <= 0 || a > 20)
1255 | throw new Error(
1256 | "Invalid refineSteps " + a + ".Should be in range [1, 20]"
1257 | );
1258 | }
1259 | var ht = (function () {
1260 | function t(t) {
1261 | this.baseModel = t;
1262 | }
1263 | return (
1264 | (t.prototype.predictForPersonSegmentation = function (t) {
1265 | var e = this.baseModel.predict(t);
1266 | return {
1267 | segmentLogits: e.segmentation,
1268 | heatmapScores: e.heatmapScores,
1269 | offsets: e.offsets,
1270 | displacementFwd: e.displacementFwd,
1271 | displacementBwd: e.displacementBwd,
1272 | };
1273 | }),
1274 | (t.prototype.predictForPersonSegmentationAndPart = function (t) {
1275 | var e = this.baseModel.predict(t);
1276 | return {
1277 | segmentLogits: e.segmentation,
1278 | partHeatmapLogits: e.partHeatmaps,
1279 | heatmapScores: e.heatmapScores,
1280 | offsets: e.offsets,
1281 | displacementFwd: e.displacementFwd,
1282 | displacementBwd: e.displacementBwd,
1283 | };
1284 | }),
1285 | (t.prototype.predictForMultiPersonInstanceSegmentationAndPart = function (
1286 | t
1287 | ) {
1288 | var e = this.baseModel.predict(t);
1289 | return {
1290 | segmentLogits: e.segmentation,
1291 | longOffsets: e.longOffsets,
1292 | heatmapScores: e.heatmapScores,
1293 | offsets: e.offsets,
1294 | displacementFwd: e.displacementFwd,
1295 | displacementBwd: e.displacementBwd,
1296 | partHeatmaps: e.partHeatmaps,
1297 | };
1298 | }),
1299 | (t.prototype.segmentPersonActivation = function (t, n, r) {
1300 | var o = this;
1301 | void 0 === r && (r = 0.5);
1302 | var i = Q(t),
1303 | a = i[0],
1304 | s = i[1],
1305 | u = Z(n, this.baseModel.outputStride, [a, s]),
1306 | f = tt(t, u),
1307 | l = f.resized,
1308 | c = f.padding,
1309 | h = e.tidy(function () {
1310 | var t = o.predictForPersonSegmentation(l),
1311 | e = t.segmentLogits,
1312 | n = t.heatmapScores,
1313 | i = t.offsets,
1314 | u = t.displacementFwd,
1315 | f = t.displacementBwd,
1316 | h = l.shape,
1317 | p = h[0],
1318 | m = h[1];
1319 | return {
1320 | segmentation: d(
1321 | $(
1322 | e,
1323 | [a, s],
1324 | [p, m],
1325 | [
1326 | [c.top, c.bottom],
1327 | [c.left, c.right],
1328 | ],
1329 | !0
1330 | ).squeeze(),
1331 | r
1332 | ),
1333 | heatmapScores: n,
1334 | offsets: i,
1335 | displacementFwd: u,
1336 | displacementBwd: f,
1337 | };
1338 | }),
1339 | p = h.segmentation,
1340 | m = h.heatmapScores,
1341 | g = h.offsets,
1342 | v = h.displacementFwd,
1343 | w = h.displacementBwd;
1344 | return (
1345 | l.dispose(),
1346 | {
1347 | segmentation: p,
1348 | heatmapScores: m,
1349 | offsets: g,
1350 | displacementFwd: v,
1351 | displacementBwd: w,
1352 | padding: c,
1353 | internalResolutionHeightAndWidth: u,
1354 | }
1355 | );
1356 | }),
1357 | (t.prototype.segmentPerson = function (t, e) {
1358 | return (
1359 | void 0 === e && (e = dt),
1360 | a(this, void 0, void 0, function () {
1361 | var n, r, o, a, u, d, f, l, c, h, p, m, g, v, w, y, b, x;
1362 | return s(this, function (s) {
1363 | switch (s.label) {
1364 | case 0:
1365 | return (
1366 | lt((e = i({}, dt, e))),
1367 | (n = this.segmentPersonActivation(
1368 | t,
1369 | e.internalResolution,
1370 | e.segmentationThreshold
1371 | )),
1372 | (r = n.segmentation),
1373 | (o = n.heatmapScores),
1374 | (a = n.offsets),
1375 | (u = n.displacementFwd),
1376 | (d = n.displacementBwd),
1377 | (f = n.padding),
1378 | (l = n.internalResolutionHeightAndWidth),
1379 | (c = r.shape),
1380 | (h = c[0]),
1381 | (p = c[1]),
1382 | [4, r.data()]
1383 | );
1384 | case 1:
1385 | return (m = s.sent()), r.dispose(), [4, et([o, a, u, d])];
1386 | case 2:
1387 | return (
1388 | (g = s.sent()),
1389 | (v = g[0]),
1390 | (w = g[1]),
1391 | (y = g[2]),
1392 | (b = g[3]),
1393 | (x = rt(
1394 | (x = C(
1395 | v,
1396 | w,
1397 | y,
1398 | b,
1399 | this.baseModel.outputStride,
1400 | e.maxDetections,
1401 | e.scoreThreshold,
1402 | e.nmsRadius
1403 | )),
1404 | [h, p],
1405 | l,
1406 | f,
1407 | !1
1408 | )),
1409 | o.dispose(),
1410 | a.dispose(),
1411 | u.dispose(),
1412 | d.dispose(),
1413 | [2, { height: h, width: p, data: m, allPoses: x }]
1414 | );
1415 | }
1416 | });
1417 | })
1418 | );
1419 | }),
1420 | (t.prototype.segmentMultiPerson = function (t, n) {
1421 | return (
1422 | void 0 === n && (n = ft),
1423 | a(this, void 0, void 0, function () {
1424 | var r,
1425 | o,
1426 | a,
1427 | u,
1428 | f,
1429 | l,
1430 | c,
1431 | h,
1432 | p,
1433 | m,
1434 | g,
1435 | v,
1436 | w,
1437 | y,
1438 | b,
1439 | x,
1440 | S,
1441 | M,
1442 | k,
1443 | _,
1444 | P,
1445 | O = this;
1446 | return s(this, function (s) {
1447 | switch (s.label) {
1448 | case 0:
1449 | return (
1450 | ct((n = i({}, ft, n))),
1451 | (r = Q(t)),
1452 | (o = r[0]),
1453 | (a = r[1]),
1454 | (u = Z(n.internalResolution, this.baseModel.outputStride, [
1455 | o,
1456 | a,
1457 | ])),
1458 | (f = tt(t, u)),
1459 | (l = f.resized),
1460 | (c = f.padding),
1461 | (h = e.tidy(function () {
1462 | var t,
1463 | e =
1464 | O.predictForMultiPersonInstanceSegmentationAndPart(l),
1465 | r = e.segmentLogits,
1466 | i = e.longOffsets,
1467 | s = e.heatmapScores,
1468 | f = e.offsets,
1469 | h = e.displacementFwd,
1470 | p = e.displacementBwd;
1471 | return (
1472 | (t = i),
1473 | {
1474 | segmentation: d(
1475 | $(
1476 | r,
1477 | [o, a],
1478 | u,
1479 | [
1480 | [c.top, c.bottom],
1481 | [c.left, c.right],
1482 | ],
1483 | !0
1484 | ).squeeze(),
1485 | n.segmentationThreshold
1486 | ),
1487 | longOffsets: t,
1488 | heatmapScoresRaw: s,
1489 | offsetsRaw: f,
1490 | displacementFwdRaw: h,
1491 | displacementBwdRaw: p,
1492 | }
1493 | );
1494 | })),
1495 | (p = h.segmentation),
1496 | (m = h.longOffsets),
1497 | (g = h.heatmapScoresRaw),
1498 | (v = h.offsetsRaw),
1499 | (w = h.displacementFwdRaw),
1500 | (y = h.displacementBwdRaw),
1501 | [4, et([g, v, w, y])]
1502 | );
1503 | case 1:
1504 | return (
1505 | (b = s.sent()),
1506 | (x = b[0]),
1507 | (S = b[1]),
1508 | (M = b[2]),
1509 | (k = b[3]),
1510 | (_ = rt(
1511 | (_ = C(
1512 | x,
1513 | S,
1514 | M,
1515 | k,
1516 | this.baseModel.outputStride,
1517 | n.maxDetections,
1518 | n.scoreThreshold,
1519 | n.nmsRadius
1520 | )),
1521 | [o, a],
1522 | u,
1523 | c,
1524 | !1
1525 | )),
1526 | [
1527 | 4,
1528 | E(
1529 | p,
1530 | m,
1531 | _,
1532 | o,
1533 | a,
1534 | this.baseModel.outputStride,
1535 | u,
1536 | c,
1537 | n.scoreThreshold,
1538 | n.refineSteps,
1539 | n.minKeypointScore,
1540 | n.maxDetections
1541 | ),
1542 | ]
1543 | );
1544 | case 2:
1545 | return (
1546 | (P = s.sent()),
1547 | l.dispose(),
1548 | p.dispose(),
1549 | m.dispose(),
1550 | g.dispose(),
1551 | v.dispose(),
1552 | w.dispose(),
1553 | y.dispose(),
1554 | [2, P]
1555 | );
1556 | }
1557 | });
1558 | })
1559 | );
1560 | }),
1561 | (t.prototype.segmentPersonPartsActivation = function (t, n, r) {
1562 | var o = this;
1563 | void 0 === r && (r = 0.5);
1564 | var i = Q(t),
1565 | a = i[0],
1566 | s = i[1],
1567 | f = Z(n, this.baseModel.outputStride, [a, s]),
1568 | l = tt(t, f),
1569 | c = l.resized,
1570 | h = l.padding,
1571 | p = e.tidy(function () {
1572 | var t = o.predictForPersonSegmentationAndPart(c),
1573 | n = t.segmentLogits,
1574 | i = t.partHeatmapLogits,
1575 | f = t.heatmapScores,
1576 | l = t.offsets,
1577 | p = t.displacementFwd,
1578 | m = t.displacementBwd,
1579 | g = c.shape,
1580 | v = g[0],
1581 | w = g[1],
1582 | y = $(
1583 | n,
1584 | [a, s],
1585 | [v, w],
1586 | [
1587 | [h.top, h.bottom],
1588 | [h.left, h.right],
1589 | ],
1590 | !0
1591 | ),
1592 | b = $(
1593 | i,
1594 | [a, s],
1595 | [v, w],
1596 | [
1597 | [h.top, h.bottom],
1598 | [h.left, h.right],
1599 | ],
1600 | !0
1601 | );
1602 | return {
1603 | partSegmentation: (function (t, n) {
1604 | var r = n.shape,
1605 | o = r[0],
1606 | i = r[1],
1607 | a = r[2];
1608 | return e.tidy(function () {
1609 | var r,
1610 | s,
1611 | d = u(n),
1612 | f = e.range(0, a, 1, "int32").expandDims(1),
1613 | l = d
1614 | .matMul(f)
1615 | .toInt()
1616 | .reshape([o, i])
1617 | .add(e.scalar(1, "int32"));
1618 | return ((r = l), (s = t), r.mul(s)).sub(e.scalar(1, "int32"));
1619 | });
1620 | })(d(y.squeeze(), r), b),
1621 | heatmapScores: f,
1622 | offsets: l,
1623 | displacementFwd: p,
1624 | displacementBwd: m,
1625 | };
1626 | }),
1627 | m = p.partSegmentation,
1628 | g = p.heatmapScores,
1629 | v = p.offsets,
1630 | w = p.displacementFwd,
1631 | y = p.displacementBwd;
1632 | return (
1633 | c.dispose(),
1634 | {
1635 | partSegmentation: m,
1636 | heatmapScores: g,
1637 | offsets: v,
1638 | displacementFwd: w,
1639 | displacementBwd: y,
1640 | padding: h,
1641 | internalResolutionHeightAndWidth: f,
1642 | }
1643 | );
1644 | }),
1645 | (t.prototype.segmentPersonParts = function (t, e) {
1646 | return (
1647 | void 0 === e && (e = dt),
1648 | a(this, void 0, void 0, function () {
1649 | var n, r, o, a, u, d, f, l, c, h, p, m, g, v, w, y, b, x;
1650 | return s(this, function (s) {
1651 | switch (s.label) {
1652 | case 0:
1653 | return (
1654 | lt((e = i({}, dt, e))),
1655 | (n = this.segmentPersonPartsActivation(
1656 | t,
1657 | e.internalResolution,
1658 | e.segmentationThreshold
1659 | )),
1660 | (r = n.partSegmentation),
1661 | (o = n.heatmapScores),
1662 | (a = n.offsets),
1663 | (u = n.displacementFwd),
1664 | (d = n.displacementBwd),
1665 | (f = n.padding),
1666 | (l = n.internalResolutionHeightAndWidth),
1667 | (c = r.shape),
1668 | (h = c[0]),
1669 | (p = c[1]),
1670 | [4, r.data()]
1671 | );
1672 | case 1:
1673 | return (m = s.sent()), r.dispose(), [4, et([o, a, u, d])];
1674 | case 2:
1675 | return (
1676 | (g = s.sent()),
1677 | (v = g[0]),
1678 | (w = g[1]),
1679 | (y = g[2]),
1680 | (b = g[3]),
1681 | (x = rt(
1682 | (x = C(
1683 | v,
1684 | w,
1685 | y,
1686 | b,
1687 | this.baseModel.outputStride,
1688 | e.maxDetections,
1689 | e.scoreThreshold,
1690 | e.nmsRadius
1691 | )),
1692 | [h, p],
1693 | l,
1694 | f,
1695 | !1
1696 | )),
1697 | o.dispose(),
1698 | a.dispose(),
1699 | u.dispose(),
1700 | d.dispose(),
1701 | [2, { height: h, width: p, data: m, allPoses: x }]
1702 | );
1703 | }
1704 | });
1705 | })
1706 | );
1707 | }),
1708 | (t.prototype.segmentMultiPersonParts = function (t, n) {
1709 | return (
1710 | void 0 === n && (n = ft),
1711 | a(this, void 0, void 0, function () {
1712 | var r,
1713 | o,
1714 | a,
1715 | f,
1716 | l,
1717 | c,
1718 | h,
1719 | p,
1720 | m,
1721 | g,
1722 | v,
1723 | w,
1724 | y,
1725 | b,
1726 | x,
1727 | S,
1728 | M,
1729 | k,
1730 | _,
1731 | E,
1732 | O,
1733 | I,
1734 | A = this;
1735 | return s(this, function (s) {
1736 | switch (s.label) {
1737 | case 0:
1738 | return (
1739 | ct((n = i({}, ft, n))),
1740 | (r = Q(t)),
1741 | (o = r[0]),
1742 | (a = r[1]),
1743 | (f = Z(n.internalResolution, this.baseModel.outputStride, [
1744 | o,
1745 | a,
1746 | ])),
1747 | (l = tt(t, f)),
1748 | (c = l.resized),
1749 | (h = l.padding),
1750 | (p = e.tidy(function () {
1751 | var t =
1752 | A.predictForMultiPersonInstanceSegmentationAndPart(c),
1753 | r = t.segmentLogits,
1754 | i = t.longOffsets,
1755 | s = t.heatmapScores,
1756 | l = t.offsets,
1757 | p = t.displacementFwd,
1758 | m = t.displacementBwd,
1759 | g = t.partHeatmaps,
1760 | v = $(
1761 | r,
1762 | [o, a],
1763 | f,
1764 | [
1765 | [h.top, h.bottom],
1766 | [h.left, h.right],
1767 | ],
1768 | !0
1769 | ),
1770 | w = $(
1771 | g,
1772 | [o, a],
1773 | f,
1774 | [
1775 | [h.top, h.bottom],
1776 | [h.left, h.right],
1777 | ],
1778 | !0
1779 | ),
1780 | y = i;
1781 | return {
1782 | segmentation: d(v.squeeze(), n.segmentationThreshold),
1783 | longOffsets: y,
1784 | heatmapScoresRaw: s,
1785 | offsetsRaw: l,
1786 | displacementFwdRaw: p,
1787 | displacementBwdRaw: m,
1788 | partSegmentation: (function (t) {
1789 | var n = t.shape,
1790 | r = n[0],
1791 | o = n[1],
1792 | i = n[2];
1793 | return e.tidy(function () {
1794 | var n = u(t),
1795 | a = e.range(0, i, 1, "int32").expandDims(1);
1796 | return n.matMul(a).toInt().reshape([r, o]);
1797 | });
1798 | })(w),
1799 | };
1800 | })),
1801 | (m = p.segmentation),
1802 | (g = p.longOffsets),
1803 | (v = p.heatmapScoresRaw),
1804 | (w = p.offsetsRaw),
1805 | (y = p.displacementFwdRaw),
1806 | (b = p.displacementBwdRaw),
1807 | (x = p.partSegmentation),
1808 | [4, et([v, w, y, b])]
1809 | );
1810 | case 1:
1811 | return (
1812 | (S = s.sent()),
1813 | (M = S[0]),
1814 | (k = S[1]),
1815 | (_ = S[2]),
1816 | (E = S[3]),
1817 | (O = rt(
1818 | (O = C(
1819 | M,
1820 | k,
1821 | _,
1822 | E,
1823 | this.baseModel.outputStride,
1824 | n.maxDetections,
1825 | n.scoreThreshold,
1826 | n.nmsRadius
1827 | )),
1828 | [o, a],
1829 | f,
1830 | h,
1831 | !1
1832 | )),
1833 | [
1834 | 4,
1835 | P(
1836 | m,
1837 | g,
1838 | x,
1839 | O,
1840 | o,
1841 | a,
1842 | this.baseModel.outputStride,
1843 | f,
1844 | h,
1845 | n.scoreThreshold,
1846 | n.refineSteps,
1847 | n.minKeypointScore,
1848 | n.maxDetections
1849 | ),
1850 | ]
1851 | );
1852 | case 2:
1853 | return (
1854 | (I = s.sent()),
1855 | c.dispose(),
1856 | m.dispose(),
1857 | g.dispose(),
1858 | v.dispose(),
1859 | w.dispose(),
1860 | y.dispose(),
1861 | b.dispose(),
1862 | x.dispose(),
1863 | [2, I]
1864 | );
1865 | }
1866 | });
1867 | })
1868 | );
1869 | }),
1870 | (t.prototype.dispose = function () {
1871 | this.baseModel.dispose();
1872 | }),
1873 | t
1874 | );
1875 | })();
1876 | function pt(t) {
1877 | return a(this, void 0, void 0, function () {
1878 | var r, o, i, a, u, d;
1879 | return s(this, function (s) {
1880 | switch (s.label) {
1881 | case 0:
1882 | if (
1883 | ((r = t.outputStride),
1884 | (o = t.quantBytes),
1885 | (i = t.multiplier),
1886 | null == e)
1887 | )
1888 | throw new Error(
1889 | "Cannot find TensorFlow.js. If you are using a