按域关闭chrome选项卡

insrf1ej  于 2023-02-01  发布在  Go
关注(0)|答案(2)|浏览(194)

我需要一种方法来关闭所有打开的Chrome标签页从给定的域列表。
例如,我回到家,打开了一些社交网络,新闻网站,或者其他什么。电脑在某个时候休眠了,第二天早上我想回到“生产”模式。有没有什么脚本化的方法来关闭所有浏览给定域名列表下任何页面的chrome标签?
使用Chrome for Windows,最新版本。如果没有其他方法,添加一个Chrome扩展或一些关于如何编写新扩展的指导是可以接受的。

vof42yt1

vof42yt12#

下面是一个扩展,它可以关闭URL中包含“duckduckgo.com/?q=“或“google.com/search“的所有选项卡:
Close Search Tabs,作者:泰根(tai@taigrr.com):

function announce_close(){
    console.log("closing all search tabs")
    chrome.tabs.query({}, function(tabs) {
        var closeable=[];
        for (var i=0; i<tabs.length; ++i) {
            console.log(tabs[i]);
            if(tabs[i].url.includes("google.com/search?")) {    
                closeable.push(tabs[i].id)
            } else if(tabs[i].url.includes("duckduckgo.com/?q=")){
                closeable.push(tabs[i].id)
            }
        }
        chrome.tabs.remove(closeable);
    });
}
chrome.browserAction.onClicked.addListener(function(tab){announce_close()});

代码许可证:

Copyright (C) 2019-2021 by Tai Groot <tai@taigrr.com>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

相关问题