bookmarkswindow.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const { ipcRenderer, remote, clipboard } = require('electron')
  2. const LiveMe = remote.getGlobal('LiveMe')
  3. const appSettings = require('electron-settings')
  4. const prettydate = require('pretty-date')
  5. const DataManager = remote.getGlobal('DataManager')
  6. let list = []
  7. let index
  8. let max
  9. $(function () {
  10. $('main').show()
  11. list = DataManager.getAllBookmarks()
  12. index = 0
  13. max = list.length
  14. $('#bookmark-list').html('')
  15. $('footer h1').html(max + ' bookmarks listed.')
  16. $('#bookmark-search').bind('paste cut keydown', function () {
  17. setTimeout(() => {
  18. const value = $(this).val().toLowerCase()
  19. if (value.trim().length === 0) {
  20. $('#bookmark-list tr').show()
  21. return
  22. }
  23. $('#bookmark-list tr').each(function () {
  24. const name = $(this).find('h1').first().text().toLowerCase()
  25. if (name.toLowerCase().indexOf(value) !== -1) {
  26. $(this).show()
  27. } else {
  28. $(this).hide()
  29. }
  30. })
  31. }, 500)
  32. })
  33. setImmediate(() => {
  34. drawEntry()
  35. })
  36. })
  37. function minimizeWindow () { remote.BrowserWindow.getFocusedWindow().minimize() }
  38. function closeWindow () { window.close() }
  39. function copyToClipboard (i) { clipboard.writeText(i) }
  40. function showFollowing (u) { ipcRenderer.send('open-followings-window', { userid: u }) }
  41. function showFollowers (u) { ipcRenderer.send('open-followers-window', { userid: u }) }
  42. function showUser (u) { ipcRenderer.send('show-user', { userid: u }) }
  43. function redrawList () {
  44. index = 0
  45. $('#bookmark-list').html('')
  46. drawEntry()
  47. }
  48. function drawEntry () {
  49. if (index === max) return
  50. let d1 = prettydate.format(new Date(list[index].newest_replay * 1000))
  51. let d2 = prettydate.format(new Date(list[index].last_viewed * 1000))
  52. let isNew = list[index].newest_replay > list[index].last_viewed ? 'new' : 'not-new'
  53. let sex = list[index].sex < 0 ? '' : (list[index].sex == 0 ? 'female' : 'male')
  54. $('#bookmark-list').append(`
  55. <tr id="entry-${list[index].uid}" data-viewed="${list[index].last_viewed}" class="${isNew} ${sex}">
  56. <td width="64">
  57. <img src="${list[index].face}" style="height: 64px; width: 64px;" class="avatar" onError="$(this).hide()" align="bottom">
  58. </td>
  59. <td width="90%" class="main ${isNew}">
  60. <div class="flag">NEW</div>
  61. <h1>${list[index].nickname}</h1>
  62. <h3><span>Latest Replay:</span> ${d1}</h3>
  63. <h4><span>Last Viewed:</span> ${d2}</h4>
  64. <div id="user-${list[index].uid}-buttons" class="buttons">
  65. <a class="button mini view" onClick="showUser('${list[index].uid}')">${list[index].counts.replays} replays</a>
  66. <a class="button mini fans" onClick="showFollowers('${list[index].uid}')">${list[index].counts.followers} Fans</a>
  67. <a class="button mini following" onClick="showFollowing('${list[index].uid}')">Following ${list[index].counts.followings}</a>
  68. </div>
  69. </td>
  70. </tr>
  71. `)
  72. index++
  73. setImmediate(() => { drawEntry() })
  74. }
  75. function hideNonRecent () {
  76. $('#bookmark-list tr.not-new').toggle()
  77. }