// ==UserScript== // @name 微博增强-添加悄悄关注 // @namespace https://github.com/ozingi // @version 2.0.02 // @description 在m.weibo.cn和weibo.com域名下运行的自定义脚本 // @author ozingi // @match https://m.weibo.cn/* // @match https://weibo.com/* // @match https://weibo.com/set/* // @match https://m.weibo.cn/u/* // @match https://m.weibo.cn/setting* // @grant GM_xmlhttpRequest // @connect weibo.cn // @license 版权所有 (C) 2024 ozingi@163.com。允许修改和再分发,但必须保留此版权声明。商业使用需联系作者获得授权。 // @downloadURL https://update.greasyfork.icu/scripts/495840/%E5%BE%AE%E5%8D%9A%E5%A2%9E%E5%BC%BA-%E6%B7%BB%E5%8A%A0%E6%82%84%E6%82%84%E5%85%B3%E6%B3%A8.user.js // @updateURL https://update.greasyfork.icu/scripts/495840/%E5%BE%AE%E5%8D%9A%E5%A2%9E%E5%BC%BA-%E6%B7%BB%E5%8A%A0%E6%82%84%E6%82%84%E5%85%B3%E6%B3%A8.meta.js // ==/UserScript== (function() { 'use strict'; // 获取当前页面的cookie var cookies = document.cookie; // 记录当前页面的URL let lastUrl = window.location.href; // 添加自定义样式 var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = ` .custom-setting-span:active { background-color: orange; } .custom-setting-div { display: none; /* 默认不显示 */ width: 200px; height: 300px; border: 1px solid black; position: absolute; top:10%; right: 5%; z-index:1; background:white; padding: 10px; box-sizing: border-box; } .custom-setting-div input, .custom-setting-div button { margin-top: 10px; width: 100%; } `; document.head.appendChild(style); function setQuietfollow(uid) { // 执行后台访问 GM_xmlhttpRequest({ method: 'GET', url: 'https://weibo.cn/'+uid+'/operation?rl=0', headers:{ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/jxl,image/webp,*/*;q=0.8", "Accept-Encoding": "gzip, deflate, br, zstd", "Accept-Language": "zh-CN,zh-HK;q=0.5", "Connection":"keep-alive", "Cookie": cookies, "Host": "weibo.cn", "Priority": "u=1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.0.0" }, onload: function(response) { // 这里可以根据返回的内容进行相应的处理 //console.log('请求成功,返回的数据:', response.responseText); //console.log(typeof(response.responseText)); // 使用正则表达式匹配St内容 var regexSt = /rl=0&st=(.*?)">/; var matchResult = response.responseText.match(regexSt); var matchesSt = matchResult ? matchResult[1] : false; //console.log("查找st",matchesSt); if(matchesSt!=false){ GM_xmlhttpRequest({ method: 'GET', url: 'https://weibo.cn/attention/addPrivate?uid='+uid+'&rl=0&st='+matchesSt+'', headers:{ "Host": "weibo.cn", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.0.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/jxl,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh-HK;q=0.5", "Accept-Encoding": "gzip, deflate, br, zstd", "Connection": "keep-alive", "Referer": 'https://weibo.cn/'+uid+'/operation?rl=0&rand=6608&p=r', "Cookie": cookies, "Upgrade-Insecure-Requests": "1", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "same-origin", "Sec-Fetch-User": "?1", "sec-ch-ua-platform": "Windows", "sec-ch-ua": '"Edge";v="118", "Chromium";v="118", "Not=A?Brand";v="24"', 'sec-ch-ua-mobile': '?0', 'Priority': 'u=1', 'TE': 'trailers' }, onload: function(response) { // 这里可以根据返回的内容进行相应的处理 //console.log('请求成功,返回的数据:', response.responseText); //console.log(typeof(response.responseText)); // 使用正则表达式匹配
添加用户
'; // 创建UID输入框 var uidInput = document.createElement('input'); uidInput.type = 'text'; uidInput.placeholder = '请输入UID'; // 创建确认添加按钮 var addButton = document.createElement('button'); addButton.textContent = '确认添加'; // 将输入框和按钮添加到设置面板 settingDiv.appendChild(uidInput); settingDiv.appendChild(addButton); // 添加点击事件监听器 newSpan.addEventListener('click', function() { //关闭时刷新悄悄关注列表 if(settingDiv.style.display=='block'){ location.reload(); } // 显示或隐藏设置面板 settingDiv.style.display = settingDiv.style.display === 'none' ? 'block' : 'none'; //console.log(settingDiv.style.display); }); // 添加点击事件监听器 addButton.addEventListener('click', function() { // 执行后台访问 setQuietfollow(uidInput.value) }); // 将新的span标签添加到找到的span标签后面 subHeaderSpan.parentNode.insertBefore(newSpan, subHeaderSpan.nextSibling); // 将设置面板div添加到body中 document.body.appendChild(settingDiv); } }); /* // 保存原始的send函数 var originalSend = XMLHttpRequest.prototype.send; // 修改send函数 XMLHttpRequest.prototype.send = function() { // 在这里添加你的代码,它会在每个请求发送时执行 // 监听请求的load事件,它会在请求完成时触发 this.addEventListener('load', function() { if (this.readyState === 4 && this.status === 200) { // 在这里添加你的代码,它会在请求成功完成时执行 var subHeaderSpan1 = document.querySelector('.box-right.m-box-center-a.m-box-center.m-btn-box'); console.log("搜索列表",subHeaderSpan1) if (subHeaderSpan1) { // 创建新的div元素 var newDiv = document.createElement('div'); newDiv.className = 'box-right m-box-center-a m-box-center m-btn-box'; // 添加自定义类名 newDiv.innerHTML = '