ABEMA Little Tools

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

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