V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
icebay
V2EX  ›  浏览器

Chrome 历史记录自动化删除

  •  
  •   icebay · Apr 13, 2018 · 3083 views
    This topic created in 2938 days ago, the information mentioned may be changed or developed.

    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 replies    2018-04-13 10:54:54 +08:00
    icebay
        1
    icebay  
    OP
       Apr 13, 2018
    如果网络比较慢,可以在 ` clearHistory(delay) ` 执行之前追加一段 ` setTimeout ` 来减慢速度。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1015 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:09 · PVG 06:09 · LAX 15:09 · JFK 18:09
    ♥ Do have faith in what you're doing.