分享一段自动删除 Youtube 活动记录的脚本

193 天前
 ooh

功能

这段脚本解决 Youtube 活动记录不能批量清空,需要用户一个个点击删除按钮。

利用浏览器控制台功能运行脚本实现在活动记录页面查找删除按钮自动点击。

注意

如果你不是需要清空自己的活动记录或者你想保留特定的评论、点赞、直播聊天消息你不应该在控制台运行该脚本

使用

在以下页面:

YouTube 上的评论

YouTube 直播中的聊天消息

对 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);

刷新页面或者关闭页面即可终止运行。

952 次点击
所在节点    分享创造
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1117927

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX