(function(window) { // 定义一个异步的添加函数 async function addById(id) { // 填充输入框并触发 change 事件 let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set; let changeEvent = new Event('change', { bubbles: true}); let inputBox = document.querySelector('input[aria-label="Search query"]'); nativeInputValueSetter.call(inputBox, id); inputBox.dispatchEvent(changeEvent); // 等待一段时间,让页面有机会更新 await new Promise(resolve => setTimeout(resolve, 2000)); // 点击“添加”按钮 let addButton = document.querySelector('div[role="button"][aria-label="Add"]'); if (addButton) { addButton.click(); } // 再等待一段时间,让页面有机会更新 await new Promise(resolve => setTimeout(resolve, 2000)); } // 从 localStorage 获取 ID 列表 let storedIds = JSON.parse(localStorage.getItem('MyFollowingIds')) || []; // 按顺序添加所有 ID async function addAllIds() { for (let id of storedIds) { await addById(id); } } // 开始执行 addAllIds(); })(window);