ABEMA Little Tools

ABEMAをちょっとだけ便利にするかもしれない機能をまとめました。

当前为 2024-04-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ABEMA Little Tools
  3. // @namespace https://greasyfork.org/ja/scripts/465585
  4. // @version 9
  5. // @description ABEMAをちょっとだけ便利にするかもしれない機能をまとめました。
  6. // @match https://abema.tv/*
  7. // @connect abema-tv.com
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_xmlhttpRequest
  10. // @license MIT License
  11. // @noframes
  12. // ==/UserScript==
  13.  
  14. (() => {
  15. 'use strict';
  16. const sid = 'LittleTools',
  17. ls = JSON.parse(localStorage.getItem(sid) || '{}') || {},
  18. lsWord = JSON.parse(localStorage.getItem(`${sid}-Word`) || '{}') || {},
  19. lsId = JSON.parse(localStorage.getItem(`${sid}-Id`) || '{}') || {},
  20. data = {
  21. archiveComments: [
  22. {
  23. createdAtMs: 0,
  24. elapsedMs: 0,
  25. id: '',
  26. isOwner: false,
  27. message: '',
  28. userId: '',
  29. },
  30. ],
  31. blockedUserId: '',
  32. comment: [{ userid: '', message: [''] }],
  33. commentAll: 0,
  34. commentId: new Set(),
  35. commentMouseEnter: false,
  36. href: '',
  37. newComments: false,
  38. ngId: new Set(lsId.ngId),
  39. /** @type {string[]} */
  40. ngWordText: [],
  41. ngWordRe: [{}],
  42. statsDomain: '',
  43. version: 9,
  44. videoSource: '',
  45. },
  46. interval = {
  47. archiveComments: 0,
  48. changeTargetQuality: 0,
  49. comment: 0,
  50. footer: 0,
  51. init: 0,
  52. navigation: 0,
  53. newcomment: 0,
  54. notification: 0,
  55. resizeVideo: 0,
  56. resolution: 0,
  57. statsI: 0,
  58. statsT: 0,
  59. videoelement: 0,
  60. videoskip: 0,
  61. videosource: 0,
  62. },
  63. selector = {
  64. archiveCommentContainer: 'c-archive-comment-ArchiveCommentContainerView',
  65. commentBefore: `:is(.com-tv-CommentBlock, .com-comment-CommentItem):has(> div:not([data-${sid.toLowerCase()}-hidden])), .com-archive-comment-ArchiveCommentItem:has(> p:not([data-${sid.toLowerCase()}-hidden]))`,
  66. commentDuplicate: `:is(.com-tv-CommentBlock, .com-comment-CommentItem):has(> div[data-${sid.toLowerCase()}-duplicate]), .com-archive-comment-ArchiveCommentItem:has(> p[data-${sid.toLowerCase()}-duplicate])`,
  67. commentHidden: `:is(.com-tv-CommentBlock, .com-comment-CommentItem):has(> div[data-${sid.toLowerCase()}-hidden="true"]), .com-archive-comment-ArchiveCommentItem:has(> p[data-${sid.toLowerCase()}-hidden="true"])`,
  68. comenntAll:
  69. '.com-tv-CommentBlock, .com-archive-comment-ArchiveCommentItem, .com-comment-CommentItem',
  70. commentArea:
  71. '.com-tv-CommentArea, .c-tv-TimeshiftPlayerContainerView__comment-wrapper:has(.com-a-OnReachTop > ul), .com-comment-CommentContainerView',
  72. commentButton: 'button:has(svg[aria-label^="コメント"])',
  73. commentContinue:
  74. '.com-tv-CommentArea__continue-button, .c-archive-comment-ArchiveCommentContainerView__new-comment-button, .com-comment-CommentContinueButton',
  75. commentForm:
  76. '.com-o-CommentForm__opened-textarea,.com-comment-CommentTextarea__textarea',
  77. commentInner:
  78. '.com-tv-CommentBlock__inner, .com-archive-comment-ArchiveCommentItem__message, .com-comment-CommentItem__inner',
  79. commentInnerTs: `.com-archive-comment-ArchiveCommentItem__message:not([data-${sid.toLowerCase()}-user-id])`,
  80. commentList:
  81. '.com-a-OnReachTop > :is(div, ul), .com-comment-CommentList__inner > ul',
  82. commentMessage:
  83. '.com-tv-CommentBlock__message > span, .com-archive-comment-ArchiveCommentItem__message > span, .com-comment-CommentItem__body',
  84. commentReport: `.com-tv-CommentReportForm:not([data-${sid.toLowerCase()}-commentreportform]), .com-archive-comment-ArchiveCommentReportForm:not([data-${sid.toLowerCase()}-commentreportform]), .com-comment-CommentReportForm:not([data-${sid.toLowerCase()}-commentreportform])`,
  85. commentReport2: `.com-tv-CommentReportForm[data-${sid.toLowerCase()}-commentreportform], .com-archive-comment-ArchiveCommentReportForm[data-${sid.toLowerCase()}-commentreportform], .com-comment-CommentReportForm[data-${sid.toLowerCase()}-commentreportform]`,
  86. commentReportCancel:
  87. '.com-tv-CommentReportForm__cancel-button, .com-archive-comment-ArchiveCommentReportForm__cancel-button, .com-comment-CommentReportForm__cancel-button',
  88. commentReportSubmitLe: 'com-comment-CommentReportForm__submit-button',
  89. commentReportSubmitTs:
  90. 'com-archive-comment-ArchiveCommentReportForm__submit-button',
  91. commentReportSubmitTv: 'com-tv-CommentReportForm__submit-button',
  92. commentReportLe: '.com-comment-CommentReportForm',
  93. commentReportTs: '.com-archive-comment-ArchiveCommentReportForm',
  94. commentReportTv: '.com-tv-CommentReportForm',
  95. commentTextarea: '.com-o-CommentForm__opened-textarea',
  96. commentTs: `.com-archive-comment-ArchiveCommentItem:has(.com-archive-comment-ArchiveCommentItem__message:not([data-${sid.toLowerCase()}-user-id]))`,
  97. footer:
  98. '.com-tv-LinearFooter,.com-vod-VideoControlBar,.com-live-event-LiveEventVideoController,.com-vod-LiveEventPayperviewControlBar',
  99. footerVisible:
  100. '.com-tv-TVScreen__footer-container:not(.com-tv-TVScreen__footer-container--hidden),.com-vod-VODScreen-container:not(.com-vod-VODScreen-container--cursor-hidden),.com-live-event-LiveEventPlayerAreaLayout--controllers-visible',
  101. headerMenu: '.com-m-HeaderMenu',
  102. inner: '.c-application-DesktopAppContainer__content',
  103. main: '#main',
  104. mypageMenu: '.com-application-MypageMenu__menu',
  105. nextCancel: '.com-vod-VODNextProgramInfo__cancel-button',
  106. nextCancelMini:
  107. '.com-vod-VODScreenOverlayForMiniPlayer__cancel-next-program-button',
  108. notification: '.com-m-NotificationManager',
  109. notificationClose: '.com-m-Notification__button[aria-label="閉じる"]',
  110. notificationMessage: '.com-m-Notification__message span',
  111. recommendedCancel:
  112. '.com-vod-VODFirstProgramOfRecommendedSeriesInfo__cancel-button',
  113. sideNavi: '.c-application-SideNavigation',
  114. sideNaviColl: 'c-application-SideNavigation--collapsed',
  115. sideNaviWrapColl: 'c-application-SideNavigation__wrapper--collapsed',
  116. sidePanelClose:
  117. '.com-tv-FeedSidePanel__close-button,.com-live-event-LiveEventStatsSidePanel__close,.com-comment-CommentAreaHeader__close-button',
  118. tvScreen: '.com-tv-TVScreen',
  119. video: 'video[src]:not([style*="display: none;"])',
  120. videoContainer: '.com-a-Video__container',
  121. videoDblclick:
  122. '.com-vod-VideoControlBar,.c-vod-EpisodePlayerContainer-ad-container,.c-tv-TimeshiftPlayerContainerView__ad-container,.com-live-event-LiveEventPlayerSectionLayout__player-area',
  123. videoMainPlayer:
  124. '.com-vod-VODMiniPlayerWrapper__player:not(.com-vod-VODMiniPlayerWrapper__player--bg):not(.com-vod-VODMiniPlayerWrapper__player--mini),.com-live-event-LiveEventPlayerAreaLayout__player',
  125. videoSkip: '.com-video_ad-AdSkipButton',
  126. videoSkip2: '.com-video_ad-AdSkipButton:not([disabled])',
  127. },
  128. setting = {
  129. _ngid: [0, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000],
  130. closeNotification: ls.closeNotification,
  131. closeSidePanel: ls.closeSidePanel,
  132. commentFontSize: ls.commentFontSize,
  133. commentFontSizeNum: ls.commentFontSizeNum,
  134. dblclickScroll: ls.dblclickScroll,
  135. enterKey: ls.enterKey,
  136. escKey: ls.escKey,
  137. headerPosition: ls.headerPosition,
  138. hiddenButtonText: ls.hiddenButtonText,
  139. hiddenCommentList: ls.hiddenCommentList,
  140. hiddenCommentListNum: ls.hiddenCommentListNum,
  141. hiddenCommentListNum2: ls.hiddenCommentListNum2,
  142. hiddenIdAndPlan: ls.hiddenIdAndPlan,
  143. highlightFirstComment: ls.highlightFirstComment,
  144. highlightNewComment: ls.highlightNewComment,
  145. mouseoverNavigation: ls.mouseoverNavigation,
  146. newCommentOneByOne: ls.newCommentOneByOne,
  147. nextProgramInfo: ls.nextProgramInfo,
  148. ngConsole: ls.ngConsole,
  149. ngId: lsId.ngId ? [...lsId.ngId] : [],
  150. ngIdEnable: ls.ngIdEnable,
  151. ngIdMaxSize: ls.ngIdMaxSize,
  152. ngWord: lsWord.ngWord,
  153. ngWordEnable: ls.ngWordEnable,
  154. overlapSidePanel: ls.overlapSidePanel,
  155. qualityEnable: ls.qualityEnable,
  156. recommendedSeriesInfo: ls.recommendedSeriesInfo,
  157. reduceCommentSpace: ls.reduceCommentSpace,
  158. reduceNavigation: ls.reduceNavigation,
  159. scrollNewComment: ls.scrollNewComment,
  160. semiTransparent: ls.semiTransparent,
  161. sidePanelBackground: ls.sidePanelBackground,
  162. sidePanelCloseButton: ls.sidePanelCloseButton,
  163. sidePanelSize: ls.sidePanelSize,
  164. sidePanelSizeNum: ls.sidePanelSizeNum,
  165. showProgramDetail: ls.showProgramDetail,
  166. skipVideo: ls.skipVideo,
  167. smallFontSize: ls.smallFontSize,
  168. stopCommentScroll: ls.stopCommentScroll,
  169. targetQuality: ls.targetQuality,
  170. videoPadding: ls.videoPadding,
  171. videoResolution: ls.videoResolution,
  172. viewCounter: ls.viewCounter,
  173. reportFormCommentList: ls.reportFormCommentList,
  174. },
  175. video = {
  176. clientHeight: 0,
  177. clientWidth: 0,
  178. pixelRatio: 0,
  179. src: '',
  180. videoHeight: 0,
  181. videoWidth: 0,
  182. };
  183.  
  184. /**
  185. * NG IDを追加する
  186. */
  187. const addNgId = () => {
  188. log('addNgId');
  189. clearInterval(interval.newcomment);
  190. const blocked = checkBlockedUser(false);
  191. if (
  192. blocked >= 100 &&
  193. setting.ngIdMaxSize &&
  194. setting._ngid[setting.ngIdMaxSize] > data.ngId.size &&
  195. data.blockedUserId &&
  196. !data.ngId.has(data.blockedUserId)
  197. ) {
  198. setting.ngId.push(data.blockedUserId);
  199. lsId.ngId.push(data.blockedUserId);
  200. data.ngId.add(data.blockedUserId);
  201. log('addNgId', data.blockedUserId, data.ngId.size);
  202. saveStorage();
  203. setTimeout(() => {
  204. checkBlockedUser(true);
  205. }, 1000);
  206. } else {
  207. log(
  208. 'not add NGiD',
  209. blocked,
  210. setting.ngIdMaxSize,
  211. setting._ngid[setting.ngIdMaxSize],
  212. data.ngId.size,
  213. data.blockedUserId,
  214. data.ngId.has(data.blockedUserId)
  215. );
  216. }
  217. };
  218.  
  219. /**
  220. * スタイルを追加
  221. * @param {string} s
  222. */
  223. const addStyle = (s) => {
  224. const init = `
  225. :is(.com-tv-CommentBlock, .com-comment-CommentItem):has(> div[data-${sid.toLowerCase()}-hidden="true"]),
  226. .com-archive-comment-ArchiveCommentItem:has(> p[data-${sid.toLowerCase()}-hidden="true"]),
  227. :is(.com-tv-CommentBlock, .com-comment-CommentItem):has(> div[data-${sid.toLowerCase()}-ngword]),
  228. .com-archive-comment-ArchiveCommentItem:has(> p[data-${sid.toLowerCase()}-ngword]),
  229. :is(.com-tv-CommentBlock, .com-comment-CommentItem):has(> div[data-${sid.toLowerCase()}-ngid]),
  230. .com-archive-comment-ArchiveCommentItem:has(> p[data-${sid.toLowerCase()}-ngid]),
  231. .${sid}_Settings_hidden,
  232. .${sid}_Settings-tab-switch {
  233. display: none;
  234. }
  235. #${sid}_Settings {
  236. background-color: #F9FCFF;
  237. border: 2px solid #CCCCCC;
  238. border-radius: 8px;
  239. box-shadow: 4px 4px 16px rgba(0,0,0,0.5);
  240. color: black;
  241. left: 20px;
  242. max-height: calc(100vh - 40px);
  243. max-width: calc(100vw - 40px);
  244. min-width: 45em;
  245. overflow: auto;
  246. padding: 8px;
  247. position: fixed;
  248. top: 20px;
  249. user-select: none;
  250. width: min-content;
  251. z-index: 9900;
  252. }
  253. #${sid}_Settings label[title] {
  254. cursor: help;
  255. }
  256. #main:has(.c-tv-NowOnAirContainer__side-panel--shown) ~ #${sid}_Settings {
  257. max-width: calc(100vw - 460px);
  258. }
  259. #${sid}_Settings-header {
  260. text-align: center;
  261. }
  262. #${sid}_Settings-main fieldset {
  263. border: 1px solid #CCCCCC;
  264. margin: 2px 0;
  265. padding: 4px 8px;
  266. }
  267. #${sid}_Settings-main fieldset + label {
  268. margin-top: 2px;
  269. }
  270. #${sid}_Settings-main fieldset + fieldset {
  271. margin-top: 10px;
  272. }
  273. #${sid}_Settings-main pre {
  274. background-color: #FFFFEE;
  275. border: 1px solid #DDDDDD;
  276. margin-left: 1em;
  277. padding: 4px;
  278. user-select: text;
  279. width: min-content;
  280. }
  281. #${sid}_Settings-main :is(label, details):not(.${sid}_Settings-tab-label) {
  282. display: inline-block;
  283. width: 100%;
  284. }
  285. #${sid}_Settings-main :is(label, details):not(.${sid}_Settings-tab-label):hover {
  286. background-color: #E3ECF6;
  287. }
  288. #${sid}_Settings-main details {
  289. transition: 0.5s;
  290. }
  291. #${sid}_Settings-main input[type="checkbox"] {
  292. position: relative;
  293. top: 2px;
  294. margin-right: 4px;
  295. }
  296. #${sid}_Settings-main summary {
  297. cursor: pointer;
  298. display: list-item;
  299. }
  300. #${sid}_Settings-main summary::before {
  301. background: #88AA88;
  302. border-radius: 50%;
  303. color: #FFFFFF;
  304. content: "?";
  305. display: inline-block;
  306. font-size: 85%;
  307. font-weight: bold;
  308. height: 1.5em;
  309. line-height: 1.5;
  310. margin-right: 4px;
  311. text-align: center;
  312. vertical-align: 2px;
  313. width: 1.5em;
  314. }
  315. #${sid}_Settings-main select {
  316. appearance: auto;
  317. cursor: pointer;
  318. margin-top: 8px;
  319. padding: 4px 8px;
  320. }
  321. #${sid}_Settings-main input + input,
  322. #${sid}_Settings-main input + input + input,
  323. #${sid}_Settings-main legend:has(input),
  324. #${sid}_Settings-main legend:has(input) ~ label {
  325. color: gray;
  326. }
  327. #${sid}_Settings-main input:checked + input,
  328. #${sid}_Settings-main input:checked + input + input,
  329. #${sid}_Settings-main legend:has(input:checked),
  330. #${sid}_Settings-main legend:has(input:checked) ~ label {
  331. color: black;
  332. }
  333. #${sid}_Settings-commentFontSizeNum {
  334. text-align: center;
  335. width: 3.5em;
  336. }
  337. #${sid}_Settings-hiddenCommentListNum,
  338. #${sid}_Settings-hiddenCommentListNum2 {
  339. text-align: center;
  340. width: 4em;
  341. }
  342. #${sid}_Settings-sidePanelSizeNum {
  343. text-align: center;
  344. width: 5em;
  345. }
  346. #${sid}_Settings input[type="number"],
  347. #${sid}_Settings select {
  348. margin-left: 8px;
  349. margin-right: 2px;
  350. }
  351. #${sid}_Settings-main input + input,
  352. #${sid}_Settings-main input + input + input,
  353. legend:has(input) ~ label #${sid}_Settings-targetQuality,
  354. legend:has(input) ~ #${sid}_Settings-ngWord,
  355. legend:has(input) ~ label #${sid}_Settings-ngIdMaxSize {
  356. background-color: #DDDDDD;
  357. }
  358. #${sid}_Settings-main input:checked + input,
  359. #${sid}_Settings-main input:checked + input + input,
  360. legend:has(input:checked) ~ label #${sid}_Settings-targetQuality,
  361. legend:has(input:checked) ~ #${sid}_Settings-ngWord,
  362. legend:has(input:checked) ~ label #${sid}_Settings-ngIdMaxSize {
  363. background-color: white;
  364. }
  365. #${sid}_Settings-ngWord {
  366. height: 6em;
  367. margin-top: 8px;
  368. max-width: calc(100vw - 118px);
  369. min-height: 6em;
  370. min-width: 40em;
  371. width: 100%;
  372. }
  373. #${sid}_Settings-ngWord-error {
  374. display: none;
  375. margin-bottom: 4px;
  376. }
  377. #${sid}_Settings-ngWord-error p {
  378. color: red;
  379. }
  380. #${sid}_Settings-ngWord-error pre {
  381. font-weight: bold;
  382. margin-top: 4px;
  383. padding: 4px 8px;
  384. }
  385. #${sid}_Settings-ngIdMaxSize {
  386. text-align: right;
  387. }
  388. #${sid}_Settings-ngId-record {
  389. margin-left: 1em;
  390. }
  391. #${sid}_Settings-footer {
  392. text-align: right;
  393. }
  394. #${sid}_Settings-footer button {
  395. border: 1px solid gray;
  396. border-radius: 4px;
  397. margin: 8px;
  398. padding: 4px;
  399. width: 8em;
  400. }
  401. #${sid}_Settings-ok {
  402. background-color: #EEEEEE;
  403. }
  404. #${sid}_Settings-cancel {
  405. background-color: #EEEEEE;
  406. }
  407. #${sid}_Settings-main {
  408. display: flex;
  409. flex-wrap: wrap;
  410. margin: 8px 0;
  411. }
  412. #${sid}_Settings-main:after {
  413. background: #8899aa;
  414. content: '';
  415. display: block;
  416. height: 1px;
  417. order: -1;
  418. width: 100%;
  419. }
  420. .${sid}_Settings-tab-label {
  421. background: #BCBCBC;
  422. border-radius: 4px 4px 0 0;
  423. color: White;
  424. cursor: pointer;
  425. flex: 1;
  426. font-weight: bold;
  427. order: -1;
  428. padding: 2px 4px;
  429. position: relative;
  430. text-align: center;
  431. text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);
  432. white-space: nowrap;
  433. z-index: 1;
  434. }
  435. .${sid}_Settings-tab-label:not(:last-of-type) {
  436. margin-right: 5px;
  437. }
  438. .${sid}_Settings-tab-content {
  439. height: 0;
  440. opacity: 0;
  441. overflow: hidden;
  442. width: 100%;
  443. }
  444. .${sid}_Settings-tab-switch:checked + .${sid}_Settings-tab-label {
  445. background: #8899aa;
  446. }
  447. .${sid}_Settings-tab-switch:checked + .${sid}_Settings-tab-label + .${sid}_Settings-tab-content {
  448. box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
  449. height: auto;
  450. opacity: 1;
  451. overflow: auto;
  452. padding: 8px;
  453. transition: .5s opacity;
  454. }
  455. #${sid}_CommentReportForm-NgComment {
  456. color: #E6E6E6;
  457. font-size: 13px;
  458. margin-top: 12px;
  459. }
  460. #${sid}_CommentReportForm-NgCommentHeader {
  461. font-size: 12px;
  462. }
  463. #${sid}_CommentReportForm-NgCommentList {
  464. background-color: #333333;
  465. margin-top: 4px;
  466. padding: 8px 4px;
  467. }
  468. #${sid}_CommentReportForm-NgCommentList p + p {
  469. margin-top: 0.8em;
  470. }
  471. #${sid}_VideoResolution {
  472. background: linear-gradient(180deg, rgba(0, 0, 0, 0.2), #000000);
  473. bottom: 0px;
  474. color: #ccc;
  475. display: none;
  476. font-size: 12px;
  477. height: 16px;
  478. left: 155px;
  479. padding: 0 2px;
  480. position: absolute;
  481. user-select: none;
  482. white-space: nowrap;
  483. }
  484. `,
  485. overlapSidePanel = `
  486. /*右側のサイドパネルを動画に重ねて表示する*/
  487. .c-tv-NowOnAirContainer__screen--with-side-panel,
  488. .com-vod-VODResponsiveMainContent--wide-mode .c-tv-TimeshiftPlayerContainerView-screen {
  489. width: 100vw !important;
  490. }
  491. .com-tv-TVScreen__player {
  492. height: 100vh !important;
  493. }
  494. .com-a-Text--info.com-a-Text--dark,
  495. .com-a-Text--info.com-a-Text--light {
  496. color: #DDDDDD !important;
  497. }
  498. .com-tv-CommentBlock,
  499. .com-tv-FeedProgramDetailContainerView__contents :is(h2, h3, h2+p, h3+p, dd),
  500. .com-tv-FeedProgramDetailContainerView__contents span:not(.com-tv-FeedProgramDetailExternalLink__button-text),
  501. .com-tv-FeedSidePanel__close-button-text,
  502. .com-comment-CommentItem__body,
  503. .com-archive-comment-ArchiveCommentHead__count > span,
  504. .com-archive-comment-ArchiveCommentItem__message > span {
  505. text-shadow:
  506. -1px -1px 1px black, -1px 0px 1px black, -1px 1px 1px black,
  507. 0px -1px 1px black, 0px 1px 1px black,
  508. 1px -1px 1px black, 1px 0px 1px black, 1px 1px 1px black !important;
  509. }
  510. .com-tv-CommentBlock__message > span,
  511. .com-comment-CommentItem__body,
  512. .com-archive-comment-ArchiveCommentHead__count > span,
  513. .com-archive-comment-ArchiveCommentItem__message > span {
  514. color: white !important;
  515. }
  516. .c-tv-NowOnAirContainer__side-panel,
  517. .com-tv-CommentArea,
  518. .com-tv-CommentArea__comment-form,
  519. .com-tv-CommentBlock,
  520. .com-tv-FeedProgramDetailContainerView__contents,
  521. .com-tv-FeedSidePanel__header,
  522. .com-comment-CommentContainerView,
  523. .com-live-event-LiveEventStatsSidePanel,
  524. .c-tv-TimeshiftPlayerContainerView__comment,
  525. .com-archive-comment-ArchiveCommentItem,
  526. .c-archive-comment-ArchiveCommentContainerView__no-input {
  527. background-color: rgba(0, 0, 0, 0) !important;
  528. }
  529. .com-tv-CommentBlock__inner:hover,
  530. .com-comment-TwitterSigninButton:hover,
  531. .com-comment-CommentItem__inner:hover,
  532. .com-archive-comment-ArchiveCommentItem:hover {
  533. background-color: rgba(0, 0, 0, 0.3) !important;
  534. }
  535. .com-tv-CommentBlock__time {
  536. opacity: 0.6 !important;
  537. }
  538. .c-tv-NowOnAirContainer__screen--with-side-panel .com-tv-TVScreen__footer-container {
  539. padding-right: ${
  540. setting.sidePanelSize ? setting.sidePanelSizeNum : '320'
  541. }px !important;
  542. }
  543. .com-o-CommentForm__can-post .com-o-CommentForm__opened-textarea-wrapper,
  544. .com-comment-CommentTextarea__textarea {
  545. background-color: rgba(255, 255, 255, 0.2) !important;
  546. }
  547. .com-o-CommentForm__can-post .com-o-CommentForm__opened-textarea:focus,
  548. .com-comment-CommentTextarea__textarea:focus {
  549. background-color: rgba(255, 255, 255, 0.8) !important;
  550. }
  551. .com-o-CommentForm__opened-textarea-wrapper {
  552. background-color: rgba(0, 0, 0, 0.2) !important;
  553. }
  554. .com-o-CommentForm__twitter-button,
  555. .com-comment-TwitterSigninButton,
  556. .com-comment-TwitterSignoutButton,
  557. .com-comment-CommentAreaHeader__comment-count {
  558. opacity: 0.2 !important;
  559. }
  560. .com-o-CommentForm__twitter-button:hover,
  561. .com-comment-TwitterSigninButton:hover,
  562. .com-comment-TwitterSignoutButton:hover,
  563. .com-comment-CommentAreaHeader__comment-count:hover {
  564. opacity: 1 !important;
  565. }
  566. .com-tv-FeedSidePanel__contents {
  567. height: 98% !important;
  568. }
  569. .com-a-Button--primary,
  570. .com-comment-CommentSubmitButton {
  571. background-color: rgba(221, 170, 0, 0.5) !important;
  572. }
  573. .com-a-Button--primary:hover:not([disabled]),
  574. .com-comment-CommentSubmitButton:hover:not([disabled]) {
  575. background-color: rgba(221, 170, 0, 1) !important;
  576. }
  577. .c-tv-NowOnAirContainer__screen--with-side-panel :is(
  578. .com-tv-SlotMyListButtonOnPlayerContainerView,
  579. .com-tv-TVScreen__ad-link-button
  580. ) {
  581. bottom: 124px !important;
  582. right: ${
  583. setting.sidePanelSize ? setting.sidePanelSizeNum : '320'
  584. }px !important;
  585. transform: translateX(500px) !important;
  586. }
  587. .com-tv-SlotMyListButtonOnPlayerContainerView--shown,
  588. .com-tv-TVScreen__ad-link-button--shown {
  589. transform: translateX(0) !important;
  590. }
  591. .c-tv-NowOnAirContainer__screen--with-side-panel .c-tv-NowOnAirContainer__remote-controller,
  592. .com-question-QuestionContainerView,
  593. .com-vod-VODResponsiveMainContent--with-side-panel .com-live-event-LiveEventOverlayControllerLayout__bottom-buttons {
  594. right: ${
  595. setting.sidePanelSize ? setting.sidePanelSizeNum : '320'
  596. }px !important;
  597. }
  598. .com-vod-VODResponsiveMainContent--with-side-panel .com-vod-LiveEventPayperviewControlBar {
  599. margin-right: ${
  600. setting.sidePanelSize ? setting.sidePanelSizeNum : '320'
  601. }px !important;
  602. }
  603. .com-tv-FeedProgramDetailCommentCounter,
  604. .com-tv-FeedProgramDetailHeader__date,
  605. .com-tv-FeedProgramDetailViewCounter {
  606. color: #CCCCCC !important;
  607. }
  608. .com-live-event-LiveEventPlayerSectionLayout__side-panel {
  609. height: calc(100vh - 10px);
  610. position: absolute;
  611. right: 0;
  612. }
  613. .com-comment-CommentAreaHeader__close-button:hover {
  614. color: #FFFFFF;
  615. }
  616. .com-o-CommentForm__opened-textarea:focus::placeholder {
  617. color: black;
  618. }
  619. .c-tv-TimeshiftPlayerContainerView__comment-wrapper {
  620. z-index: 20;
  621. }
  622. .c-tv-TimeshiftPlayerContainerView--has-comment .com-vod-VODScreen-video-control {
  623. margin: 0 !important;
  624. width: calc(100vw - 320px);
  625. z-index: 30;
  626. }
  627. .c-tv-TimeshiftPlayerContainerView__comment:hover .com-archive-comment-ArchiveCommentHead__close {
  628. background-color: rgba(0, 0, 0, 0.3);
  629. color: white !important;
  630. }
  631. .c-archive-comment-ArchiveCommentContainerView__body-waiting-show {
  632. opacity: 0 !important;
  633. }
  634. .c-archive-comment-ArchiveCommentContainerView__body-waiting-show + .c-archive-comment-ArchiveCommentContainerView__list-wrapper {
  635. opacity: 0.5;
  636. }
  637. `,
  638. highlightNewComment = `
  639. /*新規コメントと自分のコメントを強調表示する*/
  640. .com-tv-CommentBlock__inner--active,
  641. .com-archive-comment-ArchiveCommentItem__is-active,
  642. .com-tv-CommentBlock--new,
  643. .com-comment-CommentItem[data-${sid.toLowerCase()}-Own] .com-comment-CommentItem__body,
  644. .com-comment-CommentItem__inner[data-${sid.toLowerCase()}-Own] .com-comment-CommentItem__body {
  645. text-shadow:
  646. -1px -1px 1px black, -1px 0px 1px black, -1px 1px 1px black,
  647. 0px -1px 1px black, 0px 1px 1px black,
  648. 1px -1px 1px black, 1px 0px 1px black, 1px 1px 1px black,
  649. -2px -2px 1px rgba(255,165,0,0.3), -2px 0px 1px rgba(255,165,0,0.3), -2px 2px 1px rgba(255,165,0,0.3),
  650. 0px -2px 1px rgba(255,165,0,0.3), 0px 2px 1px rgba(255,165,0,0.3),
  651. 2px -2px 1px rgba(255,165,0,0.3), 2px 0px 1px rgba(255,165,0,0.3), 2px 2px 1px rgba(255,165,0,0.3) !important;
  652. }
  653. .com-tv-CommentBlock__inner--active,
  654. .com-archive-comment-ArchiveCommentItem__is-active,
  655. .com-comment-CommentItem[data-${sid.toLowerCase()}-Own],
  656. .com-comment-CommentItem__inner[data-${sid.toLowerCase()}-Own] {
  657. background-color: rgba(128,83,0,0.3) !important;
  658. }
  659. /*
  660. .com-tv-CommentBlock:not(.com-tv-CommentBlock--new) + .com-tv-CommentBlock--new {
  661. border-top: 4px dotted rgba(255,165,0,0.4) !important;
  662. }
  663. */
  664. `,
  665. highlightFirstComment = `
  666. /*初回コメントと連投コメントを強調表示する*/
  667. .com-tv-CommentBlock__inner[data-${sid.toLowerCase()}-Green],
  668. .com-comment-CommentItem__inner[data-${sid.toLowerCase()}-Green] .com-comment-CommentItem__body,
  669. .com-archive-comment-ArchiveCommentItem__message[data-${sid.toLowerCase()}-Green] span {
  670. text-shadow:
  671. -1px -1px 1px black, -1px 0px 1px black, -1px 1px 1px black,
  672. 0px -1px 1px black, 0px 1px 1px black,
  673. 1px -1px 1px black, 1px 0px 1px black, 1px 1px 1px black,
  674. -2px -2px 1px rgba(0,192,0,0.6), -2px 0px 1px rgba(0,192,0,0.6), -2px 2px 1px rgba(0,192,0,0.6),
  675. 0px -2px 1px rgba(0,192,0,0.6), 0px 2px 1px rgba(0,192,0,0.6),
  676. 2px -2px 1px rgba(0,192,0,0.6), 2px 0px 1px rgba(0,192,0,0.6), 2px 2px 1px rgba(0,192,0,0.6) !important;
  677. }
  678. .com-tv-CommentBlock__inner[data-${sid.toLowerCase()}-Purple],
  679. .com-comment-CommentItem__inner[data-${sid.toLowerCase()}-Purple] .com-comment-CommentItem__body,
  680. .com-archive-comment-ArchiveCommentItem__message[data-${sid.toLowerCase()}-Purple] span {
  681. text-shadow:
  682. -1px -1px 1px black, -1px 0px 1px black, -1px 1px 1px black,
  683. 0px -1px 1px black, 0px 1px 1px black,
  684. 1px -1px 1px black, 1px 0px 1px black, 1px 1px 1px black,
  685. -2px -2px 1px rgba(192,96,192,0.6), -2px 0px 1px rgba(192,96,192,0.6), -2px 2px 1px rgba(192,96,192,0.6),
  686. 0px -2px 1px rgba(192,96,192,0.6), 0px 2px 1px rgba(192,96,192,0.6),
  687. 2px -2px 1px rgba(192,96,192,0.6), 2px 0px 1px rgba(192,96,192,0.6), 2px 2px 1px rgba(192,96,192,0.6) !important;
  688. }
  689. .com-tv-CommentBlock__inner[data-${sid.toLowerCase()}-Red],
  690. .com-comment-CommentItem__inner[data-${sid.toLowerCase()}-Red] .com-comment-CommentItem__body,
  691. .com-archive-comment-ArchiveCommentItem__message[data-${sid.toLowerCase()}-Red] span {
  692. text-shadow:
  693. -1px -1px 1px black, -1px 0px 1px black, -1px 1px 1px black,
  694. 0px -1px 1px black, 0px 1px 1px black,
  695. 1px -1px 1px black, 1px 0px 1px black, 1px 1px 1px black,
  696. -2px -2px 1px rgba(255,0,0,0.8), -2px 0px 1px rgba(255,0,0,0.8), -2px 2px 1px rgba(255,0,0,0.8),
  697. 0px -2px 1px rgba(255,0,0,0.8), 0px 2px 1px rgba(255,0,0,0.8),
  698. 2px -2px 1px rgba(255,0,0,0.8), 2px 0px 1px rgba(255,0,0,0.8), 2px 2px 1px rgba(255,0,0,0.8) !important;
  699. }
  700. .com-tv-CommentBlock__inner[data-${sid.toLowerCase()}-Yellow],
  701. .com-comment-CommentItem__inner[data-${sid.toLowerCase()}-Yellow] .com-comment-CommentItem__body,
  702. .com-archive-comment-ArchiveCommentItem__message[data-${sid.toLowerCase()}-Yellow] span {
  703. text-shadow:
  704. -1px -1px 1px black, -1px 0px 1px black, -1px 1px 1px black,
  705. 0px -1px 1px black, 0px 1px 1px black,
  706. 1px -1px 1px black, 1px 0px 1px black, 1px 1px 1px black,
  707. -2px -2px 1px rgba(224,224,0,0.8), -2px 0px 1px rgba(224,224,0,0.8), -2px 2px 1px rgba(224,224,0,0.8),
  708. 0px -2px 1px rgba(224,224,0,0.8), 0px 2px 1px rgba(224,224,0,0.8),
  709. 2px -2px 1px rgba(224,224,0,0.8), 2px 0px 1px rgba(224,224,0,0.8), 2px 2px 1px rgba(224,224,0,0.8) !important;
  710. }
  711. `,
  712. commentFontSize = `
  713. /*コメントの文字サイズを変更する*/
  714. .com-tv-CommentBlock__message > span,
  715. .com-comment-CommentItem__body,
  716. .com-archive-comment-ArchiveCommentItem__message > span {
  717. font-size: ${setting.commentFontSizeNum}px !important;
  718. }
  719. `,
  720. reduceCommentSpace = `
  721. /*コメントの余白を減らす&行間を狭める*/
  722. .com-tv-CommentBlock__inner,
  723. .com-archive-comment-ArchiveCommentItem {
  724. padding: 2px 4px !important;
  725. }
  726. .com-comment-CommentItem__body {
  727. padding: 4px 0 !important;
  728. }
  729. .com-comment-CommentItem__body-sub-wrapper {
  730. padding: 0 4px !important;
  731. }
  732. .com-comment-CommentItem__sub {
  733. width: auto !important;
  734. }
  735. `,
  736. sidePanelCloseButton = `
  737. /*サイドパネル上端にマウスカーソルを近づけたとき閉じるボタンを表示*/
  738. .com-tv-FeedSidePanel__close-button {
  739. background-color: rgba(64,64,64,0.8) !important;
  740. }
  741. .com-tv-FeedSidePanel__contents {
  742. transform: translateY(10px) !important;
  743. }
  744. .com-tv-FeedSidePanel__header {
  745. position: absolute !important;
  746. transform: translateY(-58px) !important;
  747. transition: transform 0.2s !important;
  748. z-index: 99 !important;
  749. }
  750. .com-tv-FeedSidePanel__header:hover {
  751. transform: translateY(0px) !important;
  752. }
  753. `,
  754. sidePanelSize = `
  755. /*サイドパネルの幅を変更する*/
  756. .c-tv-NowOnAirContainer__side-panel,
  757. .com-tv-FeedSidePanel,
  758. .com-live-event-LiveEventPlayerSectionLayout__side-panel,
  759. .c-tv-TimeshiftPlayerContainerView--has-comment .c-tv-TimeshiftPlayerContainerView__comment-wrapper,
  760. .c-tv-TimeshiftPlayerContainerView__comment {
  761. width: ${
  762. setting.sidePanelSize ? setting.sidePanelSizeNum : '320'
  763. }px !important;
  764. }
  765. .com-application-Header--shrunk,
  766. .c-common-HeaderContainer-header--shrunk {
  767. width: calc(100% - ${
  768. setting.sidePanelSize ? setting.sidePanelSizeNum : '320'
  769. }px) !important;
  770. }
  771. `,
  772. showProgramDetail = `
  773. /*サイドパネルに記載された番組情報の詳細を常に表示する*/
  774. .com-tv-FeedSidePanel__contents #com-vod-VODDetailsAccordion__details {
  775. height: auto !important;
  776. }
  777. .com-tv-FeedSidePanel__contents .com-vod-VODDetailsAccordion__details--collapsed {
  778. visibility: visible !important;
  779. }
  780. .com-tv-FeedSidePanel__contents .com-vod-VODDetailsAccordion__toggle-collapsed-details-button-paragraph {
  781. display: none !important;
  782. }
  783. `,
  784. hiddenButtonText = `
  785. /*最初から見る・番組情報・コメントボタンのテキストを隠す*/
  786. .com-tv-LinearFooterChasePlayButton,
  787. .com-tv-LinearFooterProgramDetailButton,
  788. .com-tv-LinearFooterCommentButton {
  789. transition: all 0.2s !important;
  790. width: 44px !important;
  791. }
  792. .com-tv-LinearFooterChasePlayButton:hover:not(.com-tv-LinearFooterChasePlayButton--shrunk) {
  793. width: 132px !important;
  794. }
  795. .com-tv-LinearFooterProgramDetailButton:hover:not(.com-tv-LinearFooterProgramDetailButton--shrunk),
  796. .com-tv-LinearFooterCommentButton:hover:not(.com-tv-LinearFooterCommentButton--shrunk) {
  797. width: 100px !important;
  798. }
  799. .com-tv-LinearFooterChasePlayButton__text,
  800. .com-tv-LinearFooterProgramDetailButton__text,
  801. .com-tv-LinearFooterCommentButton__text {
  802. overflow: hidden;
  803. white-space: nowrap;
  804. width: 0;
  805. }
  806. .com-tv-LinearFooterChasePlayButton:hover .com-tv-LinearFooterChasePlayButton__text,
  807. .com-tv-LinearFooterProgramDetailButton:hover .com-tv-LinearFooterProgramDetailButton__text,
  808. .com-tv-LinearFooterCommentButton:hover .com-tv-LinearFooterCommentButton__text {
  809. width: auto;
  810. }
  811. `,
  812. hiddenCommentList = `
  813. /*コメントリストを半透明化*/
  814. .com-a-OnReachTop, .com-comment-CommentList__inner {
  815. opacity: ${Number(setting.hiddenCommentListNum) / 100};
  816. }
  817. `,
  818. hiddenCommentList2 = `
  819. /*コメントリストを半透明化2*/
  820. .com-a-OnReachTop, .com-comment-CommentList__inner {
  821. opacity: ${Number(setting.hiddenCommentListNum2) / 100};
  822. }
  823. `,
  824. videoResolution = `
  825. #${sid}_VideoResolution {
  826. display: block;
  827. }
  828. `,
  829. semiTransparent = `
  830. /*ヘッダーやサイドナビゲーションなどを半透明にする*/
  831. .com-application-Header,
  832. .com-application-Header:before {
  833. background: linear-gradient(0deg, rgba(0, 0, 0, 0.2), #000000) !important;
  834. }
  835. .com-InputText__input--dark-strong:not(:focus),
  836. .com-live-event-LiveEventOverlayControllerLayout__bottom-buttons .com-a-Button--dark:not(:hover) {
  837. background: rgba(33, 33, 33, 0.2) !important;
  838. }
  839. .c-application-SideNavigation__wrapper {
  840. background-color: rgba(0, 0, 0, 0.2) !important;
  841. background-image: linear-gradient(270deg,transparent, #000) !important;
  842. }
  843. .c-application-SideNavigation__footer {
  844. background-color: rgba(0, 0, 0, 0) !important;
  845. }
  846. .com-tv-LinearFooter__button button {
  847. background-color: rgba(0, 0, 0, 0.2) !important;
  848. }
  849. .c-application-SideNavigation__wrapper:hover,
  850. .com-tv-LinearFooter__button button:hover {
  851. background-color: rgba(0, 0, 0, 0.8) !important;
  852. }
  853. .com-tv-LinearChannelSwitcher__button {
  854. opacity: 0.5 !important;
  855. }
  856. .com-playback-Volume__icon {
  857. opacity: 0.8 !important;
  858. }
  859. .com-tv-LinearChannelSwitcher__button:hover,
  860. .com-playback-Volume__icon:hover {
  861. opacity: 1 !important;
  862. }
  863. .com-tv-RemoteController__button:hover {
  864. border: 2px outset #555555 !important;
  865. }
  866. .com-a-Tooltip {
  867. background-color: rgba(33, 33, 33, 0.5) !important;
  868. }
  869. .com-question-QuestionContainerView .com-question-VoteContent {
  870. background-color: rgba(23, 23, 23, 0.6) !important;
  871. }
  872. .com-question-QuestionContainerView .com-question-VoteContent:hover {
  873. background-color: rgba(23, 23, 23, 1) !important;
  874. }
  875. .com-question-VoteButton:hover:not(.com-question-VoteButton--highest) {
  876. background-color: #171717 !important;
  877. }
  878. `,
  879. smallFontSize = `
  880. /*ヘッダーやフッターの一部の文字サイズを小さくする*/
  881. .com-InputText__input {
  882. font-size: 14px !important;
  883. }
  884. .com-tv-LinearFooter__feed-super {
  885. font-size: 16px !important;
  886. }
  887. `,
  888. headerPosition = `
  889. /*ヘッダーを追従表示にする*/
  890. body:not(.com-timetable-TimeTable__body-timetable) :is(.c-common-HeaderContainer-header, .com-application-Header:not(.com-application-Header--shrunk)) {
  891. position: relative !important;
  892. }
  893. body:not(.com-timetable-TimeTable__body-timetable) .c-application-SideNavigation__wrapper {
  894. padding-top: 0 !important;
  895. }
  896. .com-a-ResponsiveMainContent {
  897. margin-top: 0 !important;
  898. }
  899. .c-application-SideNavigation__wrapper {
  900. height: calc(100vh - 68px) !important;
  901. }
  902. #main:has(.com-application-Header--scrolled) .c-application-SideNavigation__wrapper {
  903. height: 100vh !important;
  904. top: 0;
  905. }
  906. `,
  907. videoPadding = `
  908. /*動画周辺の余白を減らす*/
  909. html:has(.com-vod-VODResponsiveMainContent--wide-mode) {
  910. scrollbar-width: none;
  911. }
  912. .com-vod-VODResponsiveMainContent {
  913. margin: 0 !important;
  914. padding: 0 !important;
  915. }
  916. .com-vod-VODResponsiveMainContent .com-m-BreadcrumbList {
  917. padding: 7px 0;
  918. }
  919. .com-vod-VODResponsiveMainContent__inner {
  920. max-width: none !important;
  921. }
  922. .c-application-DesktopAppContainer__content-container:has(.com-vod-VODResponsiveMainContent--wide-mode) > :is(.c-application-SideNavigation--collapsed, .c-application-SideNavigation__wrapper--collapsed) {
  923. width: 0 !important;
  924. }
  925. `,
  926. mouseoverNavigation = `
  927. /*左端にマウスオーバーしたときサイドナビゲーションを表示する*/
  928. .c-application-SideNavigation--collapsed,
  929. .c-application-SideNavigation__wrapper--collapsed {
  930. width: 16px !important;
  931. }
  932. .c-application-SideNavigation--collapsed:not(:hover) {
  933. opacity: 0 !important;
  934. }
  935. .com-tv-TVScreen__footer-container--sidenav-collapsed {
  936. padding-left: 0 !important;
  937. }
  938. .com-timetable-DesktopTimeTableWrapper__channel-content-header-wrapper--side-navigation-collapsed,
  939. .com-timetable-TimeTableListTimeAxis--is-collapsed-side-navigation {
  940. left: 8px !important;
  941. }
  942. .c-application-DesktopAppContainer__content:has(.com-live-event-LiveEventPlayerSectionLayout__player-area) {
  943. left: 0;
  944. position: absolute;
  945. }
  946. `,
  947. sidePanelBackground = `
  948. /*サイドパネルの背景を半透明にする*/
  949. .c-tv-NowOnAirContainer__side-panel,
  950. .com-live-event-LiveEventPlayerSectionLayout__side-panel,
  951. .c-tv-TimeshiftPlayerContainerView__comment {
  952. background-color: rgba(0, 0, 0, 0.5) !important;
  953. }
  954. `,
  955. hiddenIdAndPlan = `
  956. /*サイドナビゲーションのIDと視聴プランを隠す*/
  957. .com-application-SideNavigationAccountItem__info-item {
  958. display: none !important;
  959. }
  960. `,
  961. style = document.createElement('style');
  962. if (s === 'init') {
  963. style.textContent = init;
  964. } else if (s === 'highlightFirstComment') {
  965. style.textContent = highlightFirstComment;
  966. } else if (s === 'highlightNewComment') {
  967. style.textContent = highlightNewComment;
  968. } else if (s === 'overlapSidePanel') {
  969. style.textContent = overlapSidePanel;
  970. } else if (s === 'commentFontSize') {
  971. style.textContent = commentFontSize;
  972. } else if (s === 'reduceCommentSpace') {
  973. style.textContent = reduceCommentSpace;
  974. } else if (s === 'sidePanelCloseButton') {
  975. style.textContent = sidePanelCloseButton;
  976. } else if (s === 'showProgramDetail') {
  977. style.textContent = showProgramDetail;
  978. } else if (s === 'sidePanelSize') {
  979. style.textContent = sidePanelSize;
  980. } else if (s === 'hiddenButtonText') {
  981. style.textContent = hiddenButtonText;
  982. } else if (s === 'videoResolution') {
  983. style.textContent = videoResolution;
  984. } else if (s === 'semiTransparent') {
  985. style.textContent = semiTransparent;
  986. } else if (s === 'smallFontSize') {
  987. style.textContent = smallFontSize;
  988. } else if (s === 'headerPosition') {
  989. style.textContent = headerPosition;
  990. } else if (s === 'videoPadding') {
  991. style.textContent = videoPadding;
  992. } else if (s === 'mouseoverNavigation') {
  993. style.textContent = mouseoverNavigation;
  994. } else if (s === 'hiddenCommentList') {
  995. style.textContent = hiddenCommentList;
  996. } else if (s === 'hiddenCommentList2') {
  997. style.textContent = hiddenCommentList2;
  998. } else if (s === 'sidePanelBackground') {
  999. style.textContent = sidePanelBackground;
  1000. } else if (s === 'hiddenIdAndPlan') {
  1001. style.textContent = hiddenIdAndPlan;
  1002. }
  1003. style.id = `${sid}_style_${s}`;
  1004. document.head.appendChild(style);
  1005. };
  1006.  
  1007. /**
  1008. * 動画を構成している要素に変更があったとき
  1009. */
  1010. const changeElements = () => {
  1011. const content = returnContentType();
  1012. if (content === 'tv') {
  1013. if (setting.closeSidePanel) checkSidePanel();
  1014. } else if (/ts|vi/.test(content)) {
  1015. closeNextProgramInfo();
  1016. }
  1017. hasCommentElement();
  1018. const inner = document.querySelector(selector.inner),
  1019. reports = document.querySelectorAll(selector.commentReport2);
  1020. if (inner) {
  1021. setTimeout(() => {
  1022. hasVideoElement();
  1023. checkVisibleFooter();
  1024. }, 50);
  1025. }
  1026. if (setting.reportFormCommentList) {
  1027. const report = document.querySelector(selector.commentReport);
  1028. if (report instanceof HTMLFormElement) {
  1029. report.dataset[`${sid.toLowerCase()}Commentreportform`] = String(
  1030. Date.now()
  1031. );
  1032. let uid;
  1033. if (content === 'tv') {
  1034. uid = getCommentProps(report, 'userId');
  1035. } else if (content === 'ts') {
  1036. const p = report.parentElement
  1037. ? report.parentElement.querySelector('p')
  1038. : null;
  1039. if (p instanceof HTMLParagraphElement) {
  1040. const cid = getCommentProps(report, 'commentId');
  1041. uid = p.dataset[`${sid.toLowerCase()}UserId`];
  1042. if (!uid && data.newComments && setArchiveComments(0)) {
  1043. /** @type {NodeListOf<HTMLDivElement>|null} */
  1044. const noIdComment = document.querySelectorAll(selector.commentTs),
  1045. noIdCommentInner = document.querySelectorAll(
  1046. selector.commentInnerTs
  1047. );
  1048. let reset = false;
  1049. if (noIdCommentInner.length) data.newComments = false;
  1050. for (let i = 0; i < noIdCommentInner.length; i++) {
  1051. const eMessage = noIdCommentInner[i];
  1052. if (
  1053. eMessage instanceof HTMLParagraphElement &&
  1054. eMessage.parentElement instanceof HTMLDivElement
  1055. ) {
  1056. const cid2 = getCommentProps(
  1057. eMessage.parentElement,
  1058. 'commentId'
  1059. );
  1060. if (cid && !uid) {
  1061. const comment = data.archiveComments.find(
  1062. (c) => c.id === cid
  1063. );
  1064. if (comment) uid = comment.userId;
  1065. }
  1066. if (cid2) {
  1067. const comment2 = data.archiveComments.find(
  1068. (c) => c.id === cid2
  1069. );
  1070. if (comment2) {
  1071. reset = true;
  1072. eMessage.dataset[`${sid.toLowerCase()}UserId`] =
  1073. comment2.userId;
  1074. }
  1075. }
  1076. }
  1077. }
  1078. if (reset) {
  1079. const listP = document.querySelector(
  1080. selector.commentList
  1081. )?.parentElement;
  1082. if (noIdComment.length && listP) {
  1083. ngComment(noIdComment, listP, content, true);
  1084. }
  1085. }
  1086. }
  1087. }
  1088. } else if (content === 'le') {
  1089. const eProps = report.parentElement?.parentElement;
  1090. if (eProps instanceof HTMLLIElement) {
  1091. uid = getCommentProps(eProps, 'userId');
  1092. }
  1093. }
  1094. if (uid) reportformUserComment(report, content, uid);
  1095. }
  1096. }
  1097. if (reports.length > 1) {
  1098. let minTime = Infinity,
  1099. oldForm = null;
  1100. for (let i = 0; i < reports.length; i++) {
  1101. const form = reports[i];
  1102. if (form instanceof HTMLFormElement) {
  1103. const timeS = form.dataset[`${sid.toLowerCase()}Commentreportform`];
  1104. if (timeS) {
  1105. const time = parseInt(timeS);
  1106. if (time < minTime) {
  1107. minTime = time;
  1108. oldForm = reports[i];
  1109. }
  1110. }
  1111. }
  1112. }
  1113. if (oldForm) {
  1114. const cancel = oldForm.querySelector(selector.commentReportCancel);
  1115. if (cancel instanceof HTMLButtonElement) {
  1116. cancel.click();
  1117. }
  1118. }
  1119. }
  1120. };
  1121.  
  1122. /**
  1123. * 指定したイベントリスナーを登録/解除する
  1124. * @param {boolean} b true:登録, false:解除
  1125. * @param {HTMLElement|null|undefined} e 登録/解除する要素
  1126. * @param {string} s
  1127. */
  1128. const changeEventListener = (b, e, s) => {
  1129. if (e) {
  1130. if (s === 'commentScroll') {
  1131. if (b) {
  1132. e.removeEventListener('mouseenter', checkMouseEnter);
  1133. e.removeEventListener('mouseleave', checkMouseLeave);
  1134. e.addEventListener('mouseenter', checkMouseEnter);
  1135. e.addEventListener('mouseleave', checkMouseLeave);
  1136. } else {
  1137. e.removeEventListener('mouseenter', checkMouseEnter);
  1138. e.removeEventListener('mouseleave', checkMouseLeave);
  1139. }
  1140. }
  1141. } else {
  1142. log('changeEventListener: not found element', s);
  1143. }
  1144. };
  1145.  
  1146. /**
  1147. * ページタイトル変更&URL移動したとき
  1148. */
  1149. const changePageTitle = () => {
  1150. if (data.href !== location.href) {
  1151. const content = returnContentType();
  1152. if (/tv|tt/.test(content)) {
  1153. removeStyle('headerPosition');
  1154. } else reStyle('headerPosition', setting.headerPosition);
  1155. if (content === 'tt') {
  1156. removeStyle('mouseoverNavigation');
  1157. } else reStyle('mouseoverNavigation', setting.mouseoverNavigation);
  1158. data.href = location.href;
  1159. }
  1160. };
  1161.  
  1162. /**
  1163. * 動画の画質を変更する
  1164. * @param {Number} n
  1165. */
  1166. const changeTargetQuality = (n) => {
  1167. const vi = returnVideo(),
  1168. vt = returnVideoTracks();
  1169. if (vt?.qualities) {
  1170. const qualities = vt.qualities,
  1171. len = qualities.length,
  1172. heightList = [0, 180, 240, 360, 480, 720, 1080],
  1173. targetHeight = heightList[n];
  1174. let target = -1;
  1175. if (qualities.length === 1) {
  1176. target = 0;
  1177. } else if (qualities[0].height <= 240) {
  1178. for (let i = 0; i < len; i++) {
  1179. if (qualities[i].height <= targetHeight) {
  1180. target = i;
  1181. }
  1182. }
  1183. } else {
  1184. for (let i = len - 1; i >= 0; i--) {
  1185. if (qualities[i].height <= targetHeight) {
  1186. target = i;
  1187. }
  1188. }
  1189. }
  1190. log(
  1191. 'changeTargetQuality',
  1192. n,
  1193. len,
  1194. target,
  1195. targetHeight,
  1196. qualities[target]?.height,
  1197. vi?.videoHeight
  1198. );
  1199. if (target >= 0) {
  1200. const tqHeight = vt.targetQuality?.height;
  1201. if (tqHeight !== qualities[target]?.height) {
  1202. log(
  1203. 'changeTargetQuality A',
  1204. vt.activeQuality?.height || 'null',
  1205. vt.targetQuality?.height || 'null',
  1206. vi?.videoHeight
  1207. );
  1208. vt.targetQuality = qualities[target];
  1209. }
  1210. } else {
  1211. if (vt.targetQuality) {
  1212. log(
  1213. 'changeTargetQuality B',
  1214. vt.activeQuality?.height || 'null',
  1215. vt.targetQuality?.height || 'null',
  1216. vi?.videoHeight
  1217. );
  1218. vt.targetQuality = null;
  1219. }
  1220. }
  1221. clearInterval(interval.changeTargetQuality);
  1222. interval.changeTargetQuality = setInterval(() => {
  1223. if (vt) {
  1224. if (target >= 0) {
  1225. const tqHeight = vt.targetQuality?.height;
  1226. if (tqHeight !== qualities[target]?.height) {
  1227. log(
  1228. 'changeTargetQuality C',
  1229. vt.activeQuality?.height || 'null',
  1230. vt.targetQuality?.height || 'null',
  1231. vi?.videoHeight
  1232. );
  1233. vt.targetQuality = qualities[target];
  1234. }
  1235. } else {
  1236. if (vt.targetQuality) {
  1237. log(
  1238. 'changeTargetQuality D',
  1239. vt.activeQuality?.height || 'null',
  1240. vt.targetQuality?.height || 'null',
  1241. vi?.videoHeight
  1242. );
  1243. vt.targetQuality = null;
  1244. }
  1245. }
  1246. } else {
  1247. clearInterval(interval.changeTargetQuality);
  1248. }
  1249. }, 2000);
  1250. } else if (returnContentType() !== 'le') {
  1251. log('changeTargetQuality: not found targetQuality');
  1252. }
  1253. };
  1254.  
  1255. /**
  1256. * 動画のソースが切り替わったとき
  1257. */
  1258. const changeVideoSource = () => {
  1259. clearInterval(interval.videosource);
  1260. interval.videosource = setInterval(() => {
  1261. const vi = returnVideo();
  1262. if (vi) {
  1263. clearInterval(interval.videosource);
  1264. if (vi.hasAttribute('src')) {
  1265. const src = vi.getAttribute('src');
  1266. if (src && src !== data.videoSource) {
  1267. log('changeVideoSource');
  1268. data.videoSource = src;
  1269. if (setting.qualityEnable) {
  1270. changeTargetQuality(setting.targetQuality);
  1271. }
  1272. if (setting.videoResolution) showVideoResolution();
  1273. }
  1274. }
  1275. }
  1276. }, 500);
  1277. };
  1278.  
  1279. /**
  1280. * ブロックしたユーザー数を確認する
  1281. * @param {boolean} b trueならdata.ngIdReserveを操作する
  1282. * @returns {number} ブロックしたユーザー数
  1283. */
  1284. const checkBlockedUser = (b) => {
  1285. log('checkBlockedUser', b, data.blockedUserId);
  1286. const sBui = localStorage.getItem('abm_blockedUserIds');
  1287. if (sBui) {
  1288. const aBui = sBui.split(',');
  1289. if (b) {
  1290. if (aBui.length >= 100) {
  1291. data.blockedUserId = aBui[0];
  1292. log('checkBlockedUser', data.blockedUserId, aBui[0], aBui[1]);
  1293. } else {
  1294. data.blockedUserId = '';
  1295. }
  1296. }
  1297. return aBui.length;
  1298. }
  1299. log('checkBlockedUser: not found abm_blockedUserIds', 'warn');
  1300. return 0;
  1301. };
  1302.  
  1303. /**
  1304. * クリックしたとき
  1305. * @param {MouseEvent} e
  1306. */
  1307. const checkClick = (e) => {
  1308. const content = returnContentType();
  1309. if (
  1310. (content === 'tv' &&
  1311. e.target instanceof HTMLElement &&
  1312. e.target.parentElement?.className === selector.commentReportSubmitTv) ||
  1313. (content === 'ts' &&
  1314. e.target instanceof HTMLElement &&
  1315. e.target.parentElement?.className === selector.commentReportSubmitTs) ||
  1316. (content === 'le' &&
  1317. e.target instanceof HTMLElement &&
  1318. e.target.parentElement?.className === selector.commentReportSubmitLe)
  1319. ) {
  1320. addNgId();
  1321. }
  1322. };
  1323.  
  1324. /**
  1325. * ダブルクリックしたとき
  1326. * @param {MouseEvent} e
  1327. */
  1328. const checkDblclick = (e) => {
  1329. if (
  1330. setting.dblclickScroll &&
  1331. /le|ts|vi/.test(returnContentType()) &&
  1332. e.target instanceof HTMLElement &&
  1333. e.target.closest(selector.videoDblclick)
  1334. ) {
  1335. adjustScrollPosition();
  1336. }
  1337. };
  1338.  
  1339. /**
  1340. * キーボードのキーを押したとき
  1341. * @param {KeyboardEvent} e
  1342. */
  1343. const checkKeyDown = (e) => {
  1344. const isInput =
  1345. e.target instanceof HTMLInputElement ||
  1346. e.target instanceof HTMLTextAreaElement
  1347. ? true
  1348. : false;
  1349. if (e.shiftKey && e.key === 'O' && (!isInput || (isInput && e.altKey))) {
  1350. openSettings();
  1351. } else if (!isInput && e.key === 'Escape') {
  1352. closeCommentReportForm();
  1353. } else if (setting.enterKey && e.key === 'Enter') {
  1354. if (!isInput) {
  1355. const ca = document.querySelector(selector.commentArea);
  1356. if (!ca) {
  1357. const cb = document.querySelector(selector.commentButton);
  1358. if (cb instanceof HTMLButtonElement) {
  1359. cb.click();
  1360. }
  1361. }
  1362. const ta = document.querySelector(selector.commentForm);
  1363. if (ta instanceof HTMLTextAreaElement) {
  1364. ta.focus();
  1365. e.preventDefault();
  1366. }
  1367. }
  1368. const cc = document.querySelector(selector.commentContinue);
  1369. if (cc instanceof HTMLButtonElement) {
  1370. const cf = document.querySelector(selector.commentForm);
  1371. if (
  1372. cf instanceof HTMLTextAreaElement &&
  1373. ((isInput && !cf.value) || !isInput)
  1374. ) {
  1375. cc.click();
  1376. }
  1377. }
  1378. } else if (
  1379. setting.sidePanelBackground &&
  1380. e.shiftKey &&
  1381. e.key === 'B' &&
  1382. (!isInput || (isInput && e.altKey))
  1383. ) {
  1384. const style = document.getElementById(`${sid}_style_sidePanelBackground`);
  1385. if (style) removeStyle('sidePanelBackground');
  1386. else addStyle('sidePanelBackground');
  1387. } else if (
  1388. setting.hiddenCommentList &&
  1389. e.shiftKey &&
  1390. e.key === 'C' &&
  1391. (!isInput || (isInput && e.altKey))
  1392. ) {
  1393. const style1 = document.getElementById(`${sid}_style_hiddenCommentList`),
  1394. style2 = document.getElementById(`${sid}_style_hiddenCommentList2`);
  1395. if (!style1 && !style2) {
  1396. addStyle('hiddenCommentList');
  1397. } else if (style1) {
  1398. removeStyle('hiddenCommentList');
  1399. if (setting.hiddenCommentListNum2) addStyle('hiddenCommentList2');
  1400. } else if (style2) {
  1401. removeStyle('hiddenCommentList2');
  1402. }
  1403. } else if (
  1404. e.target instanceof HTMLElement &&
  1405. (e.target.closest(selector.commentReportTv) ||
  1406. e.target.closest(selector.commentReportTs) ||
  1407. e.target.closest(selector.commentReportLe))
  1408. ) {
  1409. if (
  1410. setting.ngIdEnable &&
  1411. e.target.textContent === 'ブロック' &&
  1412. (e.key === 'Enter' || e.key === ' ')
  1413. ) {
  1414. addNgId();
  1415. }
  1416. }
  1417. };
  1418.  
  1419. /**
  1420. * マウスカーソルをコメントリストに重ねたとき
  1421. * @param {MouseEvent} e
  1422. */
  1423. const checkMouseEnter = (e) => {
  1424. const cl = document.querySelector(selector.commentList)?.parentElement;
  1425. if (cl === e.target) data.commentMouseEnter = true;
  1426. };
  1427.  
  1428. /**
  1429. * マウスカーソルをコメントリストから外したとき
  1430. * @param {MouseEvent} e
  1431. */
  1432. const checkMouseLeave = (e) => {
  1433. const cl = document.querySelector(selector.commentList)?.parentElement;
  1434. if (cl === e.target) data.commentMouseEnter = false;
  1435. };
  1436.  
  1437. /**
  1438. * 新規コメントを読み込んだとき
  1439. */
  1440. const checkNewComments = async () => {
  1441. const content = returnContentType();
  1442. if (!content) return;
  1443. const ca = document.querySelectorAll(selector.comenntAll),
  1444. /** @type {NodeListOf<HTMLDivElement>|null} */
  1445. cb = content ? document.querySelectorAll(selector.commentBefore) : null,
  1446. listP =
  1447. content === 'tv' || content === 'ts'
  1448. ? document.querySelector(selector.commentList)?.parentElement
  1449. : content === 'le'
  1450. ? document.querySelector(selector.commentList)?.parentElement
  1451. ?.parentElement
  1452. : null;
  1453. if (!ca?.length || !cb?.length) return;
  1454. data.newComments = true;
  1455. data.commentAll = ca.length;
  1456. if (ca.length === cb.length) {
  1457. data.archiveComments.length = 0;
  1458. data.commentId.clear();
  1459. if (content !== 'ts') data.comment.length = 0;
  1460. }
  1461. if (listP) {
  1462. for (let i = 0; i < cb.length; i++) {
  1463. /** @type {HTMLDivElement|null} */
  1464. const eInner = cb[i].querySelector(selector.commentInner);
  1465. if (eInner) {
  1466. eInner.dataset[`${sid.toLowerCase()}Hidden`] = 'true';
  1467. }
  1468. }
  1469. if (content === 'ts') {
  1470. data.archiveComments.length = 0;
  1471. await sleep(1000);
  1472. if (setArchiveComments(ca.length - cb.length)) {
  1473. ngComment(cb, listP, content, false);
  1474. } else log('checkNewComments: not found archiveCommentContainer');
  1475. } else ngComment(cb, listP, content, false);
  1476. }
  1477. };
  1478.  
  1479. /**
  1480. * サイドパネルが最初から開いているかを調べる
  1481. */
  1482. const checkSidePanel = () => {
  1483. if (!document.querySelector(`.${sid}_SidePanelCloseed`)) {
  1484. /** @type {HTMLButtonElement|null} */
  1485. const button = document.querySelector(selector.sidePanelClose);
  1486. button?.classList.add(`${sid}_SidePanelCloseed`);
  1487. button?.click();
  1488. }
  1489. };
  1490.  
  1491. /**
  1492. * スクリプトとストレージのバージョンを確認
  1493. */
  1494. const checkVersion = () => {
  1495. if ('version' in ls) {
  1496. if (ls.version < 9) {
  1497. if ('pageKey' in ls) {
  1498. delete ls.pageKey;
  1499. log('delete ls.pageKey');
  1500. }
  1501. }
  1502. }
  1503. ls.version = data.version;
  1504. saveStorage();
  1505. };
  1506.  
  1507. /**
  1508. * 動画のフッターが表示されているかを調べる
  1509. */
  1510. const checkVisibleFooter = () => {
  1511. const cvf = () => {
  1512. const fo = document.querySelector(selector.footerVisible);
  1513. if (setting.videoResolution && fo) showVideoResolution();
  1514. };
  1515. clearInterval(interval.footer);
  1516. interval.footer = setInterval(cvf, 500);
  1517. cvf();
  1518. };
  1519.  
  1520. /**
  1521. * ブロックアイコンをクリックして表示した報告フォームをすべて閉じる
  1522. */
  1523. const closeCommentReportForm = () => {
  1524. const submit = document.querySelectorAll(selector.commentReportCancel);
  1525. for (let i = 0; i < submit.length; i++) {
  1526. const button = submit[i];
  1527. if (button instanceof HTMLButtonElement) button.click();
  1528. }
  1529. };
  1530.  
  1531. /**
  1532. * 「次のエピソード」が表示されたらキャンセルボタンを押す
  1533. * 「こちらもオススメ」が表示されたらキャンセルボタンを押す
  1534. * 可能ならスキップボタンを押す
  1535. */
  1536. const closeNextProgramInfo = () => {
  1537. if (setting.nextProgramInfo) {
  1538. const nc = document.querySelector(selector.nextCancel);
  1539. if (nc instanceof HTMLButtonElement) {
  1540. setTimeout(() => {
  1541. nc.click();
  1542. }, 2000);
  1543. }
  1544. }
  1545. if (setting.nextProgramInfo) {
  1546. const ncm = document.querySelector(selector.nextCancelMini);
  1547. if (ncm instanceof HTMLButtonElement) {
  1548. setTimeout(() => {
  1549. ncm.click();
  1550. }, 2000);
  1551. }
  1552. }
  1553. if (setting.recommendedSeriesInfo) {
  1554. const rc = document.querySelector(selector.recommendedCancel);
  1555. if (rc instanceof HTMLButtonElement) {
  1556. setTimeout(() => {
  1557. rc.click();
  1558. }, 2000);
  1559. }
  1560. }
  1561. if (setting.skipVideo) {
  1562. const vs = document.querySelector(selector.videoSkip);
  1563. if (vs instanceof HTMLButtonElement) {
  1564. clearInterval(interval.videoskip);
  1565. interval.videoskip = setInterval(() => {
  1566. const vs2 = document.querySelector(selector.videoSkip2);
  1567. if (vs2 instanceof HTMLButtonElement) {
  1568. clearInterval(interval.videoskip);
  1569. vs2.click();
  1570. } else if (!vs && !vs2) clearInterval(interval.videoskip);
  1571. }, 500);
  1572. }
  1573. }
  1574. };
  1575.  
  1576. /**
  1577. * 一部の通知を閉じる
  1578. */
  1579. const closeNotificationToast = () => {
  1580. log('closeNotificationToast');
  1581. /** @type {HTMLButtonElement|null} */
  1582. const closeButton = document.querySelector(selector.notificationClose),
  1583. /** @type {HTMLVideoElement|null} */
  1584. message = document.querySelector(selector.notificationMessage);
  1585. if (closeButton && message) {
  1586. if (/推奨環境外のため/.test(message.innerText)) {
  1587. closeButton.click();
  1588. }
  1589. }
  1590. };
  1591.  
  1592. /**
  1593. * 設定欄を閉じる
  1594. */
  1595. const closeSettings = () => {
  1596. const settings = document.querySelector(`#${sid}_Settings`);
  1597. settings?.classList.add(`${sid}_Settings_hidden`);
  1598. };
  1599.  
  1600. /**
  1601. * 記入されたNGワードを処理しやすくするため正規表現用とそれ以外用に分ける
  1602. * @param {string} t
  1603. * @returns {string}
  1604. */
  1605. const convertNgword = (t) => {
  1606. log('convertNgword');
  1607. const aWord = t.split(/\r\n|\n|\r/),
  1608. aText = [],
  1609. aRe = [];
  1610. let sError = '';
  1611. for (let i = 0, j = aWord.length; i < j; i++) {
  1612. const str = aWord[i].trim();
  1613. if (str.slice(0, 2) !== '//') {
  1614. if (/^\/.+\/[dgimsuvy]{0,}$/.test(str)) {
  1615. try {
  1616. RegExp(str);
  1617. const re = str.slice(1, str.lastIndexOf('/')),
  1618. flag = str.slice(str.lastIndexOf('/') + 1) || '';
  1619. aRe.push({ r: re, f: flag });
  1620. } catch (error) {
  1621. sError += `${i + 1}行目: ${str}\n`;
  1622. }
  1623. } else {
  1624. aText.push(str);
  1625. }
  1626. }
  1627. }
  1628. if (!sError) {
  1629. data.ngWordText = [...aText];
  1630. data.ngWordRe = [...aRe];
  1631. }
  1632. return sError;
  1633. };
  1634.  
  1635. /**
  1636. * 設定欄を作成する
  1637. */
  1638. const createSettings = () => {
  1639. const sSettings = `
  1640. <div id="${sid}_Settings-header">
  1641. ${sid} 設定
  1642. </div>
  1643. <div id="${sid}_Settings-main">
  1644. <input id="${sid}_Settings-Tab-General" type="radio" name="Tab" class="${sid}_Settings-tab-switch" checked="checked">
  1645. <label class="${sid}_Settings-tab-label" for="${sid}_Settings-Tab-General">全般</label>
  1646. <div id="${sid}_Settings-General" class="${sid}_Settings-tab-content">
  1647. <fieldset>
  1648. <legend>全般</legend>
  1649. <label>
  1650. <input id="${sid}_Settings-reduceNavigation" type="checkbox">
  1651. ページを開いたときサイドナビゲーションを縮める
  1652. </label>
  1653. <br>
  1654. <label title="左側のサイドナビゲーションを縮めているとき、ウィンドウ左端にマウスカーソルを合わせるとサイドナビゲーションを表示します。">
  1655. <input id="${sid}_Settings-mouseoverNavigation" type="checkbox">
  1656. 左端にマウスオーバーしたときサイドナビゲーションを表示する
  1657. </label>
  1658. <br>
  1659. <label>
  1660. <input id="${sid}_Settings-closeNotification" type="checkbox">
  1661. 右上に表示される一部の通知を閉じる
  1662. </label>
  1663. <br>
  1664. <label title="テレビ・ビデオでは最大解像度も表示します。">
  1665. <input id="${sid}_Settings-videoResolution" type="checkbox">
  1666. 動画の解像度と表示領域サイズを表示する
  1667. </label>
  1668. <br>
  1669. <label title="ABEMAトップページなどで、ヘッダーは固定表示せずにページのスクロールに追従するようにします。">
  1670. <input id="${sid}_Settings-headerPosition" type="checkbox">
  1671. ヘッダーを追従表示にする
  1672. </label>
  1673. <br>
  1674. <label title="ヘッダー・サイドナビゲーションなどの背景や一部のボタンを半透明にします。">
  1675. <input id="${sid}_Settings-semiTransparent" type="checkbox">
  1676. ヘッダーやサイドナビゲーションなどを半透明にする
  1677. </label>
  1678. <br>
  1679. <label>
  1680. <input id="${sid}_Settings-smallFontSize" type="checkbox">
  1681. ヘッダーやフッターの一部の文字サイズを小さくする
  1682. </label>
  1683. <br>
  1684. <label title="動画の表示幅を縮めずに右側のサイドパネルを動画に重ねて表示します。">
  1685. <input id="${sid}_Settings-overlapSidePanel" type="checkbox">
  1686. サイドパネルを動画に重ねて表示する
  1687. </label>
  1688. <br>
  1689. <label title="「サイドパネルを動画に重ねて表示する」がONのときサイドパネルの背景が透明になりますが、Shift+Bキーで背景を半透明の黒色にします。&#13;&#10;入力欄にフォーカスしているときはAlt+Shift+Bキーで動作します。">
  1690. <input id="${sid}_Settings-sidePanelBackground" type="checkbox">
  1691. Shift+Bキーでサイドパネルの背景を半透明にする
  1692. </label>
  1693. <br>
  1694. <label title="サイドパネルの幅を100px~1000pxに変更できます。&#13;&#10;初期値:320">
  1695. <input id="${sid}_Settings-sidePanelSize" type="checkbox">
  1696. サイドパネルの幅を変更する
  1697. <input id="${sid}_Settings-sidePanelSizeNum" type="number" min="100" max="1000" step="10" ${
  1698. setting.sidePanelSize ? '' : 'disabled'
  1699. }>px
  1700. </label>
  1701. <br>
  1702. <label title="IDと視聴プランはアカウント管理ページで確認できます。">
  1703. <input id="${sid}_Settings-hiddenIdAndPlan" type="checkbox">
  1704. サイドナビゲーションのIDと視聴プランを隠す
  1705. </label>
  1706. <br>
  1707. </fieldset>
  1708. </div>
  1709. <input id="${sid}_Settings-Tab-Tv" type="radio" name="Tab" class="${sid}_Settings-tab-switch">
  1710. <label class="${sid}_Settings-tab-label" for="${sid}_Settings-Tab-Tv">テレビ</label>
  1711. <div id="${sid}_Settings-Tv" class="${sid}_Settings-tab-content">
  1712. <fieldset>
  1713. <legend>テレビ</legend>
  1714. <label>
  1715. <input id="${sid}_Settings-closeSidePanel" type="checkbox">
  1716. ページを開いたとき右側のサイドパネルを閉じる
  1717. </label>
  1718. <br>
  1719. <label>
  1720. <input id="${sid}_Settings-sidePanelCloseButton" type="checkbox">
  1721. サイドパネル上端にマウスオーバーしたとき閉じるボタンを表示する
  1722. </label>
  1723. <br>
  1724. <label title="番組情報を開いたとき詳細情報を自動的に表示します。">
  1725. <input id="${sid}_Settings-showProgramDetail" type="checkbox">
  1726. サイドパネルに記載された番組情報の詳細を常に表示する
  1727. </label>
  1728. <br>
  1729. <label title="ボタンにマウスオーバーしたときテキストを表示します。">
  1730. <input id="${sid}_Settings-hiddenButtonText" type="checkbox">
  1731. [最初から見る・番組情報・コメント]ボタンのテキストを隠す
  1732. </label>
  1733. <br>
  1734. <label title="約1分ごとに視聴数を更新します。">
  1735. <input id="${sid}_Settings-viewCounter" type="checkbox">
  1736. 入力欄に視聴数を表示する
  1737. </label>
  1738. <br>
  1739. </fieldset>
  1740. </div>
  1741. <input id="${sid}_Settings-Tab-Video" type="radio" name="Tab" class="${sid}_Settings-tab-switch">
  1742. <label class="${sid}_Settings-tab-label" for="${sid}_Settings-Tab-Video">ビデオ</label>
  1743. <div id="${sid}_Settings-Video" class="${sid}_Settings-tab-content">
  1744. <fieldset>
  1745. <legend>ビデオ・見逃し視聴</legend>
  1746. <label title="自動的に次のエピソードへ移動せずに最後まで再生できるようにします。">
  1747. <input id="${sid}_Settings-nextProgramInfo" type="checkbox">
  1748. 再生中に[次のエピソード]が表示されたらキャンセルボタンを押す
  1749. </label>
  1750. <br>
  1751. <label title="自動的にオススメ作品へ移動せずに最後まで再生できるようにします。">
  1752. <input id="${sid}_Settings-recommendedSeriesInfo" type="checkbox">
  1753. 再生中に[オススメ作品]が表示されたらキャンセルボタンを押す
  1754. </label>
  1755. <br>
  1756. <label>
  1757. <input id="${sid}_Settings-skipVideo" type="checkbox">
  1758. 再生中に可能ならスキップボタンを押す
  1759. </label>
  1760. <br>
  1761. </fieldset>
  1762. <fieldset>
  1763. <legend>ビデオ・見逃し視聴・ライブイベント</legend>
  1764. <label title="デフォルト表示では動画の上や左の余白を減らします。&#13;&#10;ワイド表示では動画の大きさをウィンドウ幅に合わせます。">
  1765. <input id="${sid}_Settings-videoPadding" type="checkbox">
  1766. 動画周辺の余白を減らす
  1767. </label>
  1768. <br>
  1769. <label title="可能であれば動画の上や左に隙間がなくなるようにページをスクロールします。">
  1770. <input id="${sid}_Settings-dblclickScroll" type="checkbox">
  1771. 動画のコントローラーをダブルクリックしてスクロール位置を調整
  1772. </label>
  1773. <br>
  1774. </fieldset>
  1775. </div>
  1776. <input id="${sid}_Settings-Tab-Comment" type="radio" name="Tab" class="${sid}_Settings-tab-switch">
  1777. <label class="${sid}_Settings-tab-label" for="${sid}_Settings-Tab-Comment">コメント</label>
  1778. <div id="${sid}_Settings-Comment" class="${sid}_Settings-tab-content">
  1779. <fieldset>
  1780. <legend>コメント</legend>
  1781. <label>
  1782. <input id="${sid}_Settings-newCommentOneByOne" type="checkbox">
  1783. コメントを1つずつ表示する
  1784. </label>
  1785. <br>
  1786. <label title="新着コメントが多い場合はスクロールせずに瞬時に表示します。">
  1787. <input id="${sid}_Settings-scrollNewComment" type="checkbox">
  1788. コメントを1つずつスクロールする
  1789. </label>
  1790. <br>
  1791. <label title="いずれかのコメントにマウスカーソルを合わせている間、一時的に新着コメントを表示しません。">
  1792. <input id="${sid}_Settings-stopCommentScroll" type="checkbox">
  1793. コメントにマウスオーバーしたときスクロールを止める
  1794. </label>
  1795. <br>
  1796. <label title="自分のコメントは背景を色付きの半透明で表示します。">
  1797. <input id="${sid}_Settings-highlightNewComment" type="checkbox">
  1798. 自分のコメントとテレビでの新規コメントを強調表示する
  1799. </label>
  1800. <br>
  1801. <label title="緑色:初回コメント&#13;&#10;黄色:2~3連続で同内容のコメント&#13;&#10;赤色:4連続以上で同内容のコメント&#13;&#10;紫色:直近5回のいずれかと同内容のコメント">
  1802. <input id="${sid}_Settings-highlightFirstComment" type="checkbox">
  1803. 初回コメントと連投コメントを強調表示する
  1804. </label>
  1805. <br>
  1806. <label title="文字サイズを10px~32pxに変更できます。&#13;&#10;初期値:13">
  1807. <input id="${sid}_Settings-commentFontSize" type="checkbox">
  1808. コメントの文字サイズを変更する
  1809. <input id="${sid}_Settings-commentFontSizeNum" type="number" min="10" max="32" ${
  1810. setting.commentFontSize ? '' : 'disabled'
  1811. }>px
  1812. </label>
  1813. <br>
  1814. <label>
  1815. <input id="${sid}_Settings-reduceCommentSpace" type="checkbox">
  1816. コメント周辺の余白を減らす&行間を縮める
  1817. </label>
  1818. <br>
  1819. <label title="コメントの透明度を0%~100%に変更できます。透明度は2つまで指定できます。&#13;&#10;入力欄にフォーカスしているときはAlt+Shift+Cキーで動作します。&#13;&#10;入力欄1の初期値:50">
  1820. <input id="${sid}_Settings-hiddenCommentList" type="checkbox">
  1821. Shift+Cキーでコメントリストを半透明化
  1822. <input id="${sid}_Settings-hiddenCommentListNum" type="number" min="0" max="100" step="5" ${
  1823. setting.hiddenCommentList ? '' : 'disabled'
  1824. }>%
  1825. <input id="${sid}_Settings-hiddenCommentListNum2" type="number" min="0" max="100" step="5" ${
  1826. setting.hiddenCommentList ? '' : 'disabled'
  1827. }>%
  1828. </label>
  1829. <br>
  1830. <label title="各コメント右端のブロックアイコンをクリックすると表示されるフォームをEscキーで閉じます。">
  1831. <input id="${sid}_Settings-escKey" type="checkbox">
  1832. Escキーで[このユーザーをブロックします]をすべてキャンセルする
  1833. </label>
  1834. <br>
  1835. <label title="コメントリストを上へスクロールしたときに表示される[新着コメント↓]ボタンもEnterキーで押します。">
  1836. <input id="${sid}_Settings-enterKey" type="checkbox">
  1837. Enterキーでコメント欄を開く&コメント入力欄にフォーカスする
  1838. </label>
  1839. <br>
  1840. <label title="そのユーザーのコメントを一覧表示します。ブロックする理由の参考にしてください。">
  1841. <input id="${sid}_Settings-reportFormCommentList" type="checkbox">
  1842. コメント報告フォームを開いたときそのユーザーのコメント履歴を表示する
  1843. </label>
  1844. <br>
  1845. </fieldset>
  1846. </div>
  1847. <input id="${sid}_Settings-Tab-Quality" type="radio" name="Tab" class="${sid}_Settings-tab-switch">
  1848. <label class="${sid}_Settings-tab-label" for="${sid}_Settings-Tab-Quality">画質</label>
  1849. <div id="${sid}_Settings-Quality" class="${sid}_Settings-tab-content">
  1850. <fieldset>
  1851. <legend>
  1852. <label title="チェックボックスONで画質機能を有効にします。">
  1853. <input id="${sid}_Settings-qualityEnable" type="checkbox">
  1854. 画質
  1855. </label>
  1856. </legend>
  1857. <details>
  1858. <summary>[説明]</summary>
  1859. <p>番組の画質を設定します。ライブイベントには対応していません。</p>
  1860. <p>番組を開いた直後やCM直後などから数秒後に設定した画質が反映されます。</p>
  1861. <p>設定した画質が用意されていない番組ではそれよりも低い画質で再生します。</p>
  1862. </details>
  1863. <label>
  1864. 画質:
  1865. <select id="${sid}_Settings-targetQuality" ${
  1866. setting.qualityEnable ? '' : 'disabled'
  1867. }>
  1868. <option value="0">自動</option>
  1869. <option value="1">通信節約モード(180p)</option>
  1870. <option value="2">最低画質(240p)</option>
  1871. <option value="3">低画質(360p)</option>
  1872. <option value="4">中画質(480p)</option>
  1873. <option value="5">高画質(720p)</option>
  1874. <option value="6">最高画質(1080p)</option>
  1875. </select>
  1876. </label>
  1877. </fieldset>
  1878. </div>
  1879. <input id="${sid}_Settings-Tab-Ng" type="radio" name="Tab" class="${sid}_Settings-tab-switch">
  1880. <label class="${sid}_Settings-tab-label" for="${sid}_Settings-Tab-Ng">NG</label>
  1881. <div id="${sid}_Settings-Ng" class="${sid}_Settings-tab-content">
  1882. <fieldset>
  1883. <legend>
  1884. <label title="チェックボックスONでNGワード機能を有効にします。">
  1885. <input id="${sid}_Settings-ngWordEnable" type="checkbox">
  1886. NGワード
  1887. </label>
  1888. </legend>
  1889. <details>
  1890. <summary>[説明]</summary>
  1891. <p>NGワードに該当するコメントを表示しません。</p>
  1892. <p>1行に1つのNGワードを記入してください。<br>
  1893. 先頭と末尾に / を付けると正規表現として扱います。<br>
  1894. 正規表現の末尾に i u などを追記してフラグを使用できます。</p>
  1895. <p>先頭が // の行はコメントとして扱うのでNGワードとして使用しません。</p>
  1896. <p>記入例:
  1897. <pre>
  1898. Aaa
  1899. bbb
  1900. /Ccc|DDD|eEe/
  1901.  
  1902. //大文字小文字を区別しません
  1903. /fff|ggg|hhh/i
  1904.  
  1905. //10桁以上の数字
  1906. /\\d{10,}/
  1907.  
  1908. //5文字以上の同じ文字を3回以上繰り返している
  1909. //(例:あいうえおあいうえおあいうえお)
  1910. /(.{5,})\\1{2,}/
  1911.  
  1912. //[ひらがな・カタカナ・漢字・絵文字・全角英数字・一部の全角記号]の
  1913. //いずれも含まない(Chromeなど一部のブラウザのみ有効)
  1914. /^(?!.*[\\p{scx=Hira}\\p{scx=Kana}\\p{scx=Han}\\p{RGI_Emoji}\\uFF01-\\uFF65]).*$/v
  1915. </pre>
  1916. </p>
  1917. <p>NGワードが多すぎると動作が重くなるのでご注意ください。</p>
  1918. </details>
  1919. <textarea id="${sid}_Settings-ngWord" ${
  1920. setting.ngWordEnable ? '' : 'disabled'
  1921. }></textarea>
  1922. <div id="${sid}_Settings-ngWord-error">
  1923. <p>エラー:下記の正規表現を修正してください。</p>
  1924. <pre id="${sid}_Settings-ngWord-error-pre"></pre>
  1925. </div>
  1926. <label>
  1927. <input id="${sid}_Settings-ngConsole" type="checkbox" ${
  1928. setting.ngWordEnable ? '' : 'disabled'
  1929. }>
  1930. NGワードに該当したコメントをブラウザのコンソールに出力する
  1931. </label>
  1932. </fieldset>
  1933. <fieldset>
  1934. <legend>
  1935. <label title="チェックボックスONでNG ID機能を有効にします。">
  1936. <input id="${sid}_Settings-ngIdEnable" type="checkbox">
  1937. NG ID
  1938. </label>
  1939. </legend>
  1940. <details>
  1941. <summary>[説明]</summary>
  1942. <p>ABEMAではコメント欄からブロックしたユーザーIDをブラウザに100件まで保存していて、それ以上ブロックしたときは古い方から破棄されます。<br>
  1943. このNG ID機能ではその破棄されるユーザーIDを別枠で保存しておいてそのユーザーのコメントもブロックします。</p>
  1944. <p>現在の保存数よりも少ない保存数に変更した場合は古いほうから溢れた分を破棄します。<br>
  1945. 0に変更するとすべて破棄します。</p>
  1946. </details>
  1947. <label>
  1948. 最大保存数:
  1949. <select id="${sid}_Settings-ngIdMaxSize" ${
  1950. setting.ngIdEnable ? '' : 'disabled'
  1951. }>
  1952. <option value="0">${setting._ngid[0]}</option>
  1953. <option value="1">${setting._ngid[1]}</option>
  1954. <option value="2">${setting._ngid[2]}</option>
  1955. <option value="3">${setting._ngid[3]}</option>
  1956. <option value="4">${setting._ngid[4]}</option>
  1957. <option value="5">${setting._ngid[5]}</option>
  1958. <option value="6">${setting._ngid[6]}</option>
  1959. <option value="7">${setting._ngid[7]}</option>
  1960. <option value="8">${setting._ngid[8]}</option>
  1961. <option value="9">${setting._ngid[9]}</option>
  1962. </select>
  1963. <span id="${sid}_Settings-ngId-record"></span>
  1964. </label>
  1965. </fieldset>
  1966. </div>
  1967. </div>
  1968. <div id="${sid}_Settings-footer">
  1969. <button id="${sid}_Settings-ok">OK</button>
  1970. <button id="${sid}_Settings-cancel">キャンセル</button>
  1971. </div>`,
  1972. eSettings = document.createElement('div');
  1973. eSettings.id = `${sid}_Settings`;
  1974. eSettings.className = `${sid}_Settings_hidden`;
  1975. eSettings.innerHTML = sSettings;
  1976. document.body.appendChild(eSettings);
  1977. document
  1978. .getElementById(`${sid}_Settings-overlapSidePanel`)
  1979. ?.addEventListener('change', () => {
  1980. const osp = document.getElementById(`${sid}_Settings-overlapSidePanel`),
  1981. spb = document.getElementById(`${sid}_Settings-sidePanelBackground`);
  1982. if (
  1983. osp instanceof HTMLInputElement &&
  1984. spb instanceof HTMLInputElement
  1985. ) {
  1986. spb.disabled = osp.checked ? false : true;
  1987. }
  1988. });
  1989. document
  1990. .getElementById(`${sid}_Settings-sidePanelSize`)
  1991. ?.addEventListener('change', () => {
  1992. const sps = document.getElementById(`${sid}_Settings-sidePanelSize`),
  1993. spsn = document.getElementById(`${sid}_Settings-sidePanelSizeNum`);
  1994. if (
  1995. sps instanceof HTMLInputElement &&
  1996. spsn instanceof HTMLInputElement
  1997. ) {
  1998. spsn.disabled = sps.checked ? false : true;
  1999. }
  2000. });
  2001. document
  2002. .getElementById(`${sid}_Settings-newCommentOneByOne`)
  2003. ?.addEventListener('change', () => {
  2004. const snc = document.getElementById(`${sid}_Settings-scrollNewComment`),
  2005. obo = document.getElementById(`${sid}_Settings-newCommentOneByOne`);
  2006. if (
  2007. snc instanceof HTMLInputElement &&
  2008. obo instanceof HTMLInputElement
  2009. ) {
  2010. snc.disabled = obo.checked ? false : true;
  2011. }
  2012. });
  2013. document
  2014. .getElementById(`${sid}_Settings-commentFontSize`)
  2015. ?.addEventListener('change', () => {
  2016. const cfs = document.getElementById(`${sid}_Settings-commentFontSize`),
  2017. cfsn = document.getElementById(`${sid}_Settings-commentFontSizeNum`);
  2018. if (
  2019. cfs instanceof HTMLInputElement &&
  2020. cfsn instanceof HTMLInputElement
  2021. ) {
  2022. cfsn.disabled = cfs.checked ? false : true;
  2023. }
  2024. });
  2025. document
  2026. .getElementById(`${sid}_Settings-hiddenCommentList`)
  2027. ?.addEventListener('change', () => {
  2028. const hcl = document.getElementById(
  2029. `${sid}_Settings-hiddenCommentList`
  2030. ),
  2031. hcln = document.getElementById(
  2032. `${sid}_Settings-hiddenCommentListNum`
  2033. ),
  2034. hcln2 = document.getElementById(
  2035. `${sid}_Settings-hiddenCommentListNum2`
  2036. );
  2037. if (
  2038. hcl instanceof HTMLInputElement &&
  2039. hcln instanceof HTMLInputElement &&
  2040. hcln2 instanceof HTMLInputElement
  2041. ) {
  2042. hcln.disabled = hcl.checked ? false : true;
  2043. hcln2.disabled = hcl.checked ? false : true;
  2044. }
  2045. });
  2046. document
  2047. .getElementById(`${sid}_Settings-qualityEnable`)
  2048. ?.addEventListener('change', () => {
  2049. const qe = document.getElementById(`${sid}_Settings-qualityEnable`),
  2050. tq = document.getElementById(`${sid}_Settings-targetQuality`);
  2051. if (qe instanceof HTMLInputElement && tq instanceof HTMLSelectElement) {
  2052. tq.disabled = qe.checked ? false : true;
  2053. }
  2054. });
  2055. document
  2056. .getElementById(`${sid}_Settings-ngWordEnable`)
  2057. ?.addEventListener('change', () => {
  2058. const ngwe = document.getElementById(`${sid}_Settings-ngWordEnable`),
  2059. ngw = document.getElementById(`${sid}_Settings-ngWord`),
  2060. ngc = document.getElementById(`${sid}_Settings-ngConsole`);
  2061. if (
  2062. ngwe instanceof HTMLInputElement &&
  2063. ngw instanceof HTMLTextAreaElement &&
  2064. ngc instanceof HTMLInputElement
  2065. ) {
  2066. ngw.disabled = ngwe.checked ? false : true;
  2067. ngc.disabled = ngwe.checked ? false : true;
  2068. }
  2069. });
  2070. document
  2071. .getElementById(`${sid}_Settings-ngIdEnable`)
  2072. ?.addEventListener('change', () => {
  2073. const ngie = document.getElementById(`${sid}_Settings-ngIdEnable`),
  2074. ngims = document.getElementById(`${sid}_Settings-ngIdMaxSize`);
  2075. if (
  2076. ngie instanceof HTMLInputElement &&
  2077. ngims instanceof HTMLSelectElement
  2078. ) {
  2079. ngims.disabled = ngie.checked ? false : true;
  2080. }
  2081. });
  2082. document
  2083. .getElementById(`${sid}_Settings-ok`)
  2084. ?.addEventListener('click', () => {
  2085. const eWord = document.getElementById(`${sid}_Settings-ngWord`),
  2086. eWordError = document.getElementById(`${sid}_Settings-ngWord-error`),
  2087. eWordPre = document.getElementById(
  2088. `${sid}_Settings-ngWord-error-pre`
  2089. );
  2090. let sError = '';
  2091. if (eWord instanceof HTMLTextAreaElement) {
  2092. const sWord = eWord.value;
  2093. if (sWord) {
  2094. sError = convertNgword(sWord);
  2095. }
  2096. }
  2097. if (
  2098. eWordError instanceof HTMLDivElement &&
  2099. eWordPre instanceof HTMLPreElement
  2100. ) {
  2101. if (sError) {
  2102. const eTabNg = document.getElementById(`${sid}_Settings-Tab-Ng`);
  2103. if (eTabNg instanceof HTMLInputElement) {
  2104. eWordPre.innerText = sError;
  2105. eWordError.style.display = 'block';
  2106. eTabNg.checked = true;
  2107. }
  2108. } else {
  2109. eWordPre.innerText = '';
  2110. eWordError.style.display = 'none';
  2111. saveSettings();
  2112. closeSettings();
  2113. }
  2114. }
  2115. });
  2116. document
  2117. .getElementById(`${sid}_Settings-cancel`)
  2118. ?.addEventListener('click', () => {
  2119. closeSettings();
  2120. loadSettings();
  2121. });
  2122. };
  2123.  
  2124. /**
  2125. * コメントのプロパティを取得する
  2126. * @param {HTMLDivElement|HTMLFormElement|HTMLLIElement} e 調べる要素
  2127. * @param {string} k キー名
  2128. * @returns {array|boolean|number|string|undefined}
  2129. */
  2130. const getCommentProps = (e, k) => {
  2131. let flag = false;
  2132. if (!e) {
  2133. log('getCommentProps: not found element', k);
  2134. return undefined;
  2135. }
  2136. for (const key in e) {
  2137. if (key.startsWith('__reactFiber$')) {
  2138. flag = true;
  2139. if (k === 'isOwnComment') {
  2140. if ('isOwnComment' in e[key].return.pendingProps) {
  2141. return e[key].return.pendingProps.isOwnComment;
  2142. }
  2143. log('getCommentProps: not found key', k);
  2144. log(e, 'debug');
  2145. return false;
  2146. }
  2147. if (k === 'commentId') {
  2148. if ('commentId' in e[key].return.pendingProps) {
  2149. return e[key].return.pendingProps.commentId;
  2150. }
  2151. log('getCommentProps: not found key', k);
  2152. log(e, 'debug');
  2153. return false;
  2154. }
  2155. if (k === 'commentMessage') {
  2156. if ('commentMessage' in e[key].return.pendingProps) {
  2157. return e[key].return.pendingProps.commentMessage;
  2158. }
  2159. log('getCommentProps: not found key', k);
  2160. log(e, 'debug');
  2161. return false;
  2162. }
  2163. if (k === 'viewCounter') {
  2164. if (e[key].return.pendingProps.slot?.id) {
  2165. return e[key].return.pendingProps.slot.id;
  2166. }
  2167. log('getCommentProps: not found key', k);
  2168. log(e, 'debug');
  2169. return false;
  2170. }
  2171. if (k === 'comments') {
  2172. if (e[key].return.pendingProps.comments) {
  2173. return e[key].return.pendingProps.comments;
  2174. }
  2175. log('getCommentProps: not found key', k);
  2176. return [];
  2177. }
  2178. if (k === 'commentCount') {
  2179. if (e[key].return.pendingProps.commentCount) {
  2180. return e[key].return.pendingProps.commentCount;
  2181. }
  2182. log('getCommentProps: not found key', k);
  2183. return 0;
  2184. }
  2185. if (
  2186. e[key].return?.pendingProps?.comment &&
  2187. e[key].return.pendingProps.comment[`_${k}`]
  2188. ) {
  2189. return e[key].return.pendingProps.comment[`_${k}`];
  2190. }
  2191. if (
  2192. e[key].return?.pendingProps?.commentItem &&
  2193. e[key].return.pendingProps.commentItem[k]
  2194. ) {
  2195. return e[key].return.pendingProps.commentItem[k];
  2196. }
  2197. if (k === 'id' && e[key].return?.pendingProps?.commentId) {
  2198. return e[key].return.pendingProps.commentId;
  2199. }
  2200. }
  2201. }
  2202. log('getCommentProps: not found key', k, flag);
  2203. log(e, 'debug');
  2204. return undefined;
  2205. };
  2206.  
  2207. /**
  2208. * 視聴している番組のステータスを取得する
  2209. * @param {string} t view:視聴数
  2210. * @param {boolean} f フラグ
  2211. */
  2212. const getStats = (t, f) => {
  2213. if (t === 'view') {
  2214. clearTimeout(interval.statsT);
  2215. /** @type {HTMLDivElement|null} */
  2216. const screen = document.querySelector(selector.tvScreen);
  2217. if (!screen) return;
  2218. const id = getCommentProps(screen, 'viewCounter');
  2219. const func = () => {
  2220. clearTimeout(interval.statsT);
  2221. const ta2 = document.querySelector(selector.commentTextarea);
  2222. if (ta2 instanceof HTMLTextAreaElement) {
  2223. GM_xmlhttpRequest({
  2224. method: 'GET',
  2225. url: `${
  2226. data.statsDomain
  2227. }v1/broadcast/slots/${id}/stats?${new Date().getTime()}`,
  2228. onload: (res) => {
  2229. if (res.status === 200) {
  2230. const obj = JSON.parse(res.responseText);
  2231. if (obj?.stats?.view) {
  2232. ta2.placeholder = `コメントを入力 (視聴数:${obj.stats.view})`;
  2233. }
  2234. }
  2235. },
  2236. onerror: () => {
  2237. log('getStats Error', t);
  2238. },
  2239. });
  2240. } else {
  2241. interval.statsT = setTimeout(func, 1000);
  2242. }
  2243. };
  2244. clearInterval(interval.statsI);
  2245. const ta1 = document.querySelector(selector.commentTextarea);
  2246. if (f) {
  2247. interval.statsI = setInterval(func, 70000);
  2248. if (ta1 instanceof HTMLTextAreaElement) {
  2249. ta1.placeholder = 'コメントを入力';
  2250. }
  2251. setTimeout(func, 1000);
  2252. } else {
  2253. const ta2 = document.querySelector(selector.commentTextarea);
  2254. if (ta1 instanceof HTMLTextAreaElement) {
  2255. ta1.placeholder = 'コメントを入力';
  2256. }
  2257. if (ta2 instanceof HTMLTextAreaElement) ta2.placeholder = '';
  2258. }
  2259. }
  2260. };
  2261.  
  2262. /**
  2263. * 番組ステータス取得用のドメインを調べる
  2264. */
  2265. const getStatsDomain = () => {
  2266. if (!data.statsDomain) {
  2267. /** @type {NodeListOf<HTMLLinkElement>|null} */
  2268. const link = document.querySelectorAll('link[rel="preconnect"]');
  2269. for (let i = 0; i < link.length; i++) {
  2270. if (/^https:\/\/api\.[^/]+\.abema-tv\.com\/$/.test(link[i].href)) {
  2271. data.statsDomain = link[i].href;
  2272. break;
  2273. }
  2274. }
  2275. }
  2276. };
  2277.  
  2278. /**
  2279. * 必要ならコメントに色を付ける
  2280. * @param {HTMLDivElement} e1 処理前の新着コメント
  2281. * @param {HTMLDivElement} e2 カスタムデータ属性を付与する新着コメント内の要素
  2282. * @param {String|null|undefined} m コメント本文
  2283. * @param {*} u userID
  2284. * @param {string} t どのページを開いているか
  2285. */
  2286. const highlightComment = (e1, e2, m, u, t) => {
  2287. if (setting.highlightFirstComment) {
  2288. let exists = false,
  2289. duplicate = 0;
  2290. for (let j = 0; j < data.comment.length; j++) {
  2291. if (data.comment[j].userid === u) {
  2292. exists = true;
  2293. if (m) {
  2294. const mes = m.trim().replace(/(.)\1{3,}$/, '$1$1$1');
  2295. for (let k = 0; k < data.comment[j].message.length; k++) {
  2296. if (data.comment[j].message[k] === mes) {
  2297. duplicate += 1;
  2298. if (k === 0) {
  2299. duplicate += 1000;
  2300. } else if (k === 1 && duplicate > 1000) {
  2301. duplicate += 1000;
  2302. } else if (k === 2 && duplicate > 2000) {
  2303. duplicate += 1000;
  2304. break;
  2305. }
  2306. }
  2307. }
  2308. if (data.comment[j].message.length > 4) {
  2309. data.comment[j].message.pop();
  2310. }
  2311. data.comment[j].message.unshift(mes);
  2312. }
  2313. break;
  2314. }
  2315. }
  2316. if (!exists) {
  2317. if (typeof u === 'string' && m) {
  2318. data.comment.push({ userid: u, message: [m] });
  2319. e2.dataset[`${sid.toLowerCase()}Green`] = '';
  2320. }
  2321. } else if (duplicate > 3000) {
  2322. e2.dataset[`${sid.toLowerCase()}Red`] = '';
  2323. } else if (duplicate > 1000) {
  2324. e2.dataset[`${sid.toLowerCase()}Yellow`] = '';
  2325. } else if (duplicate > 0) {
  2326. e2.dataset[`${sid.toLowerCase()}Purple`] = '';
  2327. }
  2328. }
  2329. if (
  2330. setting.highlightNewComment &&
  2331. t === 'le' &&
  2332. getCommentProps(e1, 'isOwnComment')
  2333. ) {
  2334. e2.dataset[`${sid.toLowerCase()}Own`] = '';
  2335. }
  2336. };
  2337.  
  2338. /**
  2339. * コメント欄の要素があるか調べる
  2340. */
  2341. const hasCommentElement = () => {
  2342. const check = () => {
  2343. const ca = document.querySelector(selector.commentArea);
  2344. if (ca) {
  2345. clearInterval(interval.comment);
  2346. if (!document.querySelector(`.${sid}_CommentElement`)) {
  2347. setTimeout(() => {
  2348. const cl = ca.querySelector(selector.commentList);
  2349. if (cl) {
  2350. cl.classList.add(`${sid}_CommentElement`);
  2351. if (setting.stopCommentScroll) {
  2352. changeEventListener(true, cl.parentElement, 'commentScroll');
  2353. }
  2354. observerC.observe(cl, { childList: true });
  2355. checkNewComments();
  2356. } else log('hasCommentElement: Not found element.', 'warn');
  2357. }, 1000);
  2358. }
  2359. } else {
  2360. clearInterval(interval.newcomment);
  2361. }
  2362. };
  2363. clearInterval(interval.comment);
  2364. interval.comment = setInterval(check, 500);
  2365. check();
  2366. };
  2367.  
  2368. /**
  2369. * 通知の要素があるか調べる
  2370. */
  2371. const hasNotification = () => {
  2372. clearInterval(interval.notification);
  2373. interval.notification = setInterval(() => {
  2374. const noti = document.querySelector(selector.notification);
  2375. if (noti) {
  2376. clearInterval(interval.notification);
  2377. closeNotificationToast();
  2378. }
  2379. }, 1000);
  2380. };
  2381.  
  2382. /**
  2383. * サイドナビゲーションの要素があるか調べる
  2384. */
  2385. const hasSideNavigation = () => {
  2386. log('hasSideNavigation');
  2387. clearInterval(interval.navigation);
  2388. interval.navigation = setInterval(() => {
  2389. const navi = document.querySelector(selector.sideNavi);
  2390. if (navi) {
  2391. clearInterval(interval.navigation);
  2392. if (
  2393. !navi.classList.contains(selector.sideNaviColl) &&
  2394. !navi.classList.contains(selector.sideNaviWrapColl)
  2395. ) {
  2396. reduceSideNavigation();
  2397. }
  2398. }
  2399. }, 4000);
  2400. };
  2401.  
  2402. /**
  2403. * VIDEO要素があるか調べる
  2404. */
  2405. const hasVideoElement = () => {
  2406. clearInterval(interval.videoelement);
  2407. interval.videoelement = setInterval(() => {
  2408. const vi = returnVideo();
  2409. if (vi) {
  2410. clearInterval(interval.videoelement);
  2411. if (!vi.classList.contains(`${sid}_VideoElement`)) {
  2412. log('hasVideoElement');
  2413. const content = returnContentType();
  2414. vi.classList.add(`${sid}_VideoElement`);
  2415. observerV.observe(vi, { attributes: true });
  2416. observerR.observe(vi);
  2417. if (setting.qualityEnable) {
  2418. changeTargetQuality(setting.targetQuality);
  2419. }
  2420. if (setting.viewCounter && data.statsDomain && content === 'tv') {
  2421. getStats('view', true);
  2422. }
  2423. if (content === 'ts') {
  2424. vi.addEventListener('seeked', seekedVideo);
  2425. }
  2426. }
  2427. }
  2428. }, 500);
  2429. };
  2430.  
  2431. /**
  2432. * 見逃し視聴で動画をシークしたとき
  2433. */
  2434. const seekedVideo = async () => {
  2435. log('seekedVideo');
  2436. data.archiveComments.length = 0;
  2437. data.comment.length = 0;
  2438. data.commentId.clear();
  2439. await sleep(1000);
  2440. closeCommentReportForm();
  2441. };
  2442.  
  2443. /**
  2444. * ページを開いたときに実行
  2445. */
  2446. const init = () => {
  2447. log('init');
  2448. addStyle('init');
  2449. checkVersion();
  2450. setInitialValue();
  2451. if (!document.getElementById(`${sid}_Settings`)) createSettings();
  2452. convertNgword(setting.ngWord);
  2453. checkBlockedUser(true);
  2454. GM_registerMenuCommand('設定', openSettings);
  2455. getStatsDomain();
  2456. setTimeout(startFirstObserve, 1000);
  2457. if (setting.overlapSidePanel) addStyle('overlapSidePanel');
  2458. if (setting.highlightFirstComment) addStyle('highlightFirstComment');
  2459. if (setting.highlightNewComment) addStyle('highlightNewComment');
  2460. if (setting.sidePanelCloseButton) addStyle('sidePanelCloseButton');
  2461. if (setting.showProgramDetail) addStyle('showProgramDetail');
  2462. if (setting.sidePanelSize) addStyle('sidePanelSize');
  2463. if (setting.hiddenIdAndPlan) addStyle('hiddenIdAndPlan');
  2464. if (setting.hiddenButtonText) addStyle('hiddenButtonText');
  2465. if (setting.videoResolution) addStyle('videoResolution');
  2466. if (setting.semiTransparent) addStyle('semiTransparent');
  2467. if (setting.smallFontSize) addStyle('smallFontSize');
  2468. if (setting.commentFontSize) addStyle('commentFontSize');
  2469. if (setting.reduceCommentSpace) addStyle('reduceCommentSpace');
  2470. if (setting.headerPosition && !/tv|tt/.test(returnContentType())) {
  2471. addStyle('headerPosition');
  2472. }
  2473. if (setting.videoPadding) addStyle('videoPadding');
  2474. if (setting.mouseoverNavigation && returnContentType() !== 'tt') {
  2475. addStyle('mouseoverNavigation');
  2476. }
  2477. if (setting.reduceNavigation) hasSideNavigation();
  2478. if (setting.closeNotification) hasNotification();
  2479. };
  2480.  
  2481. /**
  2482. * 設定を読み込んで設定欄に反映する
  2483. */
  2484. const loadSettings = () => {
  2485. /**
  2486. * 変数aの型がsとは異なる場合trueを返す
  2487. * @param {any} a 判別したい変数
  2488. * @param {string} t 型
  2489. * @returns {boolean}
  2490. */
  2491. const notType = (a, t) =>
  2492. Object.prototype.toString.call(a).slice(8, -1) !== t ? true : false;
  2493. /**
  2494. * 保存している値を設定欄のチェックボックスに反映する
  2495. * @param {string} s 変数名
  2496. * @param {string} t 型
  2497. */
  2498. const setCheck = (s, t) => {
  2499. const e = document.getElementById(`${sid}_Settings-${s}`);
  2500. if (e instanceof HTMLInputElement && !notType(setting[s], t)) {
  2501. e.checked = setting[s];
  2502. }
  2503. };
  2504. /**
  2505. * 保存している値を設定欄のセレクトボックスに反映する
  2506. * @param {string} s 変数名
  2507. * @param {string} t 型
  2508. */
  2509. const setSelect = (s, t) => {
  2510. const e = document.getElementById(`${sid}_Settings-${s}`);
  2511. if (e) {
  2512. if (e instanceof HTMLSelectElement && !notType(setting[s], t)) {
  2513. e.options.selectedIndex = setting[s];
  2514. }
  2515. }
  2516. };
  2517. /**
  2518. * 保存している値を設定欄の入力ボックス・テキストエリアに反映する
  2519. * @param {string} s 変数名
  2520. * @param {string} t 型
  2521. */
  2522. const setValue = (s, t) => {
  2523. const e = document.getElementById(`${sid}_Settings-${s}`);
  2524. if (e instanceof HTMLTextAreaElement) {
  2525. if (s === 'ngWord' && !notType(lsWord[s], t)) e.value = lsWord[s];
  2526. } else if (e instanceof HTMLInputElement) {
  2527. if (!notType(setting[s], t)) e.value = setting[s];
  2528. }
  2529. };
  2530. setCheck('reduceNavigation', 'Boolean');
  2531. setCheck('hiddenButtonText', 'Boolean');
  2532. setCheck('closeNotification', 'Boolean');
  2533. setCheck('overlapSidePanel', 'Boolean');
  2534. setCheck('videoResolution', 'Boolean');
  2535. setCheck('semiTransparent', 'Boolean');
  2536. setCheck('smallFontSize', 'Boolean');
  2537. setCheck('closeSidePanel', 'Boolean');
  2538. setCheck('sidePanelCloseButton', 'Boolean');
  2539. setCheck('showProgramDetail', 'Boolean');
  2540. setCheck('sidePanelBackground', 'Boolean');
  2541. setCheck('sidePanelSize', 'Boolean');
  2542. setValue('sidePanelSizeNum', 'String');
  2543. setCheck('hiddenIdAndPlan', 'Boolean');
  2544. setCheck('nextProgramInfo', 'Boolean');
  2545. setCheck('recommendedSeriesInfo', 'Boolean');
  2546. setCheck('skipVideo', 'Boolean');
  2547. setCheck('headerPosition', 'Boolean');
  2548. setCheck('videoPadding', 'Boolean');
  2549. setCheck('dblclickScroll', 'Boolean');
  2550. setCheck('mouseoverNavigation', 'Boolean');
  2551. setCheck('newCommentOneByOne', 'Boolean');
  2552. setCheck('scrollNewComment', 'Boolean');
  2553. setCheck('stopCommentScroll', 'Boolean');
  2554. setCheck('highlightNewComment', 'Boolean');
  2555. setCheck('highlightFirstComment', 'Boolean');
  2556. setCheck('commentFontSize', 'Boolean');
  2557. setValue('commentFontSizeNum', 'String');
  2558. setCheck('reduceCommentSpace', 'Boolean');
  2559. setCheck('hiddenCommentList', 'Boolean');
  2560. setValue('hiddenCommentListNum', 'String');
  2561. setValue('hiddenCommentListNum2', 'String');
  2562. setCheck('escKey', 'Boolean');
  2563. setCheck('enterKey', 'Boolean');
  2564. setCheck('viewCounter', 'Boolean');
  2565. setCheck('reportFormCommentList', 'Boolean');
  2566. setCheck('qualityEnable', 'Boolean');
  2567. setSelect('targetQuality', 'Number');
  2568. setCheck('ngWordEnable', 'Boolean');
  2569. setValue('ngWord', 'String');
  2570. setSelect('ngIdMaxSize', 'Number');
  2571. setCheck('ngConsole', 'Boolean');
  2572. setCheck('ngIdEnable', 'Boolean');
  2573. const spb = document.getElementById(`${sid}_Settings-sidePanelBackground`);
  2574. if (spb instanceof HTMLInputElement) {
  2575. spb.disabled = setting.overlapSidePanel ? false : true;
  2576. }
  2577. const snc = document.getElementById(`${sid}_Settings-scrollNewComment`);
  2578. if (snc instanceof HTMLInputElement) {
  2579. snc.disabled = setting.newCommentOneByOne ? false : true;
  2580. }
  2581. const tq = document.getElementById(`${sid}_Settings-targetQuality`);
  2582. if (tq instanceof HTMLSelectElement) {
  2583. tq.disabled = setting.qualityEnable ? false : true;
  2584. }
  2585. const ngw = document.getElementById(`${sid}_Settings-ngWord`),
  2586. ngc = document.getElementById(`${sid}_Settings-ngConsole`);
  2587. if (ngw instanceof HTMLTextAreaElement && ngc instanceof HTMLInputElement) {
  2588. ngw.disabled = setting.ngWordEnable ? false : true;
  2589. ngc.disabled = setting.ngWordEnable ? false : true;
  2590. }
  2591. const ngims = document.getElementById(`${sid}_Settings-ngIdMaxSize`);
  2592. if (ngims instanceof HTMLSelectElement) {
  2593. ngims.disabled = setting.ngIdEnable ? false : true;
  2594. }
  2595. const ngwe = document.getElementById(`${sid}_Settings-ngWord-error`),
  2596. ngwep = document.getElementById(`${sid}_Settings-ngWord-error-pre`);
  2597. if (ngwe instanceof HTMLDivElement && ngwep instanceof HTMLPreElement) {
  2598. ngwep.innerText = '';
  2599. ngwe.style.display = 'none';
  2600. }
  2601. const record = document.getElementById(`${sid}_Settings-ngId-record`);
  2602. if (record instanceof HTMLSpanElement) {
  2603. record.textContent = data.ngId.size
  2604. ? `(現在の保存数:${data.ngId.size})`
  2605. : '';
  2606. }
  2607. };
  2608.  
  2609. /**
  2610. * デバッグ用ログ
  2611. * @param {...any} a
  2612. */
  2613. const log = (...a) => {
  2614. if (ls.debug) {
  2615. try {
  2616. if (/^debug$|^error$|^info$|^warn$/.test(a[a.length - 1])) {
  2617. const b = a.pop();
  2618. console[b](sid, ...a);
  2619. } else console.log(sid, ...a);
  2620. } catch (e) {
  2621. if (e instanceof Error) console.error(e.message, ...a);
  2622. else if (typeof e === 'string') console.error(e, ...a);
  2623. else console.error('log error', ...a);
  2624. }
  2625. }
  2626. };
  2627.  
  2628. /**
  2629. * 該当するコメントをNG処理する
  2630. * @param {NodeListOf<HTMLDivElement>} n 処理前の新着コメント一覧
  2631. * @param {HTMLElement} e コメントリストの親要素
  2632. * @param {string} t どのページを開いているか
  2633. * @param {boolean} r true:見逃し視聴でuserID未登録コメントのブロックアイコンをクリックしたとき
  2634. */
  2635. const ngComment = (n, e, t, r) => {
  2636. for (let i = 0; i < n.length; i++) {
  2637. const eMessage = n[i].querySelector(selector.commentMessage),
  2638. /** @type {HTMLDivElement|null} */
  2639. eInner = n[i].querySelector(selector.commentInner),
  2640. message = eMessage?.textContent;
  2641. let cid = undefined,
  2642. ngFlag = false,
  2643. userId = undefined;
  2644. //コメントIDとユーザーIDを取得
  2645. if (/le|tv/.test(t)) {
  2646. cid = getCommentProps(n[i], 'id');
  2647. } else if (t === 'ts') {
  2648. cid = getCommentProps(n[i], 'commentId');
  2649. if (eInner) {
  2650. if (`${sid.toLowerCase()}UserId` in eInner.dataset) {
  2651. userId = eInner.dataset[`${sid.toLowerCase()}UserId`];
  2652. } else {
  2653. for (let j = 0; j < data.archiveComments.length; j++) {
  2654. if (data.archiveComments[j].id === cid) {
  2655. userId = data.archiveComments[j].userId;
  2656. eInner.dataset[`${sid.toLowerCase()}UserId`] = userId;
  2657. break;
  2658. }
  2659. }
  2660. if (!userId) {
  2661. log('checkNewComments: not found userId', cid, message);
  2662. }
  2663. }
  2664. }
  2665. }
  2666. const uid = t === 'ts' ? userId : getCommentProps(n[i], 'userId');
  2667. if (!eInner || !cid) continue;
  2668. if (!data.commentId.has(cid)) {
  2669. data.commentId.add(cid);
  2670. //NG IDの処理
  2671. if (!ngFlag && setting.ngIdEnable && uid) {
  2672. if (!(`${sid.toLowerCase()}Ngid` in eInner.dataset)) {
  2673. if (data.ngId.has(uid)) {
  2674. ngFlag = true;
  2675. log(`NG ID: ${uid} / ${cid} / ${message}`);
  2676. eInner.dataset[`${sid.toLowerCase()}Ngid`] = '';
  2677. }
  2678. }
  2679. }
  2680. //NGワードの処理
  2681. if (
  2682. !r &&
  2683. !ngFlag &&
  2684. setting.ngWordEnable &&
  2685. message &&
  2686. !(`${sid.toLowerCase()}Ngword` in eInner.dataset)
  2687. ) {
  2688. for (let j = 0; j < data.ngWordText.length; j++) {
  2689. if (data.ngWordText[j] && message.includes(data.ngWordText[j])) {
  2690. ngFlag = true;
  2691. eInner.dataset[`${sid.toLowerCase()}Ngword`] = '';
  2692. if (setting.ngConsole) {
  2693. console.log(
  2694. `${sid} NG Word: ${data.ngWordText[j]} / Comment: ${message} / UserID: ${uid}`
  2695. );
  2696. }
  2697. break;
  2698. }
  2699. }
  2700. if (!ngFlag) {
  2701. for (let j = 0; j < data.ngWordRe.length; j++) {
  2702. const wr = data.ngWordRe[j],
  2703. re = new RegExp(wr.r, wr.f);
  2704. if (data.ngWordRe[j] && re.test(message)) {
  2705. ngFlag = true;
  2706. eInner.dataset[`${sid.toLowerCase()}Ngword`] = '';
  2707. if (setting.ngConsole) {
  2708. const ng = re.exec(message);
  2709. if (ng) {
  2710. console.log(
  2711. `${sid} NG Word: ${ng[0]} / Comment: ${ng.input} / UserID: ${uid}`
  2712. );
  2713. }
  2714. }
  2715. break;
  2716. }
  2717. }
  2718. }
  2719. }
  2720. } else if (t !== 'ts') {
  2721. //重複コメントの処理
  2722. ngFlag = true;
  2723. if (!(`${sid.toLowerCase()}Duplicate` in eInner.dataset)) {
  2724. log(`---------- Duplicate: ${uid} / ${cid} / ${message} ----------`);
  2725. eInner.dataset[`${sid.toLowerCase()}Duplicate`] = '';
  2726. }
  2727. }
  2728. if (ngFlag) eInner.dataset[`${sid.toLowerCase()}Hidden`] = '';
  2729. if (uid) highlightComment(n[i], eInner, message, uid, t);
  2730. }
  2731. if (!r) {
  2732. if (t !== 'ts') {
  2733. const dupli = document.querySelectorAll(selector.commentDuplicate);
  2734. for (const ele of dupli) {
  2735. const inner = ele.firstChild;
  2736. if (inner) inner.remove();
  2737. }
  2738. }
  2739. visibleComment(e, t);
  2740. }
  2741. };
  2742.  
  2743. /**
  2744. * 設定欄を開く
  2745. */
  2746. const openSettings = () => {
  2747. const settings = document.querySelector(`#${sid}_Settings`);
  2748. if (settings && settings.classList.contains(`${sid}_Settings_hidden`)) {
  2749. loadSettings();
  2750. settings.classList.remove(`${sid}_Settings_hidden`);
  2751. }
  2752. };
  2753.  
  2754. /**
  2755. * サイドナビゲーションを縮める
  2756. */
  2757. const reduceSideNavigation = () => {
  2758. log('reduceSideNavigation');
  2759. /** @type {HTMLButtonElement|null} */
  2760. const headerMenu = document.querySelector(selector.headerMenu);
  2761. headerMenu?.click();
  2762. };
  2763.  
  2764. /**
  2765. * 報告フォームの下にそのユーザーのコメント一覧を追加する
  2766. * @param {HTMLFormElement} e ブロックアイコンをクリックして表示される報告フォームの要素
  2767. * @param {string} t どのページを開いているか
  2768. * @param {*} u ブロックアイコンをクリックしたコメントのuserID
  2769. */
  2770. const reportformUserComment = (e, t, u) => {
  2771. log('reportformUserComment', t, u);
  2772. const list = document.querySelectorAll(selector.comenntAll),
  2773. comments = [],
  2774. ids = new Set();
  2775. const addComment = (message, id) => {
  2776. if (message && typeof message === 'string' && !ids.has(id)) {
  2777. comments.push(message);
  2778. ids.add(id);
  2779. }
  2780. };
  2781. for (let i = 0; i < list.length; i++) {
  2782. const co = list[i];
  2783. if (co instanceof HTMLDivElement || co instanceof HTMLLIElement) {
  2784. if (/le|tv/.test(t)) {
  2785. if (getCommentProps(co, 'userId') === u) {
  2786. addComment(
  2787. getCommentProps(co, t === 'tv' ? 'message' : 'body'),
  2788. getCommentProps(co, 'id')
  2789. );
  2790. }
  2791. } else if (t === 'ts') {
  2792. const p = co.querySelector('p');
  2793. if (p instanceof HTMLParagraphElement) {
  2794. if (p.dataset[`${sid.toLowerCase()}UserId`] === u) {
  2795. addComment(
  2796. getCommentProps(co, 'commentMessage'),
  2797. getCommentProps(co, 'commentId')
  2798. );
  2799. }
  2800. }
  2801. }
  2802. }
  2803. }
  2804. if (comments.length) {
  2805. const eWrapper = document.createElement('div'),
  2806. eHeader = document.createElement('div'),
  2807. eList = document.createElement('div');
  2808. eWrapper.id = `${sid}_CommentReportForm-NgComment`;
  2809. eHeader.id = `${sid}_CommentReportForm-NgCommentHeader`;
  2810. eHeader.textContent = 'このユーザーのコメント履歴:';
  2811. eList.id = `${sid}_CommentReportForm-NgCommentList`;
  2812. eWrapper.appendChild(eHeader);
  2813. for (let i = 0; i < comments.length; i++) {
  2814. const p = document.createElement('p');
  2815. p.textContent = comments[i];
  2816. eList.appendChild(p);
  2817. }
  2818. eWrapper.appendChild(eList);
  2819. e.appendChild(eWrapper);
  2820. }
  2821. };
  2822.  
  2823. /**
  2824. * 動画の大きさが変わったとき
  2825. */
  2826. const resizeVideo = () => {
  2827. if (setting.qualityEnable) {
  2828. clearTimeout(interval.resizeVideo);
  2829. interval.resizeVideo = setTimeout(() => {
  2830. changeTargetQuality(setting.targetQuality);
  2831. checkVisibleFooter();
  2832. }, 500);
  2833. }
  2834. };
  2835.  
  2836. /**
  2837. * スタイルを追加・削除する
  2838. * @param {string} s スタイルの設定名
  2839. * @param {boolean} b trueならスタイルを追加
  2840. */
  2841. const reStyle = (s, b) => {
  2842. removeStyle(s);
  2843. if (b) addStyle(s);
  2844. };
  2845.  
  2846. /**
  2847. * スタイルを削除する
  2848. * @param {string} s スタイルの設定名
  2849. */
  2850. const removeStyle = (s) => {
  2851. const e = document.getElementById(`${sid}_style_${s}`);
  2852. if (e instanceof HTMLStyleElement) e.remove();
  2853. };
  2854.  
  2855. /**
  2856. * どのコンテンツを表示しているかを返す
  2857. * @returns {string} tv:テレビ, ts:見逃し視聴, le:ライブイベント, vi:ビデオ, tt:番組表
  2858. */
  2859. const returnContentType = () => {
  2860. const type = /^https:\/\/abema\.tv\/now-on-air\/.+$/.test(location.href)
  2861. ? 'tv'
  2862. : /^https:\/\/abema\.tv\/channels\/.+$/.test(location.href)
  2863. ? 'ts'
  2864. : /^https:\/\/abema\.tv\/live-event\/.+$/.test(location.href)
  2865. ? 'le'
  2866. : /^https:\/\/abema\.tv\/video\/episode\/.+$/.test(location.href)
  2867. ? 'vi'
  2868. : /^https:\/\/abema\.tv\/timetable/.test(location.href)
  2869. ? 'tt'
  2870. : '';
  2871. return type;
  2872. };
  2873.  
  2874. /**
  2875. * video要素を返す
  2876. * @returns {HTMLVideoElement|null}
  2877. */
  2878. const returnVideo = () => {
  2879. /** @type {HTMLVideoElement|null} */
  2880. const vi = document.querySelector(selector.video);
  2881. return vi ? vi : null;
  2882. };
  2883.  
  2884. /**
  2885. * 動画のvideoTracksを返す
  2886. * @returns {object|undefined}
  2887. */
  2888. const returnVideoTracks = () => {
  2889. const vc = document.querySelector(selector.videoContainer);
  2890. for (const key in vc) {
  2891. if (
  2892. key.startsWith('__reactFiber$') &&
  2893. vc[key].return?.stateNode?.player?.videoTracks &&
  2894. vc[key].return.stateNode.player.videoTracks[0]
  2895. ) {
  2896. return vc[key].return.stateNode.player.videoTracks[0];
  2897. }
  2898. }
  2899. return undefined;
  2900. };
  2901.  
  2902. /**
  2903. * 設定を保存する
  2904. */
  2905. const saveSettings = () => {
  2906. /**
  2907. * 設定欄のチェックボックスの値を取得する
  2908. * @param {string} s 変数名
  2909. */
  2910. const getCheck = (s) => {
  2911. const e = document.getElementById(`${sid}_Settings-${s}`);
  2912. if (e instanceof HTMLInputElement) {
  2913. setting[s] = e.checked ? true : false;
  2914. }
  2915. };
  2916. /**
  2917. * 設定欄のセレクトボックスの値を取得する
  2918. * @param {string} s 変数名
  2919. */
  2920. const getSelect = (s) => {
  2921. const e = document.getElementById(`${sid}_Settings-${s}`);
  2922. if (e instanceof HTMLSelectElement) {
  2923. const index = e.options.selectedIndex;
  2924. if (Number.isInteger(index) && index >= 0) {
  2925. setting[s] = index;
  2926. }
  2927. }
  2928. };
  2929. /**
  2930. * 設定欄の入力ボックス・テキストエリアの値を取得する
  2931. * @param {string} s 変数名
  2932. */
  2933. const getValue = (s) => {
  2934. const e = document.getElementById(`${sid}_Settings-${s}`);
  2935. if (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) {
  2936. if (s === 'commentFontSizeNum') {
  2937. if (!e.value || isNaN(Number(e.value)) || /e/.test(e.value)) {
  2938. e.value = '13';
  2939. } else if (Number(e.value) < 10) e.value = '10';
  2940. else if (Number(e.value) > 32) e.value = '32';
  2941. } else if (
  2942. s === 'hiddenCommentListNum' ||
  2943. s === 'hiddenCommentListNum2'
  2944. ) {
  2945. if (!e.value || isNaN(Number(e.value)) || /e/.test(e.value)) {
  2946. if (s === 'hiddenCommentListNum') e.value = '50';
  2947. else if (s === 'hiddenCommentListNum2') e.value = '';
  2948. } else if (Number(e.value) < 0) e.value = '0';
  2949. else if (Number(e.value) > 100) e.value = '100';
  2950. } else if (s === 'sidePanelSizeNum') {
  2951. if (!e.value || isNaN(Number(e.value)) || /e/.test(e.value)) {
  2952. e.value = '320';
  2953. } else if (Number(e.value) < 100) e.value = '100';
  2954. else if (Number(e.value) > 1000) e.value = '1000';
  2955. }
  2956. setting[s] = e.value ? e.value : '';
  2957. }
  2958. };
  2959. const content = returnContentType();
  2960. document.getElementById(`${sid}_Settings-ok`)?.blur();
  2961. getCheck('reduceNavigation');
  2962. getCheck('hiddenButtonText');
  2963. getCheck('closeNotification');
  2964. getCheck('overlapSidePanel');
  2965. getCheck('videoResolution');
  2966. getCheck('semiTransparent');
  2967. getCheck('smallFontSize');
  2968. getCheck('closeSidePanel');
  2969. getCheck('sidePanelBackground');
  2970. getCheck('sidePanelCloseButton');
  2971. getCheck('showProgramDetail');
  2972. getCheck('sidePanelSize');
  2973. getValue('sidePanelSizeNum');
  2974. getCheck('hiddenIdAndPlan');
  2975. getCheck('nextProgramInfo');
  2976. getCheck('recommendedSeriesInfo');
  2977. getCheck('skipVideo');
  2978. getCheck('headerPosition');
  2979. getCheck('videoPadding');
  2980. getCheck('dblclickScroll');
  2981. getCheck('mouseoverNavigation');
  2982. getCheck('newCommentOneByOne');
  2983. getCheck('scrollNewComment');
  2984. getCheck('stopCommentScroll');
  2985. getCheck('highlightNewComment');
  2986. getCheck('highlightFirstComment');
  2987. getCheck('commentFontSize');
  2988. getValue('commentFontSizeNum');
  2989. getCheck('reduceCommentSpace');
  2990. getCheck('hiddenCommentList');
  2991. getValue('hiddenCommentListNum');
  2992. getValue('hiddenCommentListNum2');
  2993. getCheck('escKey');
  2994. getCheck('enterKey');
  2995. getCheck('viewCounter');
  2996. getCheck('reportFormCommentList');
  2997. getCheck('qualityEnable');
  2998. getSelect('targetQuality');
  2999. getCheck('ngWordEnable');
  3000. getValue('ngWord');
  3001. getSelect('ngIdMaxSize');
  3002. getCheck('ngConsole');
  3003. getCheck('ngIdEnable');
  3004. ls.reduceNavigation = setting.reduceNavigation;
  3005. if (ls.hiddenButtonText !== setting.hiddenButtonText) {
  3006. reStyle('hiddenButtonText', setting.hiddenButtonText);
  3007. }
  3008. ls.hiddenButtonText = setting.hiddenButtonText;
  3009. ls.closeNotification = setting.closeNotification;
  3010. if (ls.videoResolution !== setting.videoResolution) {
  3011. reStyle('videoResolution', setting.videoResolution);
  3012. }
  3013. ls.videoResolution = setting.videoResolution;
  3014. if (ls.semiTransparent !== setting.semiTransparent) {
  3015. reStyle('semiTransparent', setting.semiTransparent);
  3016. }
  3017. ls.semiTransparent = setting.semiTransparent;
  3018. if (ls.smallFontSize !== setting.smallFontSize) {
  3019. reStyle('smallFontSize', setting.smallFontSize);
  3020. }
  3021. ls.smallFontSize = setting.smallFontSize;
  3022. ls.closeSidePanel = setting.closeSidePanel;
  3023. if (ls.overlapSidePanel !== setting.overlapSidePanel) {
  3024. reStyle('overlapSidePanel', setting.overlapSidePanel);
  3025. if (setting.highlightNewComment) reStyle('highlightNewComment', true);
  3026. if (setting.highlightFirstComment) reStyle('highlightFirstComment', true);
  3027. }
  3028. ls.overlapSidePanel = setting.overlapSidePanel;
  3029. if (ls.sidePanelBackground !== setting.sidePanelBackground) {
  3030. reStyle('sidePanelBackground', setting.sidePanelBackground);
  3031. }
  3032. ls.sidePanelBackground = setting.sidePanelBackground;
  3033. if (ls.sidePanelCloseButton !== setting.sidePanelCloseButton) {
  3034. reStyle('sidePanelCloseButton', setting.sidePanelCloseButton);
  3035. }
  3036. ls.sidePanelCloseButton = setting.sidePanelCloseButton;
  3037. if (ls.showProgramDetail !== setting.showProgramDetail) {
  3038. reStyle('showProgramDetail', setting.showProgramDetail);
  3039. }
  3040. ls.showProgramDetail = setting.showProgramDetail;
  3041. if (ls.sidePanelSize || ls.sidePanelSize !== setting.sidePanelSize) {
  3042. reStyle('overlapSidePanel', setting.overlapSidePanel);
  3043. reStyle('sidePanelSize', setting.sidePanelSize);
  3044. }
  3045. ls.sidePanelSize = setting.sidePanelSize;
  3046. if (ls.hiddenIdAndPlan !== setting.hiddenIdAndPlan) {
  3047. reStyle('hiddenIdAndPlan', setting.hiddenIdAndPlan);
  3048. }
  3049. ls.hiddenIdAndPlan = setting.hiddenIdAndPlan;
  3050. ls.sidePanelSizeNum = setting.sidePanelSizeNum;
  3051. ls.nextProgramInfo = setting.nextProgramInfo;
  3052. ls.recommendedSeriesInfo = setting.recommendedSeriesInfo;
  3053. ls.skipVideo = setting.skipVideo;
  3054. if (ls.headerPosition !== setting.headerPosition) {
  3055. reStyle('headerPosition', setting.headerPosition);
  3056. }
  3057. if (/tv|tt/.test(content)) removeStyle('headerPosition');
  3058. ls.headerPosition = setting.headerPosition;
  3059. if (ls.videoPadding !== setting.videoPadding) {
  3060. reStyle('videoPadding', setting.videoPadding);
  3061. }
  3062. ls.videoPadding = setting.videoPadding;
  3063. ls.dblclickScroll = setting.dblclickScroll;
  3064. if (ls.mouseoverNavigation !== setting.mouseoverNavigation) {
  3065. reStyle('mouseoverNavigation', setting.mouseoverNavigation);
  3066. }
  3067. if (content === 'tt') removeStyle('mouseoverNavigation');
  3068. ls.mouseoverNavigation = setting.mouseoverNavigation;
  3069. ls.newCommentOneByOne = setting.newCommentOneByOne;
  3070. ls.scrollNewComment = setting.scrollNewComment;
  3071. if (ls.stopCommentScroll !== setting.stopCommentScroll) {
  3072. changeEventListener(
  3073. setting.stopCommentScroll,
  3074. document.querySelector(selector.commentList)?.parentElement,
  3075. 'commentScroll'
  3076. );
  3077. }
  3078. ls.stopCommentScroll = setting.stopCommentScroll;
  3079. if (ls.highlightNewComment !== setting.highlightNewComment) {
  3080. reStyle('highlightNewComment', setting.highlightNewComment);
  3081. }
  3082. ls.highlightNewComment = setting.highlightNewComment;
  3083. if (ls.highlightFirstComment !== setting.highlightFirstComment) {
  3084. reStyle('highlightFirstComment', setting.highlightFirstComment);
  3085. }
  3086. ls.highlightFirstComment = setting.highlightFirstComment;
  3087. if (ls.commentFontSizeNum !== setting.commentFontSizeNum) {
  3088. reStyle('commentFontSize', setting.commentFontSize);
  3089. }
  3090. ls.commentFontSizeNum = setting.commentFontSizeNum;
  3091. if (ls.commentFontSize !== setting.commentFontSize) {
  3092. reStyle('commentFontSize', setting.commentFontSize);
  3093. }
  3094. ls.commentFontSize = setting.commentFontSize;
  3095. if (ls.reduceCommentSpace !== setting.reduceCommentSpace) {
  3096. reStyle('reduceCommentSpace', setting.reduceCommentSpace);
  3097. }
  3098. ls.reduceCommentSpace = setting.reduceCommentSpace;
  3099. if (ls.hiddenCommentList && !setting.hiddenCommentList) {
  3100. removeStyle('hiddenCommentList');
  3101. removeStyle('hiddenCommentList2');
  3102. }
  3103. ls.hiddenCommentList = setting.hiddenCommentList;
  3104. if (
  3105. setting.hiddenCommentList &&
  3106. ls.hiddenCommentListNum !== setting.hiddenCommentListNum &&
  3107. document.getElementById(`${sid}_style_hiddenCommentList`)
  3108. ) {
  3109. reStyle('hiddenCommentList', true);
  3110. }
  3111. ls.hiddenCommentListNum = setting.hiddenCommentListNum;
  3112. if (
  3113. setting.hiddenCommentList &&
  3114. ls.hiddenCommentListNum2 !== setting.hiddenCommentListNum2 &&
  3115. document.getElementById(`${sid}_style_hiddenCommentList2`)
  3116. ) {
  3117. reStyle('hiddenCommentList2', setting.hiddenCommentListNum2);
  3118. }
  3119. ls.hiddenCommentListNum2 = setting.hiddenCommentListNum2;
  3120. ls.escKey = setting.escKey;
  3121. ls.enterKey = setting.enterKey;
  3122. if (ls.viewCounter && !setting.viewCounter) getStats('view', false);
  3123. ls.viewCounter = setting.viewCounter;
  3124. ls.reportFormCommentList = setting.reportFormCommentList;
  3125. ls.qualityEnable = setting.qualityEnable;
  3126. if (setting.qualityEnable && setting.targetQuality !== ls.targetQuality) {
  3127. changeTargetQuality(setting.targetQuality);
  3128. }
  3129. ls.targetQuality = setting.targetQuality;
  3130. ls.ngWordEnable = setting.ngWordEnable;
  3131. lsWord.ngWord = setting.ngWord;
  3132. ls.ngIdEnable = setting.ngIdEnable;
  3133. lsId.ngId = setting.ngId ? [...setting.ngId] : [];
  3134. data.ngId = new Set(setting.ngId);
  3135. if (
  3136. ls.ngIdMaxSize < setting.ngIdMaxSize &&
  3137. setting.ngId.length > setting._ngid[ls.ngIdMaxSize]
  3138. ) {
  3139. setting.ngId.splice(
  3140. 0,
  3141. setting.ngId.length - setting._ngid[ls.ngIdMaxSize]
  3142. );
  3143. data.ngId = new Set(setting.ngId);
  3144. }
  3145. ls.ngIdMaxSize = setting.ngIdMaxSize;
  3146. ls.ngConsole = setting.ngConsole;
  3147. ls.ngIdEnable = setting.ngIdEnable;
  3148. saveStorage();
  3149. };
  3150.  
  3151. /**
  3152. * ローカルストレージに保存する
  3153. */
  3154. const saveStorage = () => {
  3155. localStorage.setItem(sid, JSON.stringify(ls));
  3156. localStorage.setItem(`${sid}-Word`, JSON.stringify(lsWord));
  3157. localStorage.setItem(`${sid}-Id`, JSON.stringify(lsId));
  3158. };
  3159.  
  3160. /**
  3161. * 可能であれば動画の上側や左側に隙間がなくなるようにページをスクロールする
  3162. */
  3163. const adjustScrollPosition = () => {
  3164. log('adjustScrollPosition');
  3165. const player = document.querySelector(selector.videoMainPlayer);
  3166. if (player) {
  3167. player.scrollIntoView({ behavior: 'smooth', inline: 'start' });
  3168. }
  3169. };
  3170.  
  3171. /**
  3172. * 見逃しコメントを登録する
  3173. * @param {number} n
  3174. * @returns
  3175. */
  3176. const setArchiveComments = (n) => {
  3177. /** @type {HTMLCollection|null} */
  3178. const acc = document.getElementsByClassName(
  3179. selector.archiveCommentContainer
  3180. );
  3181. if (acc.length && acc[0] instanceof HTMLDivElement) {
  3182. const ac = getCommentProps(acc[0], 'comments');
  3183. if (ac instanceof Array) {
  3184. data.archiveComments = ac.slice(n);
  3185. } else data.archiveComments.length = 0;
  3186. return true;
  3187. }
  3188. data.archiveComments.length = 0;
  3189. return false;
  3190. };
  3191.  
  3192. /**
  3193. * このスクリプトを初めて使うときやローカルストレージを削除したとき初期値を登録する
  3194. */
  3195. const setInitialValue = () => {
  3196. /**
  3197. * 変数aの型がsとは異なる場合trueを返す
  3198. * @param {string} t 型
  3199. * @param {any} a 判別したい変数
  3200. * @returns {boolean}
  3201. */
  3202. const notType = (t, a) =>
  3203. Object.prototype.toString.call(a).slice(8, -1) !== t ? true : false;
  3204. /**
  3205. * 設定用の変数が異なる型の場合は初期値を登録する
  3206. * @param {string} s 変数名
  3207. * @param {string} t 型の先頭3文字
  3208. * @param {any} a 初期値
  3209. */
  3210. const setValue = (s, t, a) => {
  3211. if (notType(t, setting[s])) {
  3212. setting[s] = a;
  3213. if (s === 'ngWord') lsWord[s] = '';
  3214. else if (s === 'ngId') lsId[s] = [];
  3215. else setting[s] = a;
  3216. }
  3217. };
  3218. if (!lsWord.ngWord) lsWord.ngWord = '';
  3219. if (!lsId.ngId) lsId.ngId = [];
  3220. setValue('reduceNavigation', 'Boolean', true);
  3221. setValue('hiddenButtonText', 'Boolean', true);
  3222. setValue('closeNotification', 'Boolean', false);
  3223. setValue('videoResolution', 'Boolean', true);
  3224. setValue('semiTransparent', 'Boolean', true);
  3225. setValue('smallFontSize', 'Boolean', true);
  3226. setValue('closeSidePanel', 'Boolean', true);
  3227. setValue('overlapSidePanel', 'Boolean', true);
  3228. setValue('sidePanelBackground', 'Boolean', true);
  3229. setValue('sidePanelCloseButton', 'Boolean', true);
  3230. setValue('showProgramDetail', 'Boolean', true);
  3231. setValue('sidePanelSize', 'Boolean', false);
  3232. setValue('sidePanelSizeNum', 'String', '320');
  3233. setValue('hiddenIdAndPlan', 'Boolean', true);
  3234. setValue('nextProgramInfo', 'Boolean', true);
  3235. setValue('recommendedSeriesInfo', 'Boolean', true);
  3236. setValue('skipVideo', 'Boolean', false);
  3237. setValue('headerPosition', 'Boolean', true);
  3238. setValue('videoPadding', 'Boolean', true);
  3239. setValue('dblclickScroll', 'Boolean', true);
  3240. setValue('mouseoverNavigation', 'Boolean', true);
  3241. setValue('newCommentOneByOne', 'Boolean', true);
  3242. setValue('scrollNewComment', 'Boolean', true);
  3243. setValue('stopCommentScroll', 'Boolean', true);
  3244. setValue('highlightNewComment', 'Boolean', true);
  3245. setValue('highlightFirstComment', 'Boolean', true);
  3246. setValue('commentFontSize', 'Boolean', false);
  3247. setValue('commentFontSizeNum', 'String', '13');
  3248. setValue('reduceCommentSpace', 'Boolean', true);
  3249. setValue('hiddenCommentList', 'Boolean', true);
  3250. setValue('hiddenCommentListNum', 'String', '50');
  3251. setValue('hiddenCommentListNum2', 'String', '');
  3252. setValue('escKey', 'Boolean', true);
  3253. setValue('enterKey', 'Boolean', true);
  3254. setValue('viewCounter', 'Boolean', false);
  3255. setValue('reportFormCommentList', 'Boolean', true);
  3256. setValue('qualityEnable', 'Boolean', true);
  3257. setValue('targetQuality', 'Number', 0);
  3258. setValue('ngWordEnable', 'Boolean', true);
  3259. setValue('ngWord', 'String', '');
  3260. setValue('ngIdMaxSize', 'Number', 0);
  3261. setValue('ngId', 'Array', '');
  3262. setValue('ngConsole', 'Boolean', false);
  3263. setValue('ngIdEnable', 'Boolean', true);
  3264. saveStorage();
  3265. };
  3266.  
  3267. /**
  3268. * 動画の解像度と表示領域サイズを調べて表示する
  3269. */
  3270. const showVideoResolution = () => {
  3271. clearTimeout(interval.resolution);
  3272. interval.resolution = setTimeout(() => {
  3273. const dpr = window.devicePixelRatio,
  3274. footer = document.querySelector(selector.footer),
  3275. vi = returnVideo(),
  3276. vr = document.getElementById(`${sid}_VideoResolution`),
  3277. ch = vi?.clientHeight,
  3278. cw = vi?.clientWidth,
  3279. vh = vi?.videoHeight,
  3280. vw = vi?.videoWidth;
  3281. if (vi && dpr && ch && cw && vh && vw) {
  3282. if (
  3283. video.pixelRatio !== dpr ||
  3284. video.clientHeight !== ch ||
  3285. video.clientWidth !== cw ||
  3286. video.videoHeight !== vh ||
  3287. video.videoWidth !== vw
  3288. ) {
  3289. log('showVideoResolution');
  3290. let desc = `動画解像度: ${vw${vh}`,
  3291. maxHeight = '';
  3292. if (/tv|le/.test(returnContentType())) {
  3293. const vt = returnVideoTracks();
  3294. if (vt?.qualities?.length > 1) {
  3295. maxHeight =
  3296. vt.qualities[0].height <= 240
  3297. ? vt.qualities[vt.qualities.length - 1].height
  3298. : vt.qualities[0].height;
  3299. }
  3300. if (maxHeight) desc += ` (Max: ${maxHeight}p)`;
  3301. }
  3302. desc += ` / 表示領域: ${cw${ch}`;
  3303. if (dpr !== 1) desc += ` * ${dpr}`;
  3304. if (vr) {
  3305. vr.innerText = desc;
  3306. } else {
  3307. const div = document.createElement('div');
  3308. div.id = `${sid}_VideoResolution`;
  3309. div.innerText = desc;
  3310. if (footer) footer.appendChild(div);
  3311. }
  3312. video.pixelRatio = dpr;
  3313. video.clientHeight = ch;
  3314. video.clientWidth = cw;
  3315. video.videoHeight = vh;
  3316. video.videoWidth = vw;
  3317. }
  3318. }
  3319. }, 100);
  3320. };
  3321.  
  3322. /**
  3323. * 指定時間だけ待機する
  3324. * @param {number} ms
  3325. * @returns
  3326. */
  3327. const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
  3328.  
  3329. /**
  3330. * ページを開いて動画が表示されたら1度だけ実行
  3331. */
  3332. const startFirstObserve = () => {
  3333. log('startFirstObserve');
  3334. document.addEventListener('keydown', checkKeyDown, true);
  3335. document.addEventListener('click', checkClick);
  3336. document.addEventListener('dblclick', checkDblclick);
  3337. const main = document.querySelector(selector.main);
  3338. if (main) {
  3339. observerE.observe(main, { childList: true, subtree: true });
  3340. observerT.observe(main, { childList: true });
  3341. } else log('startFirstObserve: Not found element.', 'warn');
  3342. };
  3343.  
  3344. /**
  3345. * 新着コメントを1つずつもしくは一気に表示する
  3346. * @param {HTMLElement} e コメントリストの親要素
  3347. * @param {string} t どのページを開いているか
  3348. */
  3349. const visibleComment = (e, t) => {
  3350. const clickContinueButton = () => {
  3351. /** @type {HTMLButtonElement|null} */
  3352. const cButton = document.querySelector(selector.commentContinue);
  3353. if (cButton) cButton.click();
  3354. };
  3355. if (setting.newCommentOneByOne) {
  3356. const hidden = document.querySelectorAll(selector.commentHidden),
  3357. time =
  3358. t === 'tv' || t === 'ts'
  3359. ? hidden.length > 7
  3360. ? (6.5 / hidden.length) * 1000
  3361. : 920
  3362. : t === 'le'
  3363. ? hidden.length > 5
  3364. ? (4.5 / hidden.length) * 1000
  3365. : 900
  3366. : 1000;
  3367. clearInterval(interval.newcomment);
  3368. interval.newcomment = setInterval(() => {
  3369. const ch = document.querySelector(selector.commentHidden),
  3370. rf = document.querySelector(selector.commentReport);
  3371. if (!rf && !data.commentMouseEnter) {
  3372. if (ch) {
  3373. /** @type {HTMLDivElement|null} */
  3374. const chi = ch.querySelector(selector.commentInner);
  3375. if (chi) chi.dataset[`${sid.toLowerCase()}Hidden`] = 'false';
  3376. if (e.scrollHeight - e.scrollTop - e.clientHeight < 500) {
  3377. if (setting.scrollNewComment && hidden.length < 30) {
  3378. e.scroll({
  3379. top: e.scrollHeight,
  3380. behavior: 'auto',
  3381. });
  3382. e.scrollBy({
  3383. top: -ch.clientHeight,
  3384. behavior: 'auto',
  3385. });
  3386. e.scrollBy({
  3387. top: ch.clientHeight + 1,
  3388. behavior: 'smooth',
  3389. });
  3390. } else {
  3391. e.scrollBy({
  3392. top: ch.clientHeight + 1,
  3393. behavior: 'auto',
  3394. });
  3395. }
  3396. clickContinueButton();
  3397. }
  3398. } else {
  3399. clearInterval(interval.newcomment);
  3400. if (e.scrollHeight - e.scrollTop - e.clientHeight < 500) {
  3401. if (setting.scrollNewComment && hidden.length < 30) {
  3402. e.scroll({
  3403. top: e.scrollHeight,
  3404. behavior: 'smooth',
  3405. });
  3406. } else {
  3407. e.scroll({
  3408. top: e.scrollHeight,
  3409. behavior: 'auto',
  3410. });
  3411. }
  3412. clickContinueButton();
  3413. }
  3414. }
  3415. }
  3416. }, time);
  3417. } else {
  3418. const ch = document.querySelectorAll(selector.commentHidden),
  3419. rf = document.querySelector(selector.commentReport);
  3420. if (ch.length && !rf && !data.commentMouseEnter) {
  3421. const ccb =
  3422. e.scrollHeight - e.scrollTop - e.clientHeight < 500 ? true : false;
  3423. for (let i = 0; i < ch.length; i++) {
  3424. /** @type {HTMLDivElement|null} */
  3425. const chi = ch[i].querySelector(selector.commentInner);
  3426. if (chi) chi.dataset[`${sid.toLowerCase()}Hidden`] = 'false';
  3427. }
  3428. if (ccb) clickContinueButton();
  3429. }
  3430. }
  3431. };
  3432.  
  3433. const observerC = new MutationObserver(checkNewComments),
  3434. observerE = new MutationObserver(changeElements),
  3435. observerR = new ResizeObserver(resizeVideo),
  3436. observerT = new MutationObserver(changePageTitle),
  3437. observerV = new MutationObserver(changeVideoSource);
  3438. clearInterval(interval.init);
  3439. interval.init = setInterval(() => {
  3440. if (document.querySelector(selector.main)) {
  3441. clearInterval(interval.init);
  3442. init();
  3443. }
  3444. }, 500);
  3445. })();