yaohuo

try to take over the world!

目前为 2021-07-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name yaohuo
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description try to take over the world!
  6. // @author Polygon
  7. // @match https://yaohuo.me/bbs*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @require https://code.jquery.com/jquery-1.12.4.min.js
  10. // @run-at document-end
  11. // ==/UserScript==
  12. (function () {
  13. 'use strict';
  14. // 显示全评论
  15. let nextPageURL = null
  16. let nextPageButton = document.querySelector('.more a')
  17. if (nextPageButton) {
  18. nextPageURL = nextPageButton.getAttribute('href')
  19. } else { return }
  20. let haveMore = parseInt(nextPageURL.match(/Total=(\d+)/g)[0].split('=')[1]) > 15
  21.  
  22. // 获取更多评论地址
  23. let commentURL = location.protocol + '//' + location.host + nextPageURL.replace('page=2', 'page=1')
  24. // 移除简短评论url 第一个是正文,第二个是评论
  25. let commentDiv = document.querySelectorAll('.content')[1]
  26. commentDiv.innerHTML = ""
  27. let iframe = document.createElement('iframe')
  28. iframe.id = 'full-comment'
  29. iframe.src = commentURL
  30. iframe.width = '100%'
  31. iframe.setAttribute('frameborder', 'no')
  32. iframe.setAttribute('scrolling', 'no')
  33. iframe.setAttribute('border', '0')
  34. iframe.style = `
  35. transition: height 0.3s linear;
  36. overflow: visible;
  37. `
  38. let addStyle = (document, iframeDocument) => {
  39. if (document.body.querySelector('#user-info-box-style') && iframeDocument.body.querySelector('#user-info-box-style')) { return }
  40. let style = `
  41. #user-info-box {
  42. position: absolute;
  43. display: flex;
  44. height: 160px;
  45. background-color: #e5f3ee;
  46. border-radius: 20px;
  47. justify-content: center;
  48. align-items: center;
  49. flex-direction: column;
  50. padding: 12px;
  51. box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.23);
  52. transition: width 0.3s linear;
  53. }
  54. #user-info-box .userTop {
  55. display: flex;
  56. justify-content: center;
  57. align-items: center;
  58. flex-direction: row;
  59. }
  60. #user-info-box .userTop img {
  61. width: 130px;
  62. height: 130px;
  63. border-radius: 10px;
  64. }
  65. #user-info-box .userTop #info {
  66. display: flex;
  67. margin-left: 20px;
  68. line-height: 1.5em;
  69. font-size: 18px;
  70. flex-direction: column;
  71. }
  72. #user-info-box .userBottom {
  73. display: flex;
  74. flex-direction: row;
  75. justify-content: flex-start;
  76. width: 100%;
  77. font-size: 20px;
  78. }
  79. #user-info-box .userBottom img {
  80. line-height: 1em;
  81. width: 20px;
  82. height: 20px;
  83. }
  84. `
  85. let styleEle = document.createElement('style')
  86. styleEle.innerHTML = style
  87. styleEle.setAttribute('id', 'user-info-box-style')
  88. document.body.append(styleEle)
  89. styleEle = iframeDocument.createElement('style')
  90. styleEle.innerHTML = style
  91. styleEle.setAttribute('id', 'user-info-box-style')
  92. iframeDocument.body.append(styleEle)
  93. }
  94. iframe.onload = function () {
  95. let iframeDocument = document.getElementById('full-comment').contentWindow.document
  96. let frameBody = iframeDocument.body
  97. if (frameBody.querySelector('.tip')) {
  98. document.getElementById('full-comment').contentWindow.history.back()
  99. location.reload()
  100. } else {
  101. let refresh = (mutations, observer) => {
  102. let removeEles = ['a[href^="/bbs/message"] + .btBox',
  103. 'a[href^="/bbs/message"]',
  104. '.showpage + .btBox',
  105. '.subtitle'].concat((haveMore) ? [] : '.btBox')
  106. for (let i = 0; i < removeEles.length; i++) {
  107. let node = frameBody.querySelector(removeEles[i])
  108. if (node) {
  109. node.parentNode.removeChild(node)
  110. }
  111. }
  112. iframe.height = frameBody.scrollHeight
  113. if (iframeDocument.querySelector('.showpage')) {
  114. iframeDocument.querySelector('.showpage').style['background-color'] = 'white'
  115. }
  116. // 楼主信息
  117. $('a[href^="/bbs/userinfo"]').unbind('mouseenter').unbind('mouseleave').hover(viewUserInfo, delUserInfo)
  118. // 评论区用户信息
  119. addStyle(document, iframeDocument)
  120. iframeDocument.querySelectorAll('a[href^="/bbs/userinfo"]').forEach(
  121. (userTag) => {
  122. $(userTag).unbind('mouseenter').unbind('mouseleave').hover(viewUserInfo, delUserInfo)
  123. }
  124. )
  125. }
  126. refresh()
  127. // 观察
  128. var config = {
  129. attributes: true,
  130. childList: true,
  131. subtree: true
  132. }
  133. var observer = new MutationObserver(refresh)
  134. observer.observe(frameBody, config)
  135. }
  136. };
  137. commentDiv.appendChild(iframe)
  138. // 生成详细信息 a[href^="bbs/userinfo"]
  139. let viewUserInfo = function (e) {
  140. this.parentNode.style.position = 'relative'
  141. let height = this.parentNode.offsetHeight
  142. let userBox = $(`
  143. <div id="user-info-box" style="bottom: ${height}px;">
  144. <span id="loading">${'正在加载' + this.textContent + '的信息...'}</span>
  145. <div class="userTop"></div>
  146. <div class="userBottom"></div>
  147. </div>
  148. `)
  149. $(this.parentNode).append(userBox)
  150. // 获取数据
  151. let userURL = location.protocol + '//' + location.host + this.getAttribute('href')
  152. fetch(userURL, { credentials: 'include' })
  153. .then(e => e.text())
  154. .then(html => {
  155. let hideDiv = document.createElement('div')
  156. hideDiv.innerHTML = html
  157. hideDiv.style.display = 'none'
  158. // 头像
  159. userBox.find('.userTop').append($(hideDiv).find('.content img')[0])
  160. // 信息
  161. let infoStr = $(hideDiv).find('.content')[0].innerText
  162. console.log(infoStr)
  163. let userID = /ID号:(\d+)昵称/g.exec(infoStr)[1]
  164. let userName = /昵称:(.+?)妖晶/g.exec(infoStr)[1]
  165. let money = /妖晶:(\d+)/g.exec(infoStr)[1]
  166. let level = /等级:(\d+级) 头衔:.+勋章/g.exec(infoStr)[1]
  167. let levelInfo = /等级:\d+级 头衔:(.+)勋章/g.exec(infoStr)[1]
  168. userBox.find('.userTop').append($(`
  169. <div id="info">
  170. <span>用户: ${userID}</span>
  171. <span>昵称: ${userName}</span>
  172. <span>妖晶: ${money}</span>
  173. <span>等级: ${level}</span>
  174. <span>头衔: ${levelInfo}</span>
  175. </div>
  176. `))
  177. let medals = /勋章<\/b>:(<img src=".+" alt=".">)*/g.exec($(hideDiv).find('.content')[0].innerHTML)[1]
  178. if (medals) {
  179. userBox.find('.userBottom').html(medals)
  180. } else {
  181. userBox.find('.userBottom').html('这个人很穷,没有勋章')
  182. }
  183. // 加载完毕
  184. userBox.find('#loading').remove()
  185. userBox.css('justify-content', 'space-between')
  186. })
  187. }
  188. let delUserInfo = function (e) {
  189. this.parentNode.style.position = 'inherit'
  190. this.parentNode.querySelector('#user-info-box') && this.parentNode.removeChild(this.parentNode.querySelector('#user-info-box'))
  191. }
  192.  
  193. })();