Greasy Fork 还支持 简体中文。

* Streaming Comment Reader chan

It reads comment text on streaming sites by speech synthesis.

目前為 2020-02-24 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name * Streaming Comment Reader chan
  3. // @name:ja * 配信コメント読み上げちゃん
  4. // @name:zh-CN * 朗读直播评论酱
  5. // @namespace knoa.jp
  6. // @description It reads comment text on streaming sites by speech synthesis.
  7. // @description:ja ライブ配信サイトの新着コメントを音声で読み上げます。
  8. // @description:zh-CN 用声音朗读直播网站的新到来评论。
  9. // @include https://abema.tv/*
  10. // @include https://live.bilibili.com/*
  11. // @include https://www.douyu.com/*
  12. // @include https://live.fc2.com/*
  13. // @include https://www.huajiao.com/l/*
  14. // @include https://www.huya.com/*
  15. // @include http*://www.inke.cn/live*
  16. // @include https://live.line.me/channels/*/broadcast/*
  17. // @include https://live*.nicovideo.jp/watch/*
  18. // @include https://www.openrec.tv/live/*
  19. // @include https://www.pscp.tv/w/*
  20. // @include https://www.showroom-live.com/*
  21. // @include https://twitcasting.tv/*
  22. // @include https://www.twitch.tv/*
  23. // @include https://whowatch.tv/viewer/*
  24. // @include https://www.yizhibo.com/l/*
  25. // @include https://www.youtube.com/live_chat*
  26. // @include https://www.yy.com/*
  27. // @version 1.0.10
  28. // @grant none
  29. // ==/UserScript==
  30.  
  31. (function(){
  32. const SCRIPTID = 'StreamingCommentReader-chan';
  33. const SCRIPTNAME = 'Streaming Comment Reader chan';
  34. const DEBUG = false;/*
  35. [update] 1.0.10
  36. fix for Twitch, nicolive, Greasemonkey on Firefox, and minor fixes.
  37.  
  38. [to do]
  39. ニコニコ動画!!需要があるらしい
  40. https://greasyfork.org/ja/forum/discussion/63249/x
  41. しかし新着要素じゃないから一筋縄じゃダメだな
  42.  
  43. https://fanxing.kugou.com/
  44. iQiyi ?
  45. youku ?
  46. ニコ動ぽいサイト
  47. AcFun(A站)
  48. https://www.acfun.cn/
  49. bilibili(B站)
  50. https://www.bilibili.com/
  51. 吐槽弹幕网(C站)
  52. https://www.tucao.one/
  53. 5dm.tv(D站)
  54. https://www.5dm.tv/
  55. ひまわり動画
  56. SayMove!
  57. ニコ生ぽいサイト
  58. FC2ライブ
  59. DouYu
  60. https://www.douyu.com/
  61. HUYA
  62. https://www.huya.com/
  63. 火猫TV
  64. https://www.huomao.com/
  65. 龍珠直播
  66. http://longzhu.com/
  67.  
  68. [possible]
  69.  
  70. [research]
  71. ふわっち (デフォであるw)
  72. Flash:
  73. ドキドキ
  74. mirrativ
  75. BIGO
  76. */
  77. if(window === top && console.time) console.time(SCRIPTID);
  78. if(!('speechSynthesis' in window)) return console.log(SCRIPTID, 'speechSynthesis undefined.');
  79. const USERLANGUAGE = window.navigator.language;
  80. const SITELANGUAGE = document.documentElement.lang || USERLANGUAGE;
  81. const _TEXTS = {
  82. en: {
  83. scriptname: () => `${SCRIPTNAME}`,
  84. configs: () => `${SCRIPTNAME} configs`,
  85. test: () => 'Trial',
  86. text: () => 'this is a test ABC',
  87. speech: () => 'Speech',
  88. volume: () => 'volume',
  89. pitch: () => 'pitch',
  90. voice: () => 'voice',
  91. fast: () => 'When comments flow fast',
  92. fastest: () => 'fastest',
  93. buffer: () => 'catch up latest',
  94. bufferNote: () => '* To cut off more than this number of comments for catching up latest ones.',
  95. translators: () => 'Domain specific terms',
  96. translatorsEmpty: () => 'No terms available now.',
  97. dictionary: () => 'Replacement dictionary',
  98. dictionaryNote: () => '[/source(RegExp)/, \'destination\', \'memo(optional)\'],... as Array',
  99. professional: () => '(for professional)',
  100. ng: () => 'NG words',
  101. ngNote: () => 'comma(,) separated list',
  102. reset: () => 'reset',
  103. cancel: () => 'Cancel',
  104. save: () => 'Save',
  105. dictionaryParseError: () => `Replacement dictionary error:\nrequired ${TEXTS.dictionaryNote()},\nor you can reset all preferences.`,
  106. resetConfirmation: () => `All preferences will be reset to defaults. Are you sure?`,
  107. },
  108. ja: {
  109. scriptname: () => `配信コメント読み上げちゃん`,
  110. configs: () => `配信コメント読み上げちゃん 設定`,
  111. test: () => '試し読み',
  112. text: () => 'これはテストです ABC',
  113. speech: () => '読み上げの声',
  114. volume: () => '音量',
  115. pitch: () => '高さ',
  116. voice: () => '種類',
  117. fast: () => 'コメント混雑時',
  118. fastest: () => '速読み',
  119. buffer: () => '追いかけコメント数',
  120. bufferNote: () => '※これ以上古いコメントを切り捨てることで、読み上げがいつまでも追いつかなくなるのを防ぎます。',
  121. translators: () => '専門用語モード',
  122. translatorsEmpty: () => '専門用語が用意されていません。',
  123. dictionary: () => '置換辞書',
  124. dictionaryNote: () => '[/置換元(正規表現)/, \'置換先\', \'メモ(任意)\'],... の配列',
  125. professional: () => '(上級者向け)',
  126. ng: () => 'NGワード',
  127. ngNote: () => 'カンマ(,)区切りのリスト',
  128. reset: () => 'リセット',
  129. cancel: () => 'キャンセル',
  130. save: () => '保存',
  131. dictionaryParseError: () => `置換辞書の形式が正しくありません:\n${TEXTS.dictionaryNote()}にするか、\nまたは全ての設定値をリセットしてください。`,
  132. resetConfirmation: () => 'すべての設定が初期化されます。よろしいですか?',
  133. },
  134. zh: {
  135. scriptname: () => `发布评论朗读`,
  136. configs: () => `发布评论阅读设置`,
  137. test: () => '试读',
  138. text: () => '这是测试ABC',
  139. speech: () => '朗读的声音',
  140. volume: () => '音量',
  141. pitch: () => '高度',
  142. voice: () => '种类',
  143. fast: () => '评论拥挤时',
  144. fastest: () => '速读',
  145. buffer: () => '追随评论数',
  146. bufferNote: () => '※通过舍弃更旧的评论,防止朗读永远跟不上。',
  147. translators: () => '术语模式',
  148. translatorsEmpty: () => '未提供专业术语',
  149. dictionary: () => '替换词典',
  150. dictionaryNote: () => '[/替换自(正则表达式)/, \'替换为\', \'注释(可选)\'],... 的数组。',
  151. professional: () => '(高级)',
  152. ng: () => 'NG字',
  153. ngNote: () => '以逗号(,)分隔的列表',
  154. reset: () => '重置',
  155. cancel: () => '取消',
  156. save: () => '保存',
  157. dictionaryParseError: () => `替换词典的格式不正确: \n${TEXTS.dictionaryNote()},或者\n将所有的设定值复位。`,
  158. resetConfirmation: () => '所有设置都将被初始化。可以吗?',
  159. },
  160. };
  161. const TEXTS = _TEXTS[USERLANGUAGE] || _TEXTS[USERLANGUAGE.substring(0, 2)] || _TEXTS.en;
  162. const _DICTIONARIES = {
  163. /* 置換元, 置換先, 説明(任意) */
  164. en: {
  165. default: [
  166. [/http:\/\/[^\s]+/, 'URL'],
  167. ],
  168. },
  169. ja: {
  170. default: [
  171. [/http:\/\/[^\s]+/, 'URL'],
  172. [/[88]{3,}/, 'パチパチパチ'],
  173. [/[ww]{3,}/, 'ワラワラワラ'],
  174. [/[ww]{2}/, 'ワラワラ'],
  175. [/[ww]$/, 'ワラ', '文末のみ1文字でも'],
  176. [/w/g, 'ワラ', '全角のみ1文字でも'],
  177. [/(.{1})\1{4,}/ug, '$1$1$1$1$1', '1文字の5回以上の繰り返しはカット'],
  178. [/(.{2})\1{3,}/ug, '$1$1$1$1', '2文字の4回以上の繰り返しはカット'],
  179. [/(.{3})\1{2,}/ug, '$1$1', '3文字の3回以上の繰り返しはカット'],
  180. [/(.{4,})\1{1,}/ug, '$1', '4文字以上の繰り返しはカット'],
  181. [/([あ-ん~])[~〜]/g, '$1ー', 'から => 長音'],
  182. [/はよ$/, 'ハヨ'],
  183. [/初見/, 'ショケン'],
  184. [/AbemaTV/, 'アベマティーヴィー'],
  185. [/Abema/, 'アベマ'],
  186. [/ニコ生/, 'ニコナマ'],
  187. ],
  188. nicolive: [
  189. [/^(【広告貢献[0-9]位】)?(.+)さんが([0-9]+)ptニコニ広告しました(「(.+)」)?$/, '$1、$2さんが、$3ポイント、ニコニ広告しました。$4。'],
  190. [/^(【ニコニコ新市場】)「(.+)」が貼られました$/, '$1、$2、が貼られました'],
  191. ],
  192. }
  193. };
  194. const DICTIONARIES = _DICTIONARIES[SITELANGUAGE] || _DICTIONARIES[SITELANGUAGE.substring(0, 2)] || _DICTIONARIES.en;
  195. const _TRANSLATORS = {
  196. en: {
  197. },
  198. ja: {
  199. '将棋': (text) => {
  200. // 文字入力の変換用辞書として公開されているデータがあるが採用保留
  201. // https://github.com/knu/imedic-shogi/blob/master/shogi.vje.txt
  202. const POSITIONS = [
  203. [/[11一]/g, 'イチ'],
  204. [/[22二]/g, 'ニー'],
  205. [/[33三]/g, 'サン'],
  206. [/[44四]/g, 'ヨン'],
  207. [/[55五]/g, 'ゴー'],
  208. [/[66六]/g, 'ロク'],
  209. [/[77七]/g, 'ナナ'],
  210. [/[88八]/g, 'ハチ'],
  211. [/[99九]/g, 'キュー'],
  212. ];
  213. const PIECES = [
  214. [/王/, 'オー'],
  215. [/玉/, 'ギョク'],
  216. [/飛車/, 'ヒシャ'],
  217. [/飛/, 'ヒ'],
  218. [/角/, 'カク'],
  219. [/金/, 'キン'],
  220. [/銀/, 'ギン'],
  221. [/桂馬/, 'ケーマ'],
  222. [/桂/, 'ケー'],
  223. [/香/, 'キョー'],
  224. [/歩/, 'フ'],
  225. [/龍|竜/, 'リュー'],
  226. [/馬/, 'ウマ'],
  227. [/不成/, 'ナラズ'],
  228. [/成(?![ら-ろ])/, 'ナリ'],
  229. [/と/, 'ト'],
  230. [/同/, 'ドウ'],
  231. [/打(?![た-とっ])/, 'ウツ'],
  232. [/右/, 'ミギ'],
  233. [/左/, 'ヒダリ'],
  234. [/上/, 'アガル'],
  235. [/寄(?![ら-ろっ])/, 'ヨル'],
  236. [/引(?![か-こっ])/, 'ヒク'],
  237. [/直/, 'スグ'],
  238. ];
  239. const MOVES = [{
  240. regexp: /([1-91-9])([1-91-9一二三四五六七八九])([王玉飛車角金銀桂香歩龍竜馬成と同不打右左上寄引直]+)[あ-んっ+−\+\-]?/g,
  241. replacement: [...POSITIONS, ...PIECES],
  242. }, {
  243. regexp: /([1-91-9])([1-91-9一二三四五六七八九])(?=[あ-ん指取成走入跳突叩攻守]|$)/g,
  244. replacement: [...POSITIONS],
  245. }, {
  246. regexp: /([王玉飛車角金銀桂香歩龍竜馬成と同不打右左上寄引直]{2,})[あ-んっ]?/g,
  247. replacement: [...PIECES],
  248. }];
  249. const MODIFICATIONS = [
  250. /* 固有名詞 */
  251. [/大山/g, 'オーヤマ'],
  252. [/中原/g, 'ナカハラ'],
  253. [/米長/g, 'ヨネナガ'],
  254. [/一二三/g, 'ヒフミ'],
  255. [/羽生/g, 'ハブ'],
  256. [/豊島/g, 'トヨシマ'],
  257. [/天彦/g, 'アマヒコ'],
  258. [/太地/g, 'タイチ'],
  259. [/高見/g, 'タカミ'],
  260. [/光瑠/g, 'コール'],
  261. [/聡ちゃん/g, 'ソーチャン'],
  262. [/香奈/g, 'カナ'],
  263. [/貞升/g, 'サダマス'],
  264. [/桂香(?=ちゃん)/g, 'ケーカ'],
  265. [/(K|K)太/ig, 'ケータ'],
  266. [/イトシン(TV|TV)/ig, 'イトシンティーヴィー'],
  267. [/朝日杯/, 'アサヒハイ'],
  268. [/NHK杯/, 'エネーチケーハイ'],
  269. [/JT杯/, 'ジェーティーハイ'],
  270. [/棋神/, 'キシン'],
  271. [/激指/, 'ゲキサシ'],
  272. [/elmo/, 'エルモ'],
  273. /* 用語 */
  274. [/評価値/, 'ヒョーカチ'],
  275. [/候補手/, 'コーホシュ'],
  276. [/AI/, 'エーアイ'],
  277. [/将棋星人/, 'ショーギセージン'],
  278. [/級位者/, 'キューイシャ'],
  279. [/先手|▲|☗/g, 'センテ'],
  280. [/後手|△|☖/g, 'ゴテ'],
  281. [/一手/g, 'イッテ'],
  282. [/早指し/, 'ハヤザシ'],
  283. [/早逃げ/, 'ハヤニゲ'],
  284. [/最善手/, 'サイゼンシュ'],
  285. [/次善手/, 'ジゼンシュ'],
  286. [/疑問手/, 'ギモンシュ'],
  287. [/筋悪/, 'スジワル'],
  288. [/長手数/, 'チョーテスー'],
  289. [/余詰(め)?/, 'ヨヅメ'],
  290. [/合(い)?駒/, 'アイゴマ'],
  291. [/中合(い)?/, 'チューアイ'],
  292. [/[11一]筋/, 'イチスジ'],
  293. [/[22二]筋/, 'ニスジ'],
  294. [/([1-91-9一-九])冠/, '$1カン'],
  295. [/\s対\s/, ' タイ '],
  296. [/vs|vs/, 'ブイエス'],
  297. [/大盤/, 'オーバン'],
  298. [/昼休/, 'チューキュー'],
  299. [/夕休/, 'ユーキュー'],
  300. [/盤外戦/, 'バンガイセン'],
  301. [/中継/, 'チューケー'],
  302. /* 戦型 */
  303. [/定跡(型|形)/, 'ジョーセキケー'],
  304. [/力戦(型|形)/, 'リキセンケー'],
  305. [/対抗(型|形)/, 'タイコーケー'],
  306. [/理想(型|形)/, 'リソーケー'],
  307. [/急戦/, 'キューセン'],
  308. [/戦型/, 'センケー'],
  309. [/右玉/, 'ミギギョク'],
  310. [/相居(飛車|ヒシャ)/, 'アイイビシャ'],
  311. [/相(掛|懸)(かり)?/, 'アイガカリ'],
  312. [/横歩取り/, 'ヨコフドリ'],
  313. [/居(飛車|ヒシャ)/, 'イビシャ'],
  314. [/振(り)?(飛車|ヒシャ)/, 'フリビシャ'],
  315. [/中(飛車|ヒシャ)/, 'ナカビシャ'],
  316. [/四間(飛車|ヒシャ)/, 'シケンビシャ'],
  317. [/四間/, 'シケン'],
  318. [/三間(飛車|ヒシャ)/, 'サンケンビシャ'],
  319. [/三間/, 'サンケン'],
  320. [/向(かい)?(飛車|ヒシャ)/, 'ムカイビシャ'],
  321. [/早石田/, 'ハヤイシダ'],
  322. [/角(換|替)わり/, 'カクガワリ'],
  323. [/角交換/, 'カクコーカン'],
  324. [/一手損/, 'イッテゾン'],
  325. /* 囲い */
  326. [/居玉/, 'イギョク'],
  327. [/中住まい/, 'ナカズマイ'],
  328. [/(舟|船)囲い/, 'フナガコイ'],
  329. [/(ビッグ|big)(4|4)/i, 'ビッグフォー'],
  330. [/左美濃/, 'ヒダリミノ'],
  331. [/高美濃/, 'タカミノ'],
  332. [/金無双/, 'キンムソー'],
  333. /* 駒(1文字は特に最後へ) */
  334. [/大駒/, 'オーゴマ'],
  335. [/金駒/, 'カナゴマ'],
  336. [/小駒/, 'コゴマ'],
  337. [/玉頭/, 'ギョクトー'],
  338. [/王手(飛車|ヒシャ)/, 'オーテビシャ'],
  339. [/角頭/, 'カクトー'],
  340. [/桂頭/, 'ケートー'],
  341. [/二歩/, 'ニフ'],
  342. [/と金/, 'とキン'],
  343. [/金底の歩/, 'キンゾコのフ'],
  344. [/玉/g, 'ギョク'],/*(?<!埼)*/
  345. [/角/g, 'カク'],
  346. [/金/g, 'キン'],/*(?<!お)*/
  347. [/桂馬/g, 'ケーマ'],
  348. [/桂/g, 'ケー'],
  349. [/香車/g, 'キョーシャ'],
  350. [/香(?![っらりるれろ])/g, 'キョー'],
  351. [/歩(?![いかきくけこ])/g, 'フ'],
  352. /* 評価値 */
  353. [/[+\+]([0-9]+)/g, 'プラス$1'],
  354. [/[−\-]([0-9]+)/g, 'マイナス$1'],
  355. ];
  356. /* 棋譜と符号 */
  357. MOVES.forEach(p => {
  358. let tes = text.match(p.regexp);
  359. if(tes !== null) tes.forEach(te => {
  360. let yomi = te;
  361. p.replacement.forEach(p => yomi = yomi.replace(p[0], p[1]));
  362. text = text.replace(te, yomi);
  363. });
  364. });
  365. /* 用語 */
  366. MODIFICATIONS.forEach(m => text = text.replace(m[0], m[1]));
  367. return text;
  368. },
  369. },
  370. };
  371. const TRANSLATORS = _TRANSLATORS[SITELANGUAGE] || _TRANSLATORS[SITELANGUAGE.substring(0, 2)] || _TRANSLATORS.en;
  372. const UNKNOWNPITCHRATIO = .5;/* 不明コメントのピッチ係数 */
  373. const RETRY = 10;
  374. let sites = {
  375. abema: {
  376. id: 'abema',
  377. url: /^https:\/\/abema\.tv/,
  378. reverse: false,
  379. insertBefore: false,
  380. targets: {
  381. board: () => $('.com-a-OnReachTop > div'),
  382. settingAnchor: () => $('.com-tv-TVController__volume'),
  383. },
  384. addedNodes: {
  385. name: (node) => null,
  386. content: (node) => node.querySelector('div > p > span'),
  387. read: [
  388. [1.0, (node) => (node.querySelector('time[datetime]') !== null)],
  389. ],
  390. ignore: [],
  391. }
  392. },
  393. bilibili: {
  394. id: 'bilibili',
  395. url: /^https:\/\/live\.bilibili\.com\/[0-9]+/,
  396. reverse: false,
  397. insertBefore: false,
  398. targets: {
  399. board: () => $('#chat-history-list'),
  400. settingAnchor: () => $('.icon-right-part > *:last-child'),
  401. },
  402. addedNodes: {
  403. name: (node) => node.querySelector('.user-name'),
  404. content: (node) => node.querySelector('.danmaku-content'),
  405. read: [
  406. [1.500, (node) => node.classList.contains('guard-level-1')],
  407. [1.250, (node) => node.classList.contains('guard-level-2')],
  408. [1.125, (node) => node.classList.contains('guard-danmaku')],
  409. [1.000, (node) => node.classList.contains('danmaku-item')],
  410. ],
  411. ignore: [
  412. [0.0, (node) => node.classList.contains('system-msg')],
  413. [0.0, (node) => node.classList.contains('welcome-msg')],
  414. ],
  415. }
  416. },
  417. douyu: {
  418. id: 'douyu',
  419. url: /^https:\/\/www\.douyu\.com\/.+/,
  420. reverse: false,
  421. insertBefore: false,
  422. targets: {
  423. board: () => $('#js-barrage-list'),
  424. settingAnchor: () => $('.ChatToolBar > *:last-child'),
  425. },
  426. addedNodes: {
  427. name: (node) => node.querySelector('.Barrage-nickName'),
  428. content: (node) => node.querySelector('.Barrage-content'),
  429. read: [
  430. [1.25, (node) => (node.querySelector('.Barrage-message') !== null)],
  431. [1.00, (node) => (node.querySelector('.Barrage-notice--normalBarrage') !== null)],
  432. ],
  433. ignore: [
  434. [0.0, (node) => (node.querySelector('.Barrage-userEnter') !== null)],
  435. [0.0, (node) => (node.querySelector('.Barrage-notice') !== null)],
  436. ],
  437. }
  438. },
  439. fc2: {
  440. id: 'fc2',
  441. url: /^https:\/\/live\.fc2\.com\/[0-9]+/,
  442. reverse: false,
  443. insertBefore: true,
  444. targets: {
  445. board: () => $('#js-commentListContainer'),
  446. settingAnchor: () => $('.chat_tab-control > *:first-child'),
  447. },
  448. addedNodes: {
  449. name: (node) => node.querySelector('.js-commentUserName'),
  450. content: (node) => node.querySelector('.js-commentText'),
  451. read: [
  452. [1.0, (node) => node.classList.contains('js-commentLine')],
  453. ],
  454. ignore: [],
  455. }
  456. },
  457. huajiao: {
  458. id: 'huajiao',
  459. url: /^https:\/\/www\.huajiao\.com\/l\/[0-9]+/,
  460. reverse: false,
  461. insertBefore: true,
  462. targets: {
  463. board: () => $('.tt-msg-list'),
  464. settingAnchor: () => $('.tt-type-form'),
  465. },
  466. addedNodes: {
  467. name: (node) => node.querySelector('.tt-msg-nickname'),
  468. content: (node) => node.querySelector('.tt-msg-content-h5'),
  469. read: [
  470. [1.0, (node) => node.classList.contains('.tt-msg-message')],
  471. ],
  472. ignore: [],
  473. }
  474. },
  475. huya: {
  476. id: 'huya',
  477. url: /^https:\/\/www\.huya\.com\/.+/,
  478. reverse: false,
  479. insertBefore: true,
  480. targets: {
  481. board: () => $('#chat-room__list'),
  482. settingAnchor: () => $('.room-chat-tools > *:first-child'),
  483. },
  484. addedNodes: {
  485. name: (node) => node.querySelector('.name'),
  486. content: (node) => node.querySelector('.msg'),
  487. read: [
  488. [1.25, (node) => (node.querySelector('.msg-nobleSpeak') !== null)],
  489. [1.00, (node) => (node.querySelector('.msg') !== null)],
  490. ],
  491. ignore: [
  492. [0.0, (node) => (node.querySelector('.msg-nobleEnter') !== null)],
  493. ],
  494. }
  495. },
  496. inke: {
  497. id: 'inke',
  498. url: /^https?:\/\/www\.inke\.cn\/live.+/,
  499. reverse: false,
  500. insertBefore: true,
  501. targets: {
  502. board: () => $('.comments_list > ul'),
  503. settingAnchor: () => $('.comments_box > input[type="text"]'),
  504. },
  505. addedNodes: {
  506. name: (node) => node.querySelector('li > span'),
  507. content: (node) => node.querySelector('.comments_text') || node.querySelector('.comments_gift'),
  508. read: [
  509. [1.0, (node) => (node.querySelector('img + span + span.comments_text') !== null)],
  510. [1.0, (node) => (node.querySelector('img + span + span.comments_gift') !== null)],
  511. ],
  512. ignore: [],
  513. },
  514. },
  515. line: {
  516. id: 'line',
  517. url: /^https:\/\/live\.line\.me\/channels\/[0-9]+\/broadcast\/[0-9]+/,
  518. reverse: false,
  519. insertBefore: false,
  520. targets: {
  521. board: () => $('[class*="Comment"] > div + div > [class*="Scroll"]'),
  522. settingAnchor: () => $('[class*="Notice"] > [class*="Desc"] > span'),
  523. },
  524. addedNodes: {
  525. name: (node) => node.querySelector('[class*="Head"]'),
  526. content: (node) => node.querySelector('[class*="Heart"]') || node.querySelector('[class*="Desc"]') || node,
  527. read: [
  528. [1.0, (node) => node.className.includes('Label')],
  529. [1.0, (node) => node.className.includes('Chat')],
  530. ],
  531. ignore: [],
  532. }
  533. },
  534. nicolive: {
  535. id: 'nicolive',
  536. url: /^https:\/\/live[0-9]+\.nicovideo\.jp\/watch\/[a-z]+[0-9]+/,
  537. reverse: false,
  538. insertBefore: false,
  539. targets: {
  540. board: () => $('[class*="_comment-panel_"] [class*="_table_"]'),
  541. settingAnchor: () => $('[class*="_setting-button_"]'),
  542. },
  543. addedNodes: {
  544. name: (node) => node.querySelector('[class*="_comment-author-name_"]'),
  545. content: (node) => node.querySelector('[class*="_comment-text_"]'),
  546. read: [
  547. [1.0, (node) => (node.dataset.commentType === 'nicoad')],
  548. [1.0, (node) => (node.dataset.commentType === 'normal')],
  549. [0.9, (node) => (node.dataset.commentType === 'trialWatch')],
  550. [0.5, (node) => (node.dataset.commentType === 'operator')],
  551. ],
  552. ignore: [],
  553. }
  554. },
  555. openrec: {
  556. id: 'openrec',
  557. url: /^https:\/\/www\.openrec\.tv\/live\/.+/,
  558. reverse: false,
  559. insertBefore: true,
  560. targets: {
  561. board: () => $('.chat-list-content'),
  562. settingAnchor: () => $('[class*="InputArea__ToolbarItem-"]'),
  563. },
  564. addedNodes: {
  565. name: (node) => node.querySelector('[class*="UserName__Name-"]'),
  566. content: (node) => node.querySelector('.chat-content'),
  567. read: [
  568. [1.0, (node) => node.className.includes('ChatList__CellContainer-')],
  569. ],
  570. ignore: [
  571. [0.0, (node) => node.className.includes('system-chat')],
  572. ],
  573. }
  574. },
  575. periscope: {
  576. id: 'periscope',
  577. url: /^https:\/\/www\.pscp\.tv\/w\/.+/,
  578. reverse: false,
  579. insertBefore: false,
  580. targets: {
  581. board: () => $('.Chat > div[style] > div[style]'),
  582. settingAnchor: () => $('.VideoOverlayRedesign-BottomBar-Right > *:last-child'),
  583. },
  584. addedNodes: {
  585. name: (node) => node.querySelector('.CommentMessage-username'),
  586. content: (node) => node.querySelector('.CommentMessage-message'),
  587. read: [
  588. [1.0, (node) => (node.querySelector('.CommentMessage') !== null)],
  589. ],
  590. ignore: [
  591. [0.0, (node) => (node.querySelector('.ParticipantMessage') !== null)],
  592. ],
  593. }
  594. },
  595. showroom: {
  596. id: 'showroom',
  597. url: /^https:\/\/www\.showroom-live\.com\/.+/,
  598. reverse: true,
  599. insertBefore: true,
  600. targets: {
  601. board: () => $('#room-comment-log-list'),
  602. settingAnchor: () => $('#js-room-head-other-select-box').parentNode,
  603. },
  604. addedNodes: {
  605. name: (node) => node.querySelector('.comment-log-name'),
  606. content: (node) => node.querySelector('.comment-log-comment'),
  607. read: [
  608. [1.0, (node) => node.classList.contains('commentlog-row')],
  609. ],
  610. ignore: [],
  611. }
  612. },
  613. twitcasting: {
  614. id: 'twitcasting',
  615. url: /^https:\/\/twitcasting\.tv\/.+/,
  616. reverse: true,
  617. insertBefore: false,
  618. targets: {
  619. board: () => $('.tw-player-comment-list'),
  620. settingAnchor: () => $('#commentnumarea'),
  621. },
  622. addedNodes: {
  623. name: (node) => node.querySelector('.tw-comment-item-name'),
  624. content: (node) => node.querySelector('.tw-comment-item-comment'),
  625. read: [
  626. [1.0, (node) => node.className.includes('tw-comment-item')],
  627. ],
  628. ignore: [],
  629. }
  630. },
  631. twitch: {
  632. id: 'twitch',
  633. url: /^https:\/\/www\.twitch\.tv/,
  634. reverse: false,
  635. insertBefore: true,
  636. targets: {
  637. board: () => $('[role="log"]'),
  638. settingAnchor: () => $('.chat-input__buttons-container [aria-describedby]'),
  639. },
  640. addedNodes: {
  641. name: (node) => node.querySelector('.chat-author__display-name'),
  642. content: (node) => node.querySelector('.text-fragment'),
  643. read: [
  644. [1.0, (node) => node.className.includes('chat-line__message')],
  645. ],
  646. ignore: [],
  647. }
  648. },
  649. whowatch: {
  650. id: 'whowatch',
  651. url: /^https:\/\/whowatch\.tv\/viewer\/[0-9]+/,
  652. reverse: true,
  653. insertBefore: true,
  654. targets: {
  655. board: () => $('.normal-comment-list > div'),
  656. settingAnchor: () => $('.limit'),
  657. },
  658. addedNodes: {
  659. name: (node) => node.querySelector('.user-name'),
  660. content: (node) => node.querySelector('.message'),
  661. read: [
  662. [1.0, (node) => node.classList.contains('comment-box')],
  663. ],
  664. ignore: [],
  665. },
  666. },
  667. yizhibo: {
  668. id: 'yizhibo',
  669. url: /^https:\/\/www\.yizhibo\.com\/l\/.+/,
  670. reverse: false,
  671. insertBefore: true,
  672. targets: {
  673. board: () => $('#J_msglist'),
  674. settingAnchor: () => $('#J_send_danmu'),
  675. },
  676. addedNodes: {
  677. name: (node) => node.querySelector('.nickname'),
  678. content: (node) => node.querySelector('.content'),
  679. read: [
  680. [1.0, (node) => node.classList.contains('msg_1')],
  681. ],
  682. ignore: [
  683. [0.0, (node) => node.classList.contains('msg_2')],
  684. [0.0, (node) => node.classList.contains('msg_3')],
  685. ],
  686. },
  687. },
  688. youtube: {
  689. id: 'youtube',
  690. url: /^https:\/\/www\.youtube\.com\/live_chat/,
  691. reverse: false,
  692. insertBefore: true,
  693. targets: {
  694. board: () => $('#item-offset > #items'),
  695. settingAnchor: () => $('yt-live-chat-header-renderer yt-icon-button'),
  696. },
  697. addedNodes: {
  698. name: (node) => node.querySelector('#author-name'),
  699. content: (node) => node.querySelector('#message'),
  700. read: [
  701. [1.5, (node) => (node.localName === 'yt-live-chat-paid-message-renderer'), 'スパチャ'],
  702. [1.0, (node) => node.classList.contains('yt-live-chat-item-list-renderer')],
  703. ],
  704. ignore: [
  705. [0.0, (node) => (node.localName === 'yt-live-chat-viewer-engagement-message-renderer')],
  706. ],
  707. },
  708. },
  709. yy: {
  710. id: 'yy',
  711. url: /^https:\/\/www\.yy\.com\/[0-9]+\/[0-9]+/,
  712. reverse: false,
  713. insertBefore: false,
  714. targets: {
  715. board: () => $('.chatroom-list'),
  716. settingAnchor: () => $('.chat-room-ft'),
  717. },
  718. addedNodes: {
  719. name: (node) => node.querySelector('.nickname'),
  720. content: (node) => node.querySelector('.nickname + span'),
  721. read: [
  722. [1.0, (node) => node.classList.contains('phizbox')],
  723. ],
  724. ignore: [],
  725. },
  726. },
  727. };
  728. class Configs{
  729. constructor(configs){
  730. Configs.DICTIONARY = [...DICTIONARIES.default, ...(DICTIONARIES[site.id] || [])];
  731. Configs.TRANSLATORS = Object.keys(TRANSLATORS);
  732. Configs.PROPERTIES = {
  733. text: {type: 'string', default: TEXTS.text()},
  734. volume: {type: 'int', default: 25},/* 0-100 => 0.0-1.0 */
  735. pitch: {type: 'int', default: 100},/* 0-200 => 0.0-2.0 */
  736. voice: {type: 'string', default: ''},/* name of voice */
  737. fastest: {type: 'int', default: 150},/* 100-250 => 1.0-2.5 */
  738. buffer: {type: 'int', default: 5},/* 1- 25 */
  739. dictionary: {type: 'array', default: Configs.DICTIONARY},/* replacement pairs */
  740. translators: {type: 'array', default: []},/* name of translators */
  741. ngs: {type: 'array', default: []},/* ng word list */
  742. };
  743. this.data = this.read(configs || {});
  744. }
  745. read(configs){
  746. let newConfigs = {};
  747. Object.keys(Configs.PROPERTIES).forEach(key => {
  748. if(configs[key] === undefined) return newConfigs[key] = Configs.PROPERTIES[key].default;
  749. if(key === 'dictionary') return newConfigs[key] = configs[key].map(entry => {
  750. if(entry[0] instanceof RegExp) return entry;
  751. let parts = entry[0].match(/^\/(.*)\/([a-z]*)$/);
  752. if(parts === null) entry[0] = new RegExp(entry[0]);
  753. else entry[0] = new RegExp(parts[1], parts[2]);
  754. return entry;
  755. });
  756. switch(Configs.PROPERTIES[key].type){
  757. case('bool'): return newConfigs[key] = (configs[key]) ? 1 : 0;
  758. case('int'): return newConfigs[key] = parseInt(configs[key]);
  759. case('float'): return newConfigs[key] = parseFloat(configs[key]);
  760. default: return newConfigs[key] = configs[key];
  761. }
  762. });
  763. return newConfigs;
  764. }
  765. toJSON(){
  766. let json = {};
  767. Object.keys(this.data).forEach(key => {
  768. switch(key){
  769. case('dictionary'):
  770. return json[key] = this.data[key].map(entry => {
  771. if(entry[2] === undefined) return [entry[0].toString(), entry[1]];
  772. else return [entry[0].toString(), entry[1], entry[2]];
  773. });
  774. default:
  775. return json[key] = this.data[key];
  776. }
  777. });
  778. return json;
  779. }
  780. parseDictionaryString(string){
  781. let wrapper = string.trim().match(/^\[([\S\s]+)\]$/);
  782. if(wrapper === null) return false;
  783. let entries = wrapper[1].trim().match(/\[(.+)\]\s*,/g);
  784. if(entries === null) return false;
  785. let lines = wrapper[1].trim().match(/.{3,}(\n|$)/g);
  786. if(lines.length !== entries.length) return false;
  787. let dictionary = [];
  788. for(let i = 0; entries[i]; i++){
  789. let parts = entries[i].trim().match(/\[\s*\/(.*)\/([a-z]*)\s*,\s*'(.*?[^\\])'(?:\s*,\s*'(.*[^\\])')?\s*\]\s*,/);
  790. if(parts === null) return false;
  791. dictionary[i] = [new RegExp(parts[1], parts[2]), parts[3]];
  792. if(parts[4] !== undefined) dictionary[i].push(parts[4]);
  793. }
  794. return dictionary;
  795. }
  796. parseNgsString(string){
  797. if(string.trim() === '') return [];
  798. else return string.trim().split(',').map(s => s.trim());
  799. }
  800. get text(){return this.data.text;}
  801. get volume(){return this.data.volume / 100;}
  802. get pitch(){return this.data.pitch / 100;}
  803. get voice(){return this.data.voice;}
  804. get fastest(){return this.data.fastest / 100;}
  805. get buffer(){return this.data.buffer;}
  806. get dictionary(){return this.data.dictionary;}
  807. get translators(){return this.data.translators;}
  808. get ngs(){return this.data.ngs;}
  809. get dictionaryString(){
  810. let dictionary = this.data.dictionary, string = '';
  811. let quote = (s) => '\'' + s.replace('\'', '\\\'') + '\'';
  812. dictionary.forEach(entry => {
  813. string += ' [';
  814. string += entry[0].toString();
  815. string += ', ';
  816. string += quote(entry[1]);
  817. if(entry[2] !== undefined){
  818. string += ', ';
  819. string += quote(entry[2]);
  820. }
  821. string += '],\n';
  822. });
  823. return '[\n' + string + ']';
  824. }
  825. get ngsString(){
  826. return this.data.ngs.join(',');
  827. }
  828. }
  829. class Speaker{
  830. constructor(configs){
  831. Speaker.TRANSLATORS = TRANSLATORS;
  832. this.speechSynthesis = speechSynthesis;
  833. this.voices = this.getVoices();
  834. this.configs = configs;
  835. this.queue = [];
  836. this.interval = 250;
  837. }
  838. getVoices(){
  839. let voices = {}, array = this.speechSynthesis.getVoices();
  840. if(array.length) array.forEach(v => voices[v.name] = v);
  841. else this.speechSynthesis.addEventListener('voiceschanged', () => this.voices = this.getVoices());
  842. return voices;
  843. }
  844. request(text, ratio, node){
  845. let utterance = new SpeechSynthesisUtterance(this.modify(text));
  846. utterance.pitch = this.configs.pitch * ratio;
  847. utterance.node = node;
  848. this.queue.push(utterance);
  849. if(this.queue.length === 1){/* 2個以上あるならすでに連続発話が始まっている */
  850. setTimeout(() => this.speak(), 0);/* 一度に複数リクエストを受け取った際に合計数をrateに反映させたい */
  851. }
  852. }
  853. modify(text){
  854. this.configs.dictionary.forEach(d => text = text.replace(d[0], d[1]));
  855. this.configs.translators.forEach(key => text = Speaker.TRANSLATORS[key](text));
  856. return text;
  857. }
  858. speak(){
  859. if(this.queue.length === 0) return;
  860. if(this.configs.ngs.some(ng => this.queue[0].text.includes(ng))) return this.queue.shift(), this.speak();
  861. if(this.queue.length > this.configs.buffer) this.queue = this.queue.slice(-this.configs.buffer);/*古いものは切り捨てる*/
  862. let utterance = this.queue[0];
  863. utterance.volume = this.configs.volume;
  864. utterance.rate = 1 + ((this.queue.length - 1) / ((this.configs.buffer - 1) || 1))*(this.configs.fastest - 1);
  865. utterance.voice = this.voices[this.configs.voice];
  866. utterance.node.dataset.speaking = 'true';
  867. utterance.addEventListener('end', (e) => {
  868. utterance.node.dataset.speaking = 'false';
  869. this.queue.shift();
  870. if(this.queue.length) setTimeout(() => this.speak(), this.interval);
  871. });
  872. log(utterance);
  873. this.speechSynthesis.speak(utterance);
  874. }
  875. cancel(){
  876. this.queue = [];
  877. this.speechSynthesis.cancel();
  878. }
  879. test(text, volume, pitch, voice, rate){
  880. let utterance = new SpeechSynthesisUtterance(this.modify(text));
  881. utterance.volume = volume;
  882. utterance.pitch = pitch;
  883. utterance.voice = this.voices[voice];
  884. utterance.rate = rate;
  885. this.speechSynthesis.speak(utterance);
  886. log('Test:', text, '=>', utterance.text);
  887. }
  888. }
  889. let html, elements = {}, timers = {}, site, configs, speaker;
  890. let core = {
  891. initialize: function(){
  892. html = document.documentElement;
  893. html.classList.add(SCRIPTID);
  894. core.site(RETRY);
  895. },
  896. site: function(retry){
  897. site = sites[Object.keys(sites).find(key => sites[key].url.test(location.href))];
  898. if(site === undefined) return log('Doesn\'t match any sites:', location.href);
  899. core.read();
  900. core.observeElements();
  901. core.addStyle();
  902. core.addStyle(site.id);
  903. core.addStyle('stylePanels', window.top.document);
  904. },
  905. observeElements: function(){
  906. /* 開閉する要素に対応。結局インターバルがいちばん負荷が軽い */
  907. setInterval(function(){
  908. new Promise(function(resolve, reject){
  909. if(elements.settingAnchor && elements.settingAnchor.isConnected) return resolve();
  910. elements.settingAnchor = site.targets.settingAnchor();
  911. if(elements.settingAnchor){
  912. core.configs.createButton();
  913. log("Configs button ready.");
  914. return resolve();
  915. }else{
  916. return reject();
  917. }
  918. }).then(() => {
  919. if(elements.board && elements.board.isConnected) return;
  920. elements.board = site.targets.board();
  921. if(elements.board){
  922. core.observeBoard(elements.board);
  923. log("Board ready.");
  924. }
  925. });
  926. }, 1000);
  927. },
  928. read: function(){
  929. panels = new Panels(window.top.document.body.appendChild(createElement(core.html.panels())));
  930. configs = new Configs(Storage.read('configs') || {});
  931. speaker = new Speaker(configs);
  932. },
  933. observeBoard: function(board){
  934. let configButton = elements.configButton;
  935. let isNewer = function(node){
  936. if(site.reverse){
  937. for(let i = 0; board.children[i]; i++){
  938. if(node === board.children[i]) return true;
  939. if(i >= configs.buffer) return false;
  940. }
  941. }else{
  942. for(let i = board.children.length - 1; board.children[i]; i--){
  943. if(node === board.children[i]) return true;
  944. if(board.children.length - i >= configs.buffer) return false;
  945. }
  946. }
  947. };
  948. observe(board, function(records){
  949. //log(records);
  950. if(configButton.classList.contains('active') === false) return;
  951. if(site.reverse) records.reverse();
  952. records.forEach(r => {
  953. r.addedNodes.forEach(n => {
  954. if(isNewer(n) === false) return;/*最後のbuffer個数分でなければ無視してよい*/
  955. let name = site.addedNodes.name(n);
  956. let content = site.addedNodes.content(n);
  957. if(content === null || content.textContent.trim() === '') return;
  958. let read = site.addedNodes.read.find(r => r[1](n));
  959. if(read) return speaker.request(content.textContent, read[0], content);
  960. // if(read) return setTimeout(() => {speaker.request(content.textContent, read[0], content);}, 1000);
  961. if(site.addedNodes.ignore.some(i => i[1](n))) return;
  962. speaker.request(content.textContent, UNKNOWNPITCHRATIO, content);
  963. // setTimeout(() => {speaker.request(content.textContent, UNKNOWNPITCHRATIO, content)}, 1000);
  964. });
  965. });
  966. });
  967. },
  968. configs: {
  969. createButton: function(){
  970. let anchor = elements.settingAnchor, before = site.insertBefore;
  971. let node, configButton = elements.configButton = createElement(core.html.configButton(core.html.configButtonProperties[site.id]));
  972. if(core.html.configButtonWrappers[site.id]){
  973. node = createElement(core.html.configButtonWrappers[site.id]());
  974. node.appendChild(configButton);
  975. }else{
  976. node = configButton;
  977. }
  978. node.className = [node.className, anchor.className].join(' ');
  979. configButton.addEventListener('click', function(e){
  980. configButton.classList.toggle('active');
  981. if(configButton.classList.contains('active') === false) speaker.cancel();
  982. });
  983. configButton.addEventListener('contextmenu', function(e){
  984. e.preventDefault();
  985. panels.toggle('configs');
  986. });
  987. anchor.parentNode.insertBefore(node, (before ? anchor : anchor.nextElementSibling));
  988. core.configs.createPanel();
  989. },
  990. createPanel: function(){
  991. let panel = createElement(core.html.configPanel()), itemElements = panel.querySelectorAll('[name]'), items = {};
  992. Array.from(itemElements).forEach(e => items[e.name] = e);
  993. /* リセット */
  994. panel.querySelector('button.reset').addEventListener('click', function(e){
  995. if(confirm(TEXTS.resetConfirmation())){
  996. panels.hide('configs');
  997. configs = new Configs({});
  998. core.configs.createPanel();
  999. panels.show('configs');
  1000. }
  1001. });
  1002. /* 試し読み */
  1003. let normal = panel.querySelector('button.normal'), fast = panel.querySelector('button.fast');
  1004. let getValue = (node) => (parseInt(node.value) / 100);
  1005. normal.addEventListener('click', function(e){
  1006. speaker.test(items.text.value, getValue(items.volume), getValue(items.pitch), items.voice.value, 1);
  1007. });
  1008. fast.addEventListener('click', function(e){
  1009. speaker.test(items.text.value, getValue(items.volume), getValue(items.pitch), items.voice.value, getValue(items.fastest));
  1010. });
  1011. /* 声 */
  1012. let defaultVoice = Object.keys(speaker.voices).find(key => speaker.voices[key].default) || Object.keys(speaker.voices).find(key => speaker.voices[key].lang.startsWith(navigator.language));
  1013. let currentVoice = speaker.voices[configs.voice || defaultVoice], languages = [], voices = [];
  1014. Object.keys(speaker.voices).forEach(key => {
  1015. if(languages.includes(speaker.voices[key].lang) === false) languages.push(speaker.voices[key].lang);
  1016. voices.push(key);
  1017. });
  1018. languages.sort().forEach(l => {
  1019. let option = createElement(core.html.option(l));
  1020. if(l === currentVoice.lang) option.selected = true;
  1021. items.language.appendChild(option);
  1022. });
  1023. voices.sort().forEach(v => {
  1024. let option = createElement(core.html.option(v));
  1025. if(speaker.voices[v].lang !== currentVoice.lang) option.classList.add('hidden');
  1026. if(v === currentVoice.name) option.selected = true;
  1027. items.voice.appendChild(option);
  1028. });
  1029. items.language.addEventListener('change', function(e){
  1030. Array.from(items.voice.children).reverse().forEach(o => {
  1031. if(speaker.voices[o.value].lang === e.target.value){
  1032. o.classList.remove('hidden');
  1033. o.selected = true;
  1034. }
  1035. else o.classList.add('hidden');
  1036. });
  1037. });
  1038. /* 専門用語モード */
  1039. let translatorTemplate = createElement(core.html.checkbox('translators', 'template')), translatorsEmpty = panel.querySelector('.translatorsEmpty');
  1040. items.translators = [];
  1041. Object.keys(TRANSLATORS).forEach(key => {
  1042. let label = translatorTemplate.cloneNode(true), input = label.querySelector('input[type="checkbox"]');
  1043. label.dataset.translator = key;
  1044. input.value = key;
  1045. input.checked = configs.translators.some(t => (t === key));
  1046. translatorsEmpty.parentNode.insertBefore(label, translatorsEmpty.parentNode.firstElementChild);
  1047. items.translators.push(input);
  1048. });
  1049. /* キャンセル */
  1050. panel.querySelector('button.cancel').addEventListener('click', function(e){
  1051. panels.hide('configs');
  1052. core.configs.createPanel();/*クリアしておく*/
  1053. });
  1054. /* 保存 */
  1055. panel.querySelector('button.save').addEventListener('click', function(e){
  1056. let dictionary = configs.parseDictionaryString(items.dictionary.value);
  1057. if(dictionary === false) return alert(TEXTS.dictionaryParseError());
  1058. configs = new Configs({
  1059. text: items.text.value,
  1060. volume: items.volume.value,
  1061. pitch: items.pitch.value,
  1062. voice: items.voice.value,
  1063. fastest: items.fastest.value,
  1064. buffer: items.buffer.value,
  1065. translators: Array.from(items.translators).filter(t => t.checked).map(t => t.value),
  1066. dictionary: dictionary,
  1067. ngs: configs.parseNgsString(items.ngs.value),
  1068. });
  1069. speaker.cancel();
  1070. speaker = new Speaker(configs);
  1071. Storage.save('configs', configs.toJSON());
  1072. panels.hide('configs');
  1073. core.configs.createPanel();/*クリアしておく*/
  1074. });
  1075. panels.add('configs', panel);
  1076. },
  1077. },
  1078. addStyle: function(name = 'style', d = document){
  1079. if(core.html[name] === undefined) return;
  1080. let style = createElement(core.html[name]());
  1081. d.head.appendChild(style);
  1082. if(elements[name] && elements[name].isConnected) d.head.removeChild(elements[name]);
  1083. elements[name] = style;
  1084. },
  1085. html: {
  1086. configButtonWrappers: {
  1087. showroom: () => `<li></li>`,
  1088. },
  1089. configButtonProperties: {
  1090. nicolive: 'aria-label',
  1091. },
  1092. configButton: (property = 'title') => `
  1093. <button id="${SCRIPTID}-config-button" ${property}="${TEXTS.scriptname()}">
  1094. <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 330 330" xml:space="preserve">
  1095. <g id="XMLID_797_">
  1096. <path id="XMLID_798_" d="M164.998,210c35.887,0,65.085-29.195,65.085-65.12l-0.204-80c0-35.776-29.105-64.88-64.881-64.88
  1097. c-35.773,0-64.877,29.104-64.877,64.843l-0.203,80.076C99.918,180.805,129.112,210,164.998,210z"/>
  1098. <path id="XMLID_799_" d="M280.084,154.96c0-8.285-6.717-15-15-15c-8.284,0-15,6.715-15,15c0,46.732-37.878,84.773-84.546,85.067
  1099. c-0.181-0.007-0.357-0.027-0.54-0.027c-0.184,0-0.359,0.02-0.541,0.027c-46.664-0.293-84.541-38.335-84.541-85.067
  1100. c0-8.285-6.717-15-15-15c-8.284,0-15,6.715-15,15c0,58.372,43.688,106.731,100.082,114.104V300H117c-8.284,0-15,6.716-15,15
  1101. s6.716,15,15,15h96.002c8.283,0,15-6.716,15-15s-6.717-15-15-15h-33.004v-30.936C236.395,261.69,280.084,213.332,280.084,154.96z"/>
  1102. </g>
  1103. </svg>
  1104. </button>
  1105. `,
  1106. configPanel: () => `
  1107. <div class="panel" id="${SCRIPTID}-config-panel" data-order="1">
  1108. <h1>
  1109. <button class="reset" title="${TEXTS.reset()}">
  1110. <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
  1111. <metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>
  1112. <g><path d="M500,10v392l196-196L500,10z"/><path d="M500,990C271.3,990,85.1,803.8,85.1,575.1c0-228.7,186.2-414.9,414.9-414.9v91.5c-176.4,0-323.4,143.7-323.4,323.4c0,179.7,143.7,323.4,323.4,323.4c179.7,0,323.4-143.7,323.4-323.4h91.5C914.9,803.8,728.7,990,500,990z"/></g>
  1113. </svg>
  1114. </button>
  1115. ${TEXTS.configs()}
  1116. </h1>
  1117. <fieldset>
  1118. <legend>${TEXTS.test()}</legend>
  1119. <p class="property"><input type="text" name="text" value="${configs.data.text}"><button class="normal">▶</button><button class="fast">▶▶</button></p>
  1120. </fieldset>
  1121. <fieldset>
  1122. <legend>${TEXTS.speech()}</legend>
  1123. <p class="property"><label for="config-volume">${TEXTS.volume()}<small>(0-100%)</small>:</label><input type="number" name="volume" id="config-volume" value="${configs.data.volume}" min="0" max="100" step="5"></p>
  1124. <p class="property"><label for="config-pitch" >${TEXTS.pitch()}<small>(0-200%)</small>: </label><input type="number" name="pitch" id="config-pitch" value="${configs.data.pitch}" min="0" max="200" step="10"></p>
  1125. <p class="property"><label for="config-voice" >${TEXTS.voice()}:</label><select name="language"></select><select name="voice" id="config-voice"></select></p>
  1126. </fieldset>
  1127. <fieldset>
  1128. <legend>${TEXTS.fast()}</legend>
  1129. <p class="property"><label for="config-fastest">${TEXTS.fastest()}<small>(100-250%)</small>: </label><input type="number" name="fastest" id="config-fastest" value="${configs.data.fastest}" min="100" max="250" step="10"></p>
  1130. <p class="property"><label for="config-buffer" title="${TEXTS.bufferNote()}">${TEXTS.buffer()}<sup>※</sup>:</label><input type="number" name="buffer" id="config-buffer" value="${configs.data.buffer}" min="1" max="25" step="1"></p>
  1131. </fieldset>
  1132. <fieldset>
  1133. <legend>${TEXTS.translators()}</legend>
  1134. <p class="property"><span class="translatorsEmpty">${TEXTS.translatorsEmpty()}</span></p>
  1135. </fieldset>
  1136. <fieldset>
  1137. <legend>${TEXTS.dictionary()}<small>${TEXTS.professional()}</small></legend>
  1138. <p class="property"><textarea name="dictionary" id="config-dictionary">${configs.dictionaryString}</textarea></p>
  1139. <p class="note">${TEXTS.dictionaryNote()}</p>
  1140. </fieldset>
  1141. <fieldset>
  1142. <legend>${TEXTS.ng()}</legend>
  1143. <p class="property"><textarea name="ngs" id="config-ngs">${configs.ngsString}</textarea></p>
  1144. <p class="note">${TEXTS.ngNote()}</p>
  1145. </fieldset>
  1146. <p class="buttons"><button class="cancel">${TEXTS.cancel()}</button><button class="save primary">${TEXTS.save()}</button></p>
  1147. </div>
  1148. `,
  1149. option: (value) => `<option value="${value}">${value}</option>`,
  1150. checkbox: (key, value) => `<label data-${key}="${value}"><input type="checkbox" name="${key}"></label>`,
  1151. panels: () => `<div class="panels" id="${SCRIPTID}-panels" data-panels="0"></div>`,
  1152. stylePanels: () => `
  1153. <style type="text/css">
  1154. /* 設定パネル(共通) */
  1155. #${SCRIPTID}-panels *{
  1156. font-size: 14px;
  1157. line-height: 20px;
  1158. padding: 0;
  1159. margin: 0;
  1160. }
  1161. #${SCRIPTID}-panels{
  1162. font-family: Arial, sans-serif;
  1163. position: fixed;
  1164. width: 100%;
  1165. height: 100%;
  1166. top: 0;
  1167. left: 0;
  1168. overflow: hidden;
  1169. pointer-events: none;
  1170. z-index: 99999;
  1171. }
  1172. #${SCRIPTID}-panels div.panel{
  1173. position: absolute;
  1174. max-height: 100%;/*小さなウィンドウに対応*/
  1175. overflow: auto;
  1176. left: 50%;
  1177. bottom: 50%;
  1178. transform: translate(-50%, 50%);
  1179. background: rgba(0,0,0,.75);
  1180. transition: 250ms;
  1181. padding: 5px 0;
  1182. pointer-events: auto;
  1183. }
  1184. #${SCRIPTID}-panels div.panel.hidden{
  1185. bottom: 0;
  1186. transform: translate(-50%, 100%) !important;
  1187. display: block !important;
  1188. }
  1189. #${SCRIPTID}-panels div.panel.hidden *{
  1190. animation: none !important;/*CPU負荷軽減*/
  1191. }
  1192. #${SCRIPTID}-panels h1,
  1193. #${SCRIPTID}-panels h2,
  1194. #${SCRIPTID}-panels h3,
  1195. #${SCRIPTID}-panels h4,
  1196. #${SCRIPTID}-panels legend,
  1197. #${SCRIPTID}-panels ul,
  1198. #${SCRIPTID}-panels ol,
  1199. #${SCRIPTID}-panels dl,
  1200. #${SCRIPTID}-panels p{
  1201. color: white;
  1202. padding: 2px 10px;
  1203. vertical-align: baseline;
  1204. }
  1205. #${SCRIPTID}-panels legend ~ p,
  1206. #${SCRIPTID}-panels legend ~ ul,
  1207. #${SCRIPTID}-panels legend ~ ol,
  1208. #${SCRIPTID}-panels legend ~ dl{
  1209. padding-left: calc(10px + 14px);
  1210. }
  1211. #${SCRIPTID}-panels header{
  1212. display: flex;
  1213. }
  1214. #${SCRIPTID}-panels header h1{
  1215. flex: 1;
  1216. }
  1217. #${SCRIPTID}-panels fieldset{
  1218. border: none;
  1219. }
  1220. #${SCRIPTID}-panels fieldset > p{
  1221. display: flex;
  1222. align-items: center;
  1223. }
  1224. #${SCRIPTID}-panels fieldset > p.property:hover{
  1225. background: rgba(255,255,255,.125);
  1226. }
  1227. #${SCRIPTID}-panels fieldset > p.property > label{
  1228. flex: 1;
  1229. }
  1230. #${SCRIPTID}-panels fieldset > p.property > input,
  1231. #${SCRIPTID}-panels fieldset > p.property > textarea,
  1232. #${SCRIPTID}-panels fieldset > p.property > select{
  1233. color: black;
  1234. background: white;
  1235. padding: 1px 2px;
  1236. }
  1237. #${SCRIPTID}-panels fieldset > p.property > input,
  1238. #${SCRIPTID}-panels fieldset > p.property > button{
  1239. box-sizing: border-box;
  1240. height: 20px;
  1241. }
  1242. #${SCRIPTID}-panels fieldset small{
  1243. font-size: 12px;
  1244. margin: 0 0 0 .25em;
  1245. }
  1246. #${SCRIPTID}-panels fieldset sup,
  1247. #${SCRIPTID}-panels fieldset p.note{
  1248. font-size: 10px;
  1249. line-height: 14px;
  1250. opacity: .75;
  1251. }
  1252. #${SCRIPTID}-panels div.panel > p.buttons{
  1253. text-align: right;
  1254. padding: 5px 10px;
  1255. }
  1256. #${SCRIPTID}-panels div.panel > p.buttons button{
  1257. line-height: 1.4;
  1258. width: 120px;
  1259. padding: 5px 10px;
  1260. margin-left: 10px;
  1261. border-radius: 5px;
  1262. color: rgba(255,255,255,1);
  1263. background: rgba(64,64,64,1);
  1264. border: 1px solid rgba(255,255,255,1);
  1265. cursor: pointer;
  1266. }
  1267. #${SCRIPTID}-panels div.panel > p.buttons button.primary{
  1268. font-weight: bold;
  1269. background: rgba(0,0,0,1);
  1270. }
  1271. #${SCRIPTID}-panels div.panel > p.buttons button:hover,
  1272. #${SCRIPTID}-panels div.panel > p.buttons button:focus{
  1273. background: rgba(128,128,128,1);
  1274. }
  1275. #${SCRIPTID}-panels .template{
  1276. display: none !important;
  1277. }
  1278. /* 設定パネル */
  1279. #${SCRIPTID}-config-panel{
  1280. width: 320px;
  1281. }
  1282. #${SCRIPTID}-config-panel button.reset{
  1283. float: right;
  1284. font-size: 20px;
  1285. color: white;
  1286. background: black;
  1287. border: 1px solid #666;
  1288. border-radius: 5px;
  1289. width: 1em;
  1290. height: 1em;
  1291. cursor: pointer;
  1292. }
  1293. #${SCRIPTID}-config-panel button.reset:hover{
  1294. background: #333;
  1295. }
  1296. #${SCRIPTID}-config-panel button.reset svg{
  1297. fill: white;
  1298. width: 100%;
  1299. height: 100%;
  1300. padding: 2px;
  1301. box-sizing: border-box;
  1302. }
  1303. #${SCRIPTID}-config-panel input[type="number"]{
  1304. width: 4em;
  1305. }
  1306. #${SCRIPTID}-config-panel input[name="text"]{
  1307. border: 1px solid #999;
  1308. border-radius: 5px 0 0 5px;
  1309. height: 24px;
  1310. flex: 1;
  1311. }
  1312. #${SCRIPTID}-config-panel input[name="text"] ~ button{
  1313. font-size: 10px;
  1314. white-space: nowrap;
  1315. color: white;
  1316. background: #000;
  1317. border: 1px solid #666;
  1318. border-left: none;
  1319. width: 4em;
  1320. height: 24px;
  1321. padding: 0 1em;
  1322. cursor: pointer;
  1323. }
  1324. #${SCRIPTID}-config-panel input[name="text"] ~ button.fast{
  1325. border-radius: 0 5px 5px 0;
  1326. }
  1327. #${SCRIPTID}-config-panel input[name="text"] ~ button:hover{
  1328. background: #333;
  1329. }
  1330. #${SCRIPTID}-config-panel select#config-voice{
  1331. max-width: 120px;
  1332. }
  1333. #${SCRIPTID}-config-panel option.hidden{
  1334. display: none;
  1335. }
  1336. #${SCRIPTID}-config-panel label[data-translator]{
  1337. background: #333;
  1338. border: 1px solid #666;
  1339. border-radius: 5px;
  1340. padding: 2px 5px;
  1341. flex: 0 !important;
  1342. white-space: nowrap;
  1343. cursor: pointer;
  1344. }
  1345. #${SCRIPTID}-config-panel label[data-translator]:hover{
  1346. background: #444;
  1347. }
  1348. #${SCRIPTID}-config-panel label[data-translator]::after{
  1349. content: attr(data-translator);
  1350. margin-left: 5px;
  1351. }
  1352. #${SCRIPTID}-config-panel label[data-translator] input{
  1353. cursor: pointer;
  1354. }
  1355. #${SCRIPTID}-config-panel .translatorsEmpty{
  1356. opacity: .75;
  1357. }
  1358. #${SCRIPTID}-config-panel label + .translatorsEmpty{
  1359. display: none;
  1360. }
  1361. #${SCRIPTID}-config-panel textarea{
  1362. width: 100%;
  1363. height: 40px;
  1364. font-family: monospace;
  1365. }
  1366. </style>
  1367. `,
  1368. style: () => `
  1369. <style type="text/css">
  1370. /* 設定ボタン */
  1371. button#${SCRIPTID}-config-button{
  1372. background: transparent;
  1373. border: none;
  1374. padding: 0;
  1375. margin: 0;
  1376. cursor: pointer;
  1377. transition: 125ms;
  1378. }
  1379. button#${SCRIPTID}-config-button svg{
  1380. fill: #666;
  1381. }
  1382. button#${SCRIPTID}-config-button:hover svg{
  1383. fill: #999;
  1384. }
  1385. button#${SCRIPTID}-config-button.active svg{
  1386. fill: #f00;
  1387. }
  1388. button#${SCRIPTID}-config-button.active:hover svg{
  1389. fill: #f33;
  1390. }
  1391. /* 読み上げコメント */
  1392. [data-speaking="true"]{
  1393. position: relative !important;
  1394. overflow: visible !important;
  1395. }
  1396. [data-speaking="true"]::after/*公式がbeforeを使っていても干渉しない*/{
  1397. font-family: Arial, sans-serif;
  1398. content: "●";
  1399. color: red;
  1400. font-size: 100%;
  1401. position: absolute;
  1402. left: -.125em;
  1403. top: 50%;
  1404. transform: translate(-100%, -50%);
  1405. animation: ${SCRIPTID}-blink 1000ms ease 0ms infinite alternate forwards;
  1406. }
  1407. @keyframes ${SCRIPTID}-blink{
  1408. 50%{opacity: .5}
  1409. }
  1410. </style>
  1411. `,
  1412. abema: () => `
  1413. <style type="text/css">
  1414. button#${SCRIPTID}-config-button{
  1415. width: 40px;
  1416. height: 40px;
  1417. }
  1418. button#${SCRIPTID}-config-button svg{
  1419. width: 24px;
  1420. height: 24px;
  1421. transform: translateY(7px);
  1422. fill: #ccc;
  1423. }
  1424. button#${SCRIPTID}-config-button:hover svg{
  1425. fill: #fff;
  1426. }
  1427. button#${SCRIPTID}-config-button.active svg{
  1428. fill: #f00;
  1429. }
  1430. </style>
  1431. `,
  1432. bilibili: () => `
  1433. <style type="text/css">
  1434. button#${SCRIPTID}-config-button{
  1435. width: 20px;
  1436. height: 20px;
  1437. transform: translateY(1px);
  1438. vertical-align: middle;
  1439. }
  1440. button#${SCRIPTID}-config-button::before{
  1441. display: none;
  1442. }
  1443. [data-speaking="true"]{
  1444. position: static !important;
  1445. }
  1446. [data-speaking="true"]::after{
  1447. left: .25em;
  1448. }
  1449. </style>
  1450. `,
  1451. douyu: () => `
  1452. <style type="text/css">
  1453. button#${SCRIPTID}-config-button{
  1454. width: 20px;
  1455. height: 20px;
  1456. transform: translate(-5px, calc(-100% - 5px));
  1457. vertical-align: middle;
  1458. }
  1459. [data-speaking="true"]{
  1460. position: static !important;
  1461. }
  1462. [data-speaking="true"]::after{
  1463. left: .625em;
  1464. }
  1465. </style>
  1466. `,
  1467. fc2: () => `
  1468. <style type="text/css">
  1469. button#${SCRIPTID}-config-button{
  1470. width: 42px;
  1471. height: 38px;
  1472. }
  1473. button#${SCRIPTID}-config-button svg{
  1474. width: 24px;
  1475. height: 24px;
  1476. transform: translateY(1px);
  1477. }
  1478. [data-speaking="true"]::after{
  1479. left: .5em;
  1480. }
  1481. .js-commentLine{
  1482. position: relative;
  1483. }
  1484. .js-commentText{
  1485. position: static !important;
  1486. }
  1487. </style>
  1488. `,
  1489. huajiao: () => `
  1490. <style type="text/css">
  1491. button#${SCRIPTID}-config-button{
  1492. width: 30px;
  1493. height: 30px;
  1494. position: absolute;
  1495. left: 100%;
  1496. top: 0;
  1497. transform: translate(-100%,-100%);
  1498. }
  1499. button#${SCRIPTID}-config-button svg{
  1500. width: 24px;
  1501. height: 24px;
  1502. transform: translateY(1px);
  1503. }
  1504. .tt-msg-message{
  1505. position: relative;
  1506. }
  1507. [data-speaking="true"]{
  1508. position: static !important;
  1509. }
  1510. [data-speaking="true"]::after{
  1511. left: 1.25em;
  1512. }
  1513. </style>
  1514. `,
  1515. huya: () => `
  1516. <style type="text/css">
  1517. button#${SCRIPTID}-config-button{
  1518. width: 22px;
  1519. height: 22px;
  1520. transform: translateY(1px);
  1521. vertical-align: middle;
  1522. float: left;
  1523. margin-right: 10px;
  1524. }
  1525. button#${SCRIPTID}-config-button::before{
  1526. display: none;
  1527. }
  1528. .J_msg{
  1529. position: relative;
  1530. }
  1531. [data-speaking="true"]{
  1532. position: static !important;
  1533. }
  1534. [data-speaking="true"]::after{
  1535. left: .625em;
  1536. }
  1537. </style>
  1538. `,
  1539. inke: () => `
  1540. <style type="text/css">
  1541. button#${SCRIPTID}-config-button{
  1542. width: 36px;
  1543. height: 36px;
  1544. position: absolute;
  1545. left: 100%;
  1546. top: 0;
  1547. transform: translate(calc(-100% - 10px), -100%)
  1548. }
  1549. button#${SCRIPTID}-config-button svg{
  1550. width: 24px;
  1551. height: 24px;
  1552. transform: translateY(1px);
  1553. }
  1554. .comments_list li{
  1555. position: relative;
  1556. }
  1557. [data-speaking="true"]{
  1558. position: static !important;
  1559. }
  1560. [data-speaking="true"]::after{
  1561. left: calc(28px + .65em);
  1562. }
  1563. </style>
  1564. `,
  1565. line: () => `
  1566. <style type="text/css">
  1567. button#${SCRIPTID}-config-button{
  1568. width: 40px;
  1569. height: 40px;
  1570. float: right;
  1571. }
  1572. button#${SCRIPTID}-config-button svg{
  1573. width: 24px;
  1574. height: 24px;
  1575. transform: translateY(1px);
  1576. }
  1577. #${SCRIPTID}-config-panel legend{
  1578. position: static;
  1579. width: auto;
  1580. height: auto;
  1581. }
  1582. [class*="Chat"] [data-speaking="true"]{
  1583. position: static !important;
  1584. }
  1585. [class*="Chat"] [data-speaking="true"]::after{
  1586. left: 1em;
  1587. }
  1588. [class*="Label"][data-speaking="true"]::after{
  1589. left: 0em;
  1590. }
  1591. </style>
  1592. `,
  1593. nicolive: () => `
  1594. <style type="text/css">
  1595. button#${SCRIPTID}-config-button{
  1596. width: 32px;
  1597. height: 36px;
  1598. }
  1599. button#${SCRIPTID}-config-button svg{
  1600. width: 20px;
  1601. height: 20px;
  1602. transform: translateY(1px);
  1603. }
  1604. </style>
  1605. `,
  1606. openrec: () => `
  1607. <style type="text/css">
  1608. button#${SCRIPTID}-config-button{
  1609. width: 2.2rem;
  1610. height: 2.2rem;
  1611. margin-right: 1rem;
  1612. }
  1613. .chat-content[data-speaking="true"]{
  1614. position: static !important;
  1615. }
  1616. </style>
  1617. `,
  1618. periscope: () => `
  1619. <style type="text/css">
  1620. button#${SCRIPTID}-config-button{
  1621. width: 32px;
  1622. height: 32px;
  1623. margin-left: 10px;
  1624. background-color: rgba(255, 255, 255, 0.2);
  1625. border-radius: 32px;
  1626. }
  1627. button#${SCRIPTID}-config-button svg{
  1628. width: 20px;
  1629. height: 20px;
  1630. }
  1631. .CommentMessage-body,
  1632. [data-speaking="true"]{
  1633. position: static !important;
  1634. }
  1635. </style>
  1636. `,
  1637. showroom: () => `
  1638. <style type="text/css">
  1639. button#${SCRIPTID}-config-button{
  1640. width: 60px;
  1641. height: 50px;
  1642. }
  1643. button#${SCRIPTID}-config-button svg{
  1644. width: 28px;
  1645. height: 28px;
  1646. transform: translateY(2px);
  1647. }
  1648. </style>
  1649. `,
  1650. twitcasting: () => `
  1651. <style type="text/css">
  1652. button#${SCRIPTID}-config-button{
  1653. width: 2em;
  1654. height: 2em;
  1655. margin-left: .5em;
  1656. }
  1657. #${SCRIPTID}-config-panel legend{
  1658. border: none;
  1659. width: auto;
  1660. }
  1661. #${SCRIPTID}-config-panel input,
  1662. #${SCRIPTID}-config-panel select{
  1663. width: auto;
  1664. }
  1665. </style>
  1666. `,
  1667. twitch: () => `
  1668. <style type="text/css">
  1669. .chat-input__buttons-container > div > .tw-relative > div{
  1670. display: flex;
  1671. }
  1672. button#${SCRIPTID}-config-button{
  1673. width: 3rem;
  1674. height: 3rem;
  1675. padding: .4rem;
  1676. }
  1677. button#${SCRIPTID}-config-button > svg{
  1678. width: 3rem;
  1679. height: 3rem;
  1680. position: relative;
  1681. top: -.4rem;
  1682. }
  1683. #${SCRIPTID}-config-panel button{
  1684. text-align: center;
  1685. }
  1686. .chat-line__message{
  1687. position: relative;
  1688. }
  1689. .chat-line__message [data-speaking="true"]{
  1690. position: static !important;
  1691. }
  1692. .chat-line__message [data-speaking="true"]::after{
  1693. left: 1em;
  1694. }
  1695. </style>
  1696. `,
  1697. whowatch: () => `
  1698. <style type="text/css">
  1699. button#${SCRIPTID}-config-button{
  1700. width: 36px;
  1701. height: 36px;
  1702. position: absolute;
  1703. left: 0;
  1704. bottom: 0;
  1705. }
  1706. button#${SCRIPTID}-config-button svg{
  1707. width: 32px;
  1708. height: 32px;
  1709. transform: translateY(4px);
  1710. }
  1711. form .row{
  1712. position: relative;
  1713. }
  1714. [data-speaking="true"]{
  1715. position: static !important;
  1716. }
  1717. </style>
  1718. `,
  1719. yizhibo: () => `
  1720. <style type="text/css">
  1721. button#${SCRIPTID}-config-button{
  1722. width: 30px;
  1723. height: 30px;
  1724. position: absolute;
  1725. left: 100%;
  1726. top: 0;
  1727. transform: translate(-100%,-100%);
  1728. }
  1729. button#${SCRIPTID}-config-button svg{
  1730. width: 24px;
  1731. height: 24px;
  1732. transform: translateY(1px);
  1733. }
  1734. .msg_1{
  1735. overflow: visible !important;
  1736. }
  1737. [data-speaking="true"]{
  1738. position: static !important;
  1739. }
  1740. </style>
  1741. `,
  1742. youtube: () => `
  1743. <style type="text/css">
  1744. button#${SCRIPTID}-config-button{
  1745. width: 40px;
  1746. height: 40px;
  1747. }
  1748. button#${SCRIPTID}-config-button svg{
  1749. width: 20px;
  1750. height: 20px;
  1751. transform: translateY(1px);
  1752. }
  1753. yt-live-chat-text-message-renderer #content{
  1754. position: relative !important;
  1755. }
  1756. yt-live-chat-text-message-renderer [data-speaking="true"]{
  1757. position: static !important;
  1758. }
  1759. </style>
  1760. `,
  1761. yy: () => `
  1762. <style type="text/css">
  1763. button#${SCRIPTID}-config-button{
  1764. width: 30px;
  1765. height: 30px;
  1766. position: absolute;
  1767. left: 100%;
  1768. top: 0;
  1769. transform: translate(calc(-100% - 5px), calc(-100% - 5px));
  1770. }
  1771. button#${SCRIPTID}-config-button svg{
  1772. width: 24px;
  1773. height: 24px;
  1774. transform: translateY(1px);
  1775. }
  1776. ul.chatroom-list > li{
  1777. position: relative;
  1778. }
  1779. [data-speaking="true"]{
  1780. position: static !important;
  1781. }
  1782. [data-speaking="true"]::after{
  1783. left: .5em;
  1784. }
  1785. </style>
  1786. `,
  1787. },
  1788. };
  1789. const setTimeout = window.setTimeout.bind(window), clearTimeout = window.clearTimeout.bind(window), setInterval = window.setInterval.bind(window), clearInterval = window.clearInterval.bind(window), requestAnimationFrame = window.requestAnimationFrame.bind(window);
  1790. const alert = window.alert.bind(window), confirm = window.confirm.bind(window), getComputedStyle = window.getComputedStyle.bind(window), fetch = window.fetch.bind(window), speechSynthesis = window.speechSynthesis;
  1791. if(!('isConnected' in Node.prototype)) Object.defineProperty(Node.prototype, 'isConnected', {get: function(){return document.contains(this)}});
  1792. class Storage{
  1793. static key(key){
  1794. return (SCRIPTID) ? (SCRIPTID + '-' + key) : key;
  1795. }
  1796. static save(key, value, expire = null){
  1797. key = Storage.key(key);
  1798. localStorage[key] = JSON.stringify({
  1799. value: value,
  1800. saved: Date.now(),
  1801. expire: expire,
  1802. });
  1803. }
  1804. static read(key){
  1805. key = Storage.key(key);
  1806. if(localStorage[key] === undefined) return undefined;
  1807. let data = JSON.parse(localStorage[key]);
  1808. if(data.value === undefined) return data;
  1809. if(data.expire === undefined) return data;
  1810. if(data.expire === null) return data.value;
  1811. if(data.expire < Date.now()) return localStorage.removeItem(key);
  1812. return data.value;
  1813. }
  1814. static delete(key){
  1815. key = Storage.key(key);
  1816. delete localStorage.removeItem(key);
  1817. }
  1818. static saved(key){
  1819. key = Storage.key(key);
  1820. if(localStorage[key] === undefined) return undefined;
  1821. let data = JSON.parse(localStorage[key]);
  1822. if(data.saved) return data.saved;
  1823. else return undefined;
  1824. }
  1825. }
  1826. class Panels{
  1827. constructor(parent){
  1828. this.parent = parent;
  1829. this.panels = {};
  1830. this.listen();
  1831. }
  1832. listen(){
  1833. window.addEventListener('keydown', (e) => {
  1834. if(e.key !== 'Escape') return;
  1835. if(['input', 'textarea'].includes(document.activeElement.localName)) return;
  1836. Object.keys(this.panels).forEach(key => this.hide(key));
  1837. }, true);
  1838. }
  1839. add(name, panel){
  1840. this.panels[name] = panel;
  1841. }
  1842. toggle(name){
  1843. let panel = this.panels[name];
  1844. if(panel.isConnected === false || panel.classList.contains('hidden')) this.show(name);
  1845. else this.hide(name);
  1846. }
  1847. show(name){
  1848. let panel = this.panels[name];
  1849. if(panel.isConnected) return;
  1850. panel.classList.add('hidden');
  1851. this.parent.appendChild(panel);
  1852. this.parent.dataset.panels = parseInt(this.parent.dataset.panels) + 1;
  1853. animate(() => panel.classList.remove('hidden'));
  1854. }
  1855. hide(name){
  1856. let panel = this.panels[name];
  1857. if(panel.classList.contains('hidden')) return;
  1858. panel.classList.add('hidden');
  1859. panel.addEventListener('transitionend', (e) => {
  1860. this.parent.removeChild(panel);
  1861. this.parent.dataset.panels = parseInt(this.parent.dataset.panels) - 1;
  1862. }, {once: true});
  1863. }
  1864. }
  1865. const $ = function(s, f){
  1866. let target = document.querySelector(s);
  1867. if(target === null) return null;
  1868. return f ? f(target) : target;
  1869. };
  1870. const $$ = function(s){return document.querySelectorAll(s)};
  1871. const animate = function(callback, ...params){requestAnimationFrame(() => requestAnimationFrame(() => callback(...params)))};
  1872. const createElement = function(html = '<span></span>'){
  1873. let outer = document.createElement('div');
  1874. outer.innerHTML = html;
  1875. return outer.firstElementChild;
  1876. };
  1877. const observe = function(element, callback, options = {childList: true, attributes: false, characterData: false, subtree: false}){
  1878. let observer = new MutationObserver(callback.bind(element));
  1879. observer.observe(element, options);
  1880. return observer;
  1881. };
  1882. const normalize = function(string){
  1883. return string.replace(/[!-~]/g, function(s){
  1884. return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
  1885. }).replace(normalize.RE, function(s){
  1886. return normalize.KANA[s];
  1887. }).replace(/ /g, ' ').replace(/~/g, '〜');
  1888. };
  1889. normalize.KANA = {
  1890. ガ:'ガ', ギ:'ギ', グ:'グ', ゲ:'ゲ', ゴ: 'ゴ',
  1891. ザ:'ザ', ジ:'ジ', ズ:'ズ', ゼ:'ゼ', ゾ: 'ゾ',
  1892. ダ:'ダ', ヂ:'ヂ', ヅ:'ヅ', デ:'デ', ド: 'ド',
  1893. バ:'バ', ビ:'ビ', ブ:'ブ', ベ:'ベ', ボ: 'ボ',
  1894. パ:'パ', ピ:'ピ', プ:'プ', ペ:'ペ', ポ: 'ポ',
  1895. ヷ:'ヷ', ヺ:'ヺ', ヴ:'ヴ',
  1896. ア:'ア', イ:'イ', ウ:'ウ', エ:'エ', オ:'オ',
  1897. カ:'カ', キ:'キ', ク:'ク', ケ:'ケ', コ:'コ',
  1898. サ:'サ', シ:'シ', ス:'ス', セ:'セ', ソ:'ソ',
  1899. タ:'タ', チ:'チ', ツ:'ツ', テ:'テ', ト:'ト',
  1900. ナ:'ナ', ニ:'ニ', ヌ:'ヌ', ネ:'ネ', ノ:'ノ',
  1901. ハ:'ハ', ヒ:'ヒ', フ:'フ', ヘ:'ヘ', ホ:'ホ',
  1902. マ:'マ', ミ:'ミ', ム:'ム', メ:'メ', モ:'モ',
  1903. ヤ:'ヤ', ユ:'ユ', ヨ:'ヨ',
  1904. ラ:'ラ', リ:'リ', ル:'ル', レ:'レ', ロ:'ロ',
  1905. ワ:'ワ', ヲ:'ヲ', ン:'ン',
  1906. ァ:'ァ', ィ:'ィ', ゥ:'ゥ', ェ:'ェ', ォ:'ォ',
  1907. ッ:'ッ', ャ:'ャ', ュ:'ュ', ョ:'ョ',
  1908. "。":'。', "、":'、', "ー":'ー', "「":'「', "」":'」', "・":'・',
  1909. };
  1910. normalize.RE = new RegExp('(' + Object.keys(normalize.KANA).join('|') + ')', 'g');
  1911. const log = function(){
  1912. if(!DEBUG) return;
  1913. let l = log.last = log.now || new Date(), n = log.now = new Date();
  1914. let error = new Error(), line = log.format.getLine(error), callers = log.format.getCallers(error);
  1915. //console.log(error.stack);
  1916. console.log(
  1917. (SCRIPTID || '') + ':',
  1918. /* 00:00:00.000 */ n.toLocaleTimeString() + '.' + n.getTime().toString().slice(-3),
  1919. /* +0.000s */ '+' + ((n-l)/1000).toFixed(3) + 's',
  1920. /* :00 */ ':' + line,
  1921. /* caller.caller */ (callers[2] ? callers[2] + '() => ' : '') +
  1922. /* caller */ (callers[1] || '') + '()',
  1923. ...arguments
  1924. );
  1925. };
  1926. log.formats = [{
  1927. name: 'Firefox Scratchpad',
  1928. detector: /MARKER@Scratchpad/,
  1929. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  1930. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  1931. }, {
  1932. name: 'Firefox Console',
  1933. detector: /MARKER@debugger/,
  1934. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  1935. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  1936. }, {
  1937. name: 'Firefox Greasemonkey 3',
  1938. detector: /\/gm_scripts\//,
  1939. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  1940. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  1941. }, {
  1942. name: 'Firefox Greasemonkey 4+',
  1943. detector: /MARKER@user-script:/,
  1944. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1] - 500,
  1945. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  1946. }, {
  1947. name: 'Firefox Tampermonkey',
  1948. detector: /MARKER@moz-extension:/,
  1949. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1] - 6,
  1950. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  1951. }, {
  1952. name: 'Chrome Console',
  1953. detector: /at MARKER \(<anonymous>/,
  1954. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)?$/)[1],
  1955. getCallers: (e) => e.stack.match(/[^ ]+(?= \(<anonymous>)/gm),
  1956. }, {
  1957. name: 'Chrome Tampermonkey',
  1958. detector: /at MARKER \(chrome-extension:.*?\/userscript.html\?id=/,
  1959. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)?$/)[1] - 6,
  1960. getCallers: (e) => e.stack.match(/[^ ]+(?= \(chrome-extension:)/gm),
  1961. }, {
  1962. name: 'Chrome Extension',
  1963. detector: /at MARKER \(chrome-extension:/,
  1964. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)?$/)[1],
  1965. getCallers: (e) => e.stack.match(/[^ ]+(?= \(chrome-extension:)/gm),
  1966. }, {
  1967. name: 'Edge Console',
  1968. detector: /at MARKER \(eval/,
  1969. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1],
  1970. getCallers: (e) => e.stack.match(/[^ ]+(?= \(eval)/gm),
  1971. }, {
  1972. name: 'Edge Tampermonkey',
  1973. detector: /at MARKER \(Function/,
  1974. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1] - 4,
  1975. getCallers: (e) => e.stack.match(/[^ ]+(?= \(Function)/gm),
  1976. }, {
  1977. name: 'Safari',
  1978. detector: /^MARKER$/m,
  1979. getLine: (e) => 0,/*e.lineが用意されているが最終呼び出し位置のみ*/
  1980. getCallers: (e) => e.stack.split('\n'),
  1981. }, {
  1982. name: 'Default',
  1983. detector: /./,
  1984. getLine: (e) => 0,
  1985. getCallers: (e) => [],
  1986. }];
  1987. log.format = log.formats.find(function MARKER(f){
  1988. if(!f.detector.test(new Error().stack)) return false;
  1989. //console.log('////', f.name, 'wants', 0/*line*/, '\n' + new Error().stack);
  1990. return true;
  1991. });
  1992. const time = function(label){
  1993. if(!DEBUG) return;
  1994. const BAR = '|', TOTAL = 100;
  1995. switch(true){
  1996. case(label === undefined):/* time() to output total */
  1997. let total = 0;
  1998. Object.keys(time.records).forEach((label) => total += time.records[label].total);
  1999. Object.keys(time.records).forEach((label) => {
  2000. console.log(
  2001. BAR.repeat((time.records[label].total / total) * TOTAL),
  2002. label + ':',
  2003. (time.records[label].total).toFixed(3) + 'ms',
  2004. '(' + time.records[label].count + ')',
  2005. );
  2006. });
  2007. time.records = {};
  2008. break;
  2009. case(!time.records[label]):/* time('label') to create and start the record */
  2010. time.records[label] = {count: 0, from: performance.now(), total: 0};
  2011. break;
  2012. case(time.records[label].from === null):/* time('label') to re-start the lap */
  2013. time.records[label].from = performance.now();
  2014. break;
  2015. case(0 < time.records[label].from):/* time('label') to add lap time to the record */
  2016. time.records[label].total += performance.now() - time.records[label].from;
  2017. time.records[label].from = null;
  2018. time.records[label].count += 1;
  2019. break;
  2020. }
  2021. };
  2022. time.records = {};
  2023. core.initialize();
  2024. if(window === top && console.timeEnd) console.timeEnd(SCRIPTID);
  2025. })();