commentswindow.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* global $ */
  2. const { ipcRenderer, remote, clipboard } = require('electron')
  3. const LiveMe = remote.getGlobal('LiveMe')
  4. const appSettings = require('electron-settings')
  5. const formatDuration = require('format-duration')
  6. const DataManager = remote.getGlobal('DataManager')
  7. $(function () {
  8. $('main').show()
  9. setTimeout(() => {
  10. redrawList()
  11. }, 400)
  12. })
  13. function minimizeWindow () { remote.BrowserWindow.getFocusedWindow().minimize() }
  14. function closeWindow () { window.close() }
  15. function showUser (u) { ipcRenderer.send('show-user', { userid: u }) }
  16. function redrawList () {
  17. let videoid = window.location.href.split('?')[1]
  18. LiveMe.getVideoInfo(videoid)
  19. .then(video => {
  20. let username = video.uname
  21. let startTime = video.vtime * 1000
  22. $('main').show()
  23. LiveMe.getChatHistoryForVideo(video.msgfile)
  24. .then(raw => {
  25. let t = raw.split('\n')
  26. let messages = []
  27. for (let i = 0; i < t.length - 1; i++) {
  28. try {
  29. let j = JSON.parse(t[i])
  30. let timeStamp = formatDuration(parseInt(j.timestamp) - startTime)
  31. if (j.objectName === 'app:joinchatroommsgcontent') {
  32. } else if (j.objectName === 'app:leavechatrrommsgcontent') {
  33. } else if (j.objectName === 'app:praisemsgcontent') {
  34. } else if (j.objectName === 'RC:TxtMsg') {
  35. $('main').append(`
  36. <div class="entry">
  37. <div class="time">${timeStamp}</div>
  38. <div class="user"><a onClick="showUser('${j.content.user.id}')">${j.content.user.name}</a></div>
  39. <div class="content">
  40. ${j.content.content}
  41. </div>
  42. </div>
  43. `)
  44. }
  45. } catch (err) {
  46. // Caught
  47. console.log(err)
  48. }
  49. }
  50. })
  51. })
  52. }