* 朗读直播评论酱

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

目前为 2020-11-03 提交的版本。查看 最新版本

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