Toggle Low Heat Posts

切换隐藏/显示热度低于150的帖子,并使按钮更加显眼

  1. // ==UserScript==
  2. // @name Toggle Low Heat Posts
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description 切换隐藏/显示热度低于150的帖子,并使按钮更加显眼
  6. // @author Your Name
  7. // @match https://bbs.hupu.com/topic-daily-hot
  8. // @license LGPL
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let isHidden = false; // 状态变量,初始为未隐藏
  16.  
  17. // 创建Toggle按钮并添加到页面右上方
  18. const toggleButton = document.createElement('button');
  19. updateButtonText();
  20. toggleButton.style.position = 'fixed';
  21. toggleButton.style.top = '20px';
  22. toggleButton.style.right = '20px';
  23. toggleButton.style.zIndex = '9999';
  24. toggleButton.style.padding = '10px 20px';
  25. toggleButton.style.fontSize = '16px';
  26. toggleButton.style.backgroundColor = '#1890ff'; // 蓝色背景
  27. toggleButton.style.color = '#ffffff'; // 白色文字
  28. toggleButton.style.border = 'none';
  29. toggleButton.style.borderRadius = '5px';
  30. toggleButton.style.cursor = 'pointer';
  31. toggleButton.style.boxShadow = '0 2px 5px rgba(0,0,0,0.3)';
  32. document.body.appendChild(toggleButton);
  33.  
  34. // 添加按钮悬停效果
  35. toggleButton.addEventListener('mouseenter', function() {
  36. toggleButton.style.backgroundColor = '#40a9ff'; // 悬停时颜色变深
  37. });
  38. toggleButton.addEventListener('mouseleave', function() {
  39. toggleButton.style.backgroundColor = '#1890ff'; // 恢复原始颜色
  40. });
  41.  
  42. // 更新按钮文本和状态
  43. function updateButtonText() {
  44. toggleButton.innerText = isHidden ? 'Show Low Heat Posts' : 'Hide Low Heat Posts';
  45. }
  46.  
  47. // 点击Toggle按钮时执行函数
  48. toggleButton.addEventListener('click', function() {
  49. const posts = document.querySelectorAll('.bbs-sl-web-post-body');
  50. posts.forEach(post => {
  51. const replyCountText = post.querySelector('.post-datum').innerText.split('/')[0].trim();
  52. const replyCount = parseInt(replyCountText, 10);
  53. if (replyCount < 150) {
  54. post.style.display = isHidden ? '' : 'none'; // 根据状态显示或隐藏
  55. }
  56. });
  57. isHidden = !isHidden; // 切换状态
  58. updateButtonText(); // 更新按钮文本
  59. });
  60. })();

QingJ © 2025

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