* 朗读直播评论酱

用声音朗读直播网站的新到来评论。

目前为 2020-07-14 提交的版本。查看 最新版本

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