yaohuo

妖火评论全显示

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

  1. // ==UserScript==
  2. // @name yaohuo
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 妖火评论全显示
  6. // @author Polygon
  7. // @match https://yaohuo.me/bbs-*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. let nextPageURL = document.querySelector('.more a').getAttribute('href')
  16. console.log(nextPageURL)
  17. console.log(nextPageURL.match(/Total=(\d+)/g)[0].split('=')[1])
  18. if (parseInt(nextPageURL.match(/Total=(\d+)/g)[0].split('=')[1]) <= 15) {
  19. return
  20. }
  21. // 获取更多评论地址
  22. let commentURL = location.protocol + '//' + location.host + nextPageURL.replace('page=2', 'page=1')
  23. // 移除简短评论url 第一个是正文,第二个是评论
  24. let commentDiv = document.querySelectorAll('.content')[1]
  25. commentDiv.removeChild(commentDiv.querySelector('.recontent'))
  26. commentDiv.removeChild(commentDiv.querySelector('.more'))
  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. `
  37. commentDiv.appendChild(iframe)
  38. setInterval(() => {
  39. try {
  40. let iframeDocument = document.getElementById('full-comment').contentWindow.document
  41. let body = iframeDocument.querySelector('body')
  42. while (true) {
  43. if (body.firstElementChild.className.search('line') == -1) {
  44. body.removeChild(body.firstElementChild)
  45. } else if (body.lastElementChild.className.search('showpage') == -1) {
  46. body.removeChild(body.lastElementChild)
  47. } else {
  48. iframe.height = iframeDocument.body.scrollHeight
  49. break
  50. }
  51. }
  52. } catch (error) {
  53. console.log(error)
  54. }
  55. }, 1200)
  56. })();