yaohuo

try to take over the world!

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

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