V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
IceBay
V2EX  ›  浏览器

Chrome 历史记录自动化删除

  •  
  •   IceBay · 2018-04-13 10:50:52 +08:00 · 2571 次点击
    这是一个创建于 2176 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Chrome 历史记录自动化删除

    1. 打开历史记录页面,输入关键词搜索需要删除的页面。
    2. 得到结果页面之后刷新一次页面。
    3. 执行下面这段 javascript 代码。
    
    function clearHistory(delay = 300) {
        let historyList = document.querySelectorAll('#history-app /deep/ #content /deep/ #history /deep/ #infinite-list /deep/ history-item /deep/ #checkbox');
    
        console.log(historyList.length);
    
        if (historyList.length > 0) {
            for (let i = 0; i < historyList.length; i++) {
                let item = historyList[i];
    
                item.click();
            }
    
            setTimeout(function () {
                document.querySelector('#history-app /deep/ #toolbar /deep/ cr-toolbar-selection-overlay /deep/ #delete').click();
                setTimeout(function(){
                    document.querySelector('#history-app /deep/ #content /deep/ #history /deep/ dialog /deep/ .action-button').click();
                    clearHistory(delay);
                }, delay);
            }, delay);
        } else {
            location.href = location;
        }
    }
    
    clearHistory();
    
    

    美中不足:一次最多删除 50 条左右的数据,且无法判断是否执行完毕会一直执行下去。但是会自动化执行,所以无需担心多次操作的问题,只需要在删除完记录后 刷新一次页面 或 手动将任务清除 即可。

    1 条回复    2018-04-13 10:54:54 +08:00
    IceBay
        1
    IceBay  
    OP
       2018-04-13 10:54:54 +08:00
    如果网络比较慢,可以在 ` clearHistory(delay) ` 执行之前追加一段 ` setTimeout ` 来减慢速度。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5436 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:07 · PVG 16:07 · LAX 01:07 · JFK 04:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.