雪球快速拉黑用户按钮

在页面上直接为雪球网的个股讨论添加拉黑按钮

  1. // ==UserScript==
  2. // @name 雪球快速拉黑用户按钮
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 在页面上直接为雪球网的个股讨论添加拉黑按钮
  6. // @author 很太
  7. // @match https://xueqiu.com/*
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_notification
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const observer = new MutationObserver(mutations => mutations.forEach(addButtonIfNewNodes));
  16.  
  17. function addButtonIfNewNodes(mutation) {
  18. if (mutation.addedNodes.length) addButton();
  19. }
  20.  
  21. function addButton() {
  22. document.querySelectorAll('article.timeline__item').forEach(item => {
  23. if (!item.querySelector('.custom-blacklist-btn')) {
  24. const userInfoLink = item.querySelector('a[data-tooltip]');
  25. if (userInfoLink) {
  26. const blockButton = createBlockButton(userInfoLink.getAttribute('data-tooltip'));
  27. const actionsContainer = item.querySelector('.timeline__item__ft');
  28. actionsContainer && actionsContainer.appendChild(blockButton);
  29. }
  30. }
  31. });
  32. }
  33.  
  34. function createBlockButton(userId) {
  35. const blockButton = document.createElement('a');
  36. blockButton.className = 'timeline__item__control custom-blacklist-btn';
  37. blockButton.innerHTML = '<i class="iconfont"></i><span>拉黑</span>';
  38. blockButton.href = 'javascript:void(0);';
  39. blockButton.onclick = () => blockUser(userId);
  40. return blockButton;
  41. }
  42.  
  43. function blockUser(userId) {
  44. GM_xmlhttpRequest({
  45. method: 'POST',
  46. url: 'https://xueqiu.com/blocks/create.json',
  47. headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
  48. data: `user_id=${encodeURIComponent(userId)}`,
  49. onload: (response) => handleResponse(response, userId),
  50. onerror: () => GM_notification('拉黑请求发送失败。', '请求失败')
  51. });
  52. }
  53.  
  54. function handleResponse(response, userId) {
  55. const jsonResponse = JSON.parse(response.responseText);
  56. if (response.status === 200 && jsonResponse.success) {
  57. GM_notification(`用户 ${userId} 已被拉黑`, '拉黑成功');
  58. } else {
  59. GM_notification('拉黑操作失败,请稍后再试。', '操作失败');
  60. }
  61. }
  62.  
  63. observer.observe(document.body, { childList: true, subtree: true });
  64. addButton();
  65. })();

QingJ © 2025

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