XD-Enhance

优化 PC 端的使用体验!样式美化 / 饼干备注 / 快捷切换饼干

  1. // ==UserScript==
  2. // @name XD-Enhance
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.3
  5. // @description 优化 PC 端的使用体验!样式美化 / 饼干备注 / 快捷切换饼干
  6. // @author syrinka
  7. // @match https://www.nmbxd1.com/*
  8. // @grant GM_addStyle
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @license MIT
  12. // ==/UserScript==
  13. var custom_style = '.h-threads-item-reply, .h-threads-item-ref { margin: 12px; width: 100%; border-radius: 16px; } .h-threads-item-reply > .h-threads-item-reply-icon, .h-threads-item-ref > .h-threads-item-reply-icon { display: none !important; } .h-threads-item-reply > .h-threads-item-reply-main, .h-threads-item-ref > .h-threads-item-reply-main { padding: 12px; border-radius: 16px; } .h-threads-item-reply > .h-threads-item-reply-main > .h-threads-info, .h-threads-item-ref > .h-threads-item-reply-main > .h-threads-info { width: 100%; } .h-threads-item-reply > .h-threads-item-reply-main > .h-threads-info > .h-threads-info-id, .h-threads-item-ref > .h-threads-item-reply-main > .h-threads-info > .h-threads-info-id { float: right; } .h-threads-img-box img { margin: 15px !important; } #h-content .uk-container { margin: 0 auto; transform: translate(-75px, 0); } #h-content .uk-pagination { margin: 0px auto; } #h-menu { transition: left 0.4s; height: 100% !important; width: 150px; left: -150px; } #h-menu:hover { left: 0px; } #h-bottom-nav { display: none; } #h-post-form > form > div:nth-child(2) { display: none; } #h-post-form > .h-forum-header { display: none; } .ae-box { display: none; position: fixed; right: 24px; bottom: 24px; font-size: 21px; background: #f0e0d6; padding: 15px; border-radius: 8px; font-family: Consolas; } .ae-cookie { display: block; margin: 5px; } #ae-toast { font-size: 16px; }'
  14. function toast(msg) {
  15. $('#ae-toast').html(msg).fadeIn(500)
  16. setTimeout(function() {
  17. $('#ae-toast').fadeOut(500)
  18. }, 2000)
  19. }
  20. function init_check() {
  21. if (!GM_getValue('now-cookie', false) || !GM_getValue('cookies', false)) {
  22. toast('当前饼干信息不明! 请前往饼干列表页面并手动切换一次饼干')
  23. return false
  24. }
  25. return true
  26. }
  27. function get_desc(id) {
  28. var c = GM_getValue('cookies', null)
  29. if (!c || !c[id] || !c[id].desc) {
  30. return null
  31. } else {
  32. return c[id].desc
  33. }
  34. }
  35. function iset_desc(id) { // with prompt
  36. var c = GM_getValue('cookies')
  37. var ndesc = prompt('新备注:', c[id].desc)
  38. c[id].desc = ndesc
  39. GM_setValue('cookies', c)
  40. }
  41. function switch_cookie(cookie) {
  42. var url = 'https://www.nmbxd1.com/Member/User/Cookie/switchTo/id/' + cookie.id + '.html'
  43. $.ajax({
  44. type: 'get',
  45. url: url,
  46. success: function(r, status, xhr) {
  47. toast('切换成功! 当前饼干为 ' + cookie.name)
  48. GM_setValue('now-cookie', cookie)
  49. }
  50. })
  51. }
  52. function show_switch_panel() {
  53. $('#ae-switch-panel').remove() // 删除上次创建的 panel
  54. if (!init_check()) {
  55. return
  56. }
  57. $('body').append('<div id="ae-switch-panel" class="ae-box"></div>')
  58. var sp = $('#ae-switch-panel')
  59. sp.fadeIn(500)
  60. sp.on('mouseleave',
  61. ()=>$('#ae-switch-panel').fadeOut(500)
  62. )
  63. var cookies = GM_getValue('cookies', null)
  64. var nc = GM_getValue('now-cookie', null)
  65. var nc_id = nc?nc.id:null
  66. for (var id in cookies){
  67. var c = cookies[id]
  68. sp.append(
  69. '<a class="ae-cookie" title="' + c.desc + '">' + ((id===nc_id)?'● ':'○ ') + c.name + ' - ' + c.desc + '</a>'
  70. )
  71. sp.children().eq(-1).data('c', c)
  72. .on('click',
  73. function() {sp.fadeOut(500); switch_cookie($(this).data('c'))}
  74. )
  75. }
  76. }
  77. function threads_resolve(index, node) { // 对每个串的格式进行处理
  78. // 将图片盒移动到正文之后
  79. var box = $(this).children('.h-threads-img-box').remove()
  80. $(this).append(box)
  81. }
  82. function on_cookies_manager() {
  83. $('th.table-title').after('<th class="ae-table-desc">饼干备注</th>')
  84. $('tbody>tr>td:nth-child(3)').after('<td></td>')
  85. $('tbody>tr>td:nth-child(7) a:first-child').before('<a href="#" class="am-btn am-btn-default"><span class="am-icon-tag"></span> 修改备注 </a>')
  86. // 0 1 2 3 4 5 6
  87. // 多选框 ID 饼干 饼干备注 有效时间 领取时间 操作
  88. var cookies = {}
  89. $('tbody>tr').each(function(i, n) {
  90. var td = $(this).children()
  91. var id = td.eq(1).text()
  92. var desc = get_desc(id)
  93. cookies[id] = {
  94. id: id,
  95. name: td.eq(2).children().first().text(),
  96. desc: desc
  97. }
  98. td.eq(3).text(desc)
  99. td.eq(6).find('a:first-child').data('id', id)
  100. .on('click', function() {iset_desc($(this).data('id'))})
  101. td.eq(6).find('a:nth-child(2)').data('cookie', cookies[id]).attr('href', '#').off('click')
  102. .on('click', function() {switch_cookie($(this).data('cookie'))})
  103. })
  104. GM_setValue('cookies', cookies);
  105. console.log('♦ 饼干信息更新完毕 √')
  106. var nc = GM_getValue('now-cookie', null)
  107. var info = nc?('当前饼干为 ' + nc.name):('当前饼干信息不明,请手动切换一次饼干')
  108. $('table').after('<span>' + info + '</span>')
  109. }
  110. (function() {
  111. GM_addStyle(custom_style)
  112. // 插入 toast
  113. $('body').append('<div id="ae-toast" class="ae-box" style="text-align: center;"></div>')
  114. if (window.location.pathname === "/Member/User/Cookie/index.html") {
  115. // 饼干管理页面
  116. on_cookies_manager()
  117. } else {
  118. init_check()
  119. $('#h-tool').prepend(
  120. '<a id="ae-mem-page" href="/Member/User/Index/index.html" title="用户系统" class="h-tool-btn"><i class="uk-icon-home"></i></a>'
  121. )
  122. $('#h-tool').append(
  123. '<a id="ae-switcher-toggle" title="切换饼干" class="h-tool-btn"><i class="uk-icon-paper-plane"></i></a>'
  124. )
  125. $('#ae-switcher-toggle').on('click', ()=>show_switch_panel())
  126. // 处理串样式
  127. $('.h-threads-item-reply-main').each(threads_resolve)
  128. }
  129. })();