这段脚本解决 Youtube 活动记录不能批量清空,需要用户一个个点击删除按钮。
利用浏览器控制台功能运行脚本实现在活动记录页面查找删除按钮自动点击。
如果你不是需要清空自己的活动记录或者你想保留特定的评论、点赞、直播聊天消息你不应该在控制台运行该脚本
在以下页面:
打开浏览器控制台运行脚本:
const label = "删除活动记录"
const container = document.querySelector('div.jkOv3d');
let lastClicked = null;
setInterval(() => {
if (!container) return;
const button = Array.from(container.querySelectorAll('button, [role="button"]'))
.find(el =>
el.getAttribute('aria-label')?.includes(label) &&
getComputedStyle(el).display !== 'none' &&
getComputedStyle(el).visibility !== 'hidden' &&
el.offsetParent !== null
);
if (button && button !== lastClicked) {
button.style.backgroundColor = '#ff0000';
lastClicked = button;
setTimeout(() => button.click(), 50);
}
}, 100);
setInterval(() => {
if (!container) return;
const button = Array.from(container.querySelectorAll('button, [role="button"]'))
.find(el =>
el.getAttribute('aria-label')?.includes(label) &&
getComputedStyle(el).display !== 'none' &&
getComputedStyle(el).visibility !== 'hidden' &&
el.offsetParent !== null
);
if (button === undefined) {
window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" });
}
}, 3000);
刷新页面或者关闭页面即可终止运行。