吾爱贴子去图片

在吾爱破解论坛贴子上方添加“关闭图片”按钮,点击后隐藏贴子里的图片

  1. // ==UserScript==
  2. // @name 吾爱贴子去图片
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 在吾爱破解论坛贴子上方添加“关闭图片”按钮,点击后隐藏贴子里的图片
  6. // @author StartMenu
  7. // @match *://*.52pojie.cn/*
  8. // @require https://code.jquery.com/jquery-3.6.0.min.js
  9. // @grant GM_addStyle
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // 等待页面加载完成
  17. window.addEventListener('load', () => {
  18. // 确保 jQuery 已加载
  19. if (typeof jQuery === 'undefined') {
  20. console.error('jQuery 未正确加载');
  21. return;
  22. }
  23.  
  24. // 使用 jQuery.noConflict() 避免与其他库冲突
  25. const $ = jQuery.noConflict();
  26.  
  27. // 找到目标元素
  28. const postReplyElement = document.getElementById('pgt');
  29. if (!postReplyElement) {
  30. console.error('未找到 id="pgt" 的元素');
  31. return;
  32. }
  33.  
  34. // 创建 "关闭图片" 按钮
  35. const closeButton = document.createElement('a');
  36. closeButton.href = 'javascript:void(0)';
  37. closeButton.textContent = '关闭图片';
  38. closeButton.id = 'close_images_button'; // 为按钮设置唯一 ID
  39.  
  40. // 将按钮插入到目标元素后面
  41. postReplyElement.appendChild(closeButton);
  42.  
  43. // 为按钮添加醒目的样式,并确保与其他按钮对齐
  44. GM_addStyle(`
  45. #close_images_button {
  46. display: inline-block; /* 使按钮与其他元素在同一行 */
  47. vertical-align: middle; /* 垂直居中对齐 */
  48. background-color: #ff4d4d; /* 红色背景 */
  49. color: white; /* 白色文字 */
  50. padding: 6px 12px; /* 内边距 */
  51. border-radius: 4px; /* 圆角 */
  52. cursor: pointer; /* 鼠标悬停时显示指针 */
  53. font-weight: bold; /* 加粗文字 */
  54. text-decoration: none; /* 去掉下划线 */
  55. margin-left: 10px; /* 左边距 */
  56. transition: background-color 0.3s; /* 平滑过渡效果 */
  57. height: 24px; /* 设置高度,使其与其他按钮一致 */
  58. line-height: 24px; /* 设置行高,确保文字垂直居中 */
  59. }
  60. #close_images_button:hover {
  61. background-color: #ff0000; /* 悬停时变为深红色 */
  62. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* 添加阴影 */
  63. }
  64. `);
  65.  
  66. // 点击按钮时隐藏图片
  67. closeButton.addEventListener('click', () => {
  68. // 隐藏 id 以 aimg_ 开头的图片
  69. $('img[id^="aimg_"]').prev().remove();
  70. $('img[id^="aimg_"]').remove();
  71. });
  72. });
  73. })();

QingJ © 2025

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