yaohuo

try to take over the world!

  1. // ==UserScript==
  2. // @name yaohuo
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  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. function makeBtn(div) {
  15. if (div.querySelector('#floor')) { return }
  16. let floor = div.innerHTML.match(/\[(.+?)\]/)[1]
  17. div.innerHTML = '[' + `<a id="floor">${floor}</a>` + div.innerHTML.match(/\[.+?(\].+)/)[1]
  18. div.querySelector('#floor').onclick = () => {
  19. console.log(div.querySelector('a[href^="/bbs/userinfo"]'))
  20. viewUserInfo.call(
  21. div.querySelector('a[href^="/bbs/userinfo"]'),
  22. {
  23. fromElement: {
  24. className: div.className
  25. }
  26. }
  27. )
  28. }
  29. }
  30.  
  31. let addStyle = (document, iframeDocument) => {
  32. if (document.body.querySelector('#user-info-box-style') && iframeDocument.body.querySelector('#user-info-box-style')) { return }
  33. let style = `
  34. body {
  35. box-shadow: none;
  36. }
  37. #user-info-box {
  38. position: absolute;
  39. display: flex;
  40. height: 160px;
  41. background-color: #e5f3ee;
  42. border-radius: 20px;
  43. justify-content: center;
  44. align-items: center;
  45. flex-direction: column;
  46. padding: 12px;
  47. box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.23);
  48. transition: width 0.3s linear;
  49. }
  50. #user-info-box .userTop {
  51. display: flex;
  52. justify-content: center;
  53. align-items: center;
  54. flex-direction: row;
  55. }
  56. #user-info-box .userTop img {
  57. width: 130px;
  58. height: 130px;
  59. border-radius: 75px;
  60. }
  61. #user-info-box .userTop #info {
  62. display: flex;
  63. margin-left: 20px;
  64. line-height: 1.5em;
  65. font-size: 18px;
  66. flex-direction: column;
  67. }
  68. #user-info-box .userBottom {
  69. display: flex;
  70. flex-direction: row;
  71. justify-content: flex-start;
  72. width: 100%;
  73. font-size: 20px;
  74. }
  75. #user-info-box .userBottom img {
  76. line-height: 1em;
  77. width: 20px;
  78. height: 20px;
  79. }
  80. `
  81. if (document) {
  82. let styleEle = document.createElement('style')
  83. styleEle.innerHTML = style
  84. styleEle.setAttribute('id', 'user-info-box-style')
  85. document.body.append(styleEle)
  86. }
  87. if (iframeDocument) {
  88. let styleEle = iframeDocument.createElement('style')
  89. styleEle.innerHTML = style
  90. styleEle.setAttribute('id', 'user-info-box-style')
  91. iframeDocument.body.append(styleEle)
  92. }
  93. }
  94. // 生成详细信息 a[href^="bbs/userinfo"]
  95. let viewUserInfo = function (e) {
  96. this.parentNode.style.position = 'relative'
  97. let height
  98. if (e.fromElement.className == "subtitle") {
  99. height = this.parentNode.scrollHeight
  100. } else {
  101. height = 45
  102. }
  103. let userBox = $(`
  104. <div id="user-info-box" style="bottom: ${height}px">
  105. <span id="loading">${'正在加载' + this.textContent + '的信息...'}</span>
  106. <div class="userTop"></div>
  107. <div class="userBottom"></div>
  108. </div>
  109. `)
  110. $(this.parentNode).append(userBox)
  111. // 获取数据
  112. let userURL = location.protocol + '//' + location.host + this.getAttribute('href')
  113. fetch(userURL, { credentials: 'include' })
  114. .then(e => e.text())
  115. .then(html => {
  116. let hideDiv = document.createElement('div')
  117. hideDiv.innerHTML = html
  118. hideDiv.style.display = 'none'
  119. // 头像
  120. userBox.find('.userTop').append($(hideDiv).find('.content img')[0])
  121. // 信息
  122. let infoStr = $(hideDiv).find('.content')[0].innerText
  123. console.log(infoStr)
  124. let userID = /ID号:(\d+)昵称/g.exec(infoStr)[1]
  125. let userName = /昵称:(.+?)妖晶/g.exec(infoStr)[1]
  126. let money = /妖晶:(\d+)/g.exec(infoStr)[1]
  127. let level = /等级:(\d+级) 头衔:.+勋章/g.exec(infoStr)[1]
  128. let levelInfo = /等级:\d+级 头衔:(.+)勋章/g.exec(infoStr)[1]
  129. userBox.find('.userTop').append($(`
  130. <div id="info">
  131. <span>用户: ${userID}</span>
  132. <span>昵称: ${userName}</span>
  133. <span>妖晶: ${money}</span>
  134. <span>等级: ${level}</span>
  135. <span>头衔: ${levelInfo}</span>
  136. </div>
  137. `))
  138. let medals = /勋章<\/b>:(<img src=".+" alt=".">)*/g.exec($(hideDiv).find('.content')[0].innerHTML)[1]
  139. if (medals) {
  140. userBox.find('.userBottom').html(medals)
  141. } else {
  142. userBox.find('.userBottom').html('这个人很穷,没有勋章')
  143. }
  144. // 加载完毕
  145. userBox.find('#loading').remove()
  146. userBox.css('justify-content', 'space-between')
  147. userBox.click(function () {
  148. delUserInfo.call(this, null)
  149. })
  150. })
  151. }
  152.  
  153. let delUserInfo = function (e) {
  154. this.parentNode.style.position = 'inherit'
  155. this.parentNode.querySelector('#user-info-box') && this.parentNode.removeChild(this.parentNode.querySelector('#user-info-box'))
  156. }
  157.  
  158. // 显示全评论
  159. let nextPageURL = null
  160. let nextPageButton = document.querySelector('.more a')
  161. if (nextPageButton) {
  162. nextPageURL = nextPageButton.getAttribute('href')
  163. } else {
  164. addStyle(document)
  165. if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i))) {
  166. makeBtn(document.querySelectorAll('.subtitle')[1])
  167. } else {
  168. $('a[href^="/bbs/userinfo"]').unbind('mouseenter').unbind('mouseleave').hover(viewUserInfo, delUserInfo)
  169. }
  170. return
  171. }
  172. let haveMore = parseInt(nextPageURL.match(/Total=(\d+)/g)[0].split('=')[1]) > 15
  173.  
  174. // 获取更多评论地址
  175. let commentURL = location.protocol + '//' + location.host + nextPageURL.replace('page=2', 'page=1')
  176. // 移除简短评论url 第一个是正文,第二个是评论
  177. let commentDiv = document.querySelectorAll('.content')[1]
  178. commentDiv.innerHTML = ""
  179. let iframe = document.createElement('iframe')
  180. iframe.id = 'full-comment'
  181. iframe.src = commentURL
  182. iframe.width = '100%'
  183. iframe.setAttribute('frameborder', 'no')
  184. iframe.setAttribute('scrolling', 'no')
  185. iframe.setAttribute('border', '0')
  186. iframe.style = `
  187. transition: height 0.3s linear;
  188. `
  189. iframe.onload = function () {
  190. let iframeDocument = document.getElementById('full-comment').contentWindow.document
  191. let frameBody = iframeDocument.body // frameBody.querySelector('.tip')
  192. if (frameBody.querySelector('.tip') && !frameBody.querySelector('input')) {
  193. document.getElementById('full-comment').contentWindow.history.back()
  194. location.reload()
  195. } else {
  196. let refresh = (mutations, observer) => {
  197. let removeEles = ['a[href^="/bbs/message"] + .btBox',
  198. 'a[href^="/bbs/message"]',
  199. '.showpage + .btBox',
  200. '.subtitle'].concat((haveMore) ? [] : '.btBox')
  201. for (let i = 0; i < removeEles.length; i++) {
  202. let node = frameBody.querySelector(removeEles[i])
  203. if (node) {
  204. node.parentNode.removeChild(node)
  205. }
  206. }
  207. if (iframeDocument.querySelector('.showpage')) {
  208. iframeDocument.querySelector('.showpage').style['background-color'] = 'white'
  209. }
  210. if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i))) {
  211. // 把x楼换成可点击
  212. makeBtn(document.querySelectorAll('.subtitle')[1])
  213. iframeDocument.querySelectorAll('[class^="line"]').forEach(makeBtn)
  214. } else {
  215. // hover效果实现
  216. // 楼主信息
  217. $('a[href^="/bbs/userinfo"]').unbind('mouseenter').unbind('mouseleave').hover(viewUserInfo, delUserInfo)
  218. // 评论区用户信息
  219. iframeDocument.querySelectorAll('a[href^="/bbs/userinfo"]').forEach(
  220. (userTag) => {
  221. $(userTag).unbind('mouseenter').unbind('mouseleave').hover(viewUserInfo, delUserInfo)
  222. }
  223. )
  224. }
  225. console.log('调整高度')
  226. setTimeout(() => {
  227. iframe.height = iframeDocument.body.scrollHeight
  228. }, 500)
  229. }
  230. addStyle(document, iframeDocument)
  231. // 观察
  232. var config = { attribute: true, childList: true, subtree: true }
  233. var observer = new MutationObserver(refresh)
  234. observer.observe(frameBody, config)
  235. refresh()
  236. }
  237. }
  238. commentDiv.appendChild(iframe)
  239. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址