* 朗读直播评论酱

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

当前为 2020-10-31 提交的版本,查看 最新版本

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