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