* 朗读直播评论酱

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

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

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