常用脚本合集(望采纳)
Sunsh4j opened this issue · comments
1.获取「当前窗口」简要信息:
//.js
chrome.windows.getCurrent(
{},
function(win){
sendReplyToQuicker(true, "ok", win, qk_msg_serial)
}
)
2.获取「当前(最后聚焦)窗口「「所有标签」」」的中等详细信息:(提取数据:$= JArray.Parse({raw}.ToString()).SelectTokens("[*].url"))
//.js
chrome.windows.getLastFocused({populate:true}, function(win){
var wid = win.tabs;
sendReplyToQuicker(true, "ok", wid, qk_msg_serial)
});
3.获取所有浏览器窗口的窗口ID(一行一个):
chrome.windows.getAll({}, function(windows) {
let windowIds = [];
windows.forEach(window => {
windowIds.push(window.id);
});
// windowIds数组现在包含了所有窗口的windowId
sendReplyToQuicker(true, "ok", windowIds, qk_msg_serial);
});
4.获取「指定窗口ID」的简要信息:
$$chrome.windows.get({windowId}, function(win) {
// 调用回调函数,传入指定窗口ID
sendReplyToQuicker(true, "ok", win, qk_msg_serial);
});
5.获取「指定窗口ID」的窗口所有信息:
$$// 指定要获取的窗口ID
const windowId = {windowId};
chrome.windows.get(windowId, {populate: true}, function(window) {
// window对象包含指定ID窗口的详细信息
// 例如获取窗口的标题
let title = window.title;
// TODO: 对窗口信息进行处理
sendReplyToQuicker(true, "ok", window, qk_msg_serial);
});
6.获取「当前窗口」的「标签个数」:(提取数据:$= JObject.Parse({rawResponse}).SelectToken("data"))
chrome.tabs.query({ currentWindow: true }, function(tabs) {
var numberOfTabs = tabs.length;
sendReplyToQuicker(true, "ok", numberOfTabs, qk_msg_serial);
});
7.获取「当前标签页」在所有标签中的「位置」:(提取数据:$= {tabInfo}["index"])
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
var currentTab = tabs[0];
sendReplyToQuicker(true, "ok", currentTab, qk_msg_serial);
});
8.用(窗口)方法指定「标签id」设置为「前台」:
$$// 将标签页ID为1133169927的窗口设置为前台窗口
chrome.tabs.get({tabId}, function(tab){
chrome.windows.get(tab.windowId, function(win){
chrome.windows.update(win.id, {focused: true});
sendReplyToQuicker(true, "ok", null, qk_msg_serial);
});
});
10.指定「窗口ID」,设置为「前台窗口」:
$$// 指定要设置为前台的窗口ID
chrome.windows.update({windowId}, {focused: true}, function() {
// 窗口设置前台成功的回调函数
sendReplyToQuicker(true, "ok", null, qk_msg_serial);
});
11.「指定窗口ID」窗口「最大化」:
$$
chrome.windows.update({windowId}, {state: "maximized"});
12.获取「指定标签页ID」的窗口简要信息:
$$// 获取给定标签页ID的窗口信息
chrome.tabs.get({tabId}, function(tab){
chrome.windows.get(tab.windowId, function(win){
sendReplyToQuicker(true, "ok", win, qk_msg_serial);
});
});
13.激活指定的tabID,为当前页面,可实现在后台操作(删除第四行的窗口代码即可):
$$function ActiveTabById(tabId) {
chrome.tabs.get(tabId, function (tab) {
chrome.tabs.update(tab.id, { active: true });
chrome.windows.update(tab.windowId, { focused: true });
})
}
ActiveTabById({标签页ID});
14.「切换」到指定tabID页:
$$chrome.tabs.update({tabId}, { selected: true });
15.在当前页面的「相邻」位置打开指定网页:
$$//.js
window.open('{url}', '_blank', 'noopener');
16.「后台」打开指定链接,并返回页面的详细信息:(提取数据:$={returnTab}["id"];)
$$//.js
chrome.tabs.create({ url: "https://www.ckcloud.shop/#/register", active: false }, function (tab) {
sendReplyToQuicker(true, "ok", tab, qk_msg_serial);
});
17.「后台」打开「新窗口」并打开「指定链接」,并返回第 一个新标签的「中等详细信息」:
chrome.windows.create({ url: "https://getquicker.net/KC", state: "minimized" }, function(window){
// 调用 sendReplyToQuicker 方法传回窗口 ID
sendReplyToQuicker(true, "ok", window.tabs[0], qk_msg_serial);
});
18.指定「链接或tabid」创建★★★新窗口★★★。返回窗口ID:(提取数据:$= JObject.Parse({rawResponse}).SelectToken("data"))
$$// 创建新窗口
chrome.windows.create({
url: "{url}"
}, (window) => {
// 在回调函数中可以获取新窗口的 ID
const newWindowId = window.id;
// 调用 sendReplyToQuicker 方法传回窗口 ID
sendReplyToQuicker(true, "ok", newWindowId, qk_msg_serial);
});
19.指定2个链接,打开2个窗口(可后台),并返回标签信息:
$$//.js
(async function() {
const createWindow = url => {
return new Promise((resolve, reject) => {
chrome.windows.create(
{ url: url, state: "minimized" },
window => resolve(window)
);
});
};
const updateWindow = window => {
return new Promise((resolve, reject) => {
chrome.windows.update(
window.id,
{ focused: true, drawAttention: false, state: "minimized" },
() => resolve(window)
);
});
};
const baiduWindow = await createWindow("{url1}");
const taobaoWindow = await createWindow("{url2}");
const baiduTab = baiduWindow.tabs[0];
const taobaoTab = taobaoWindow.tabs[0];
const baiduTabId = baiduTab.id;
const taobaoTabId = taobaoTab.id;
await updateWindow(baiduWindow);
await updateWindow(taobaoWindow);
sendReplyToQuicker(true, "ok", [baiduTabId, taobaoTabId], qk_msg_serial);
// 这里可以执行在窗口创建、更新和消息发送完成后执行的其他操作
})();
20.指定链接,在当前页面的右边打开新页面,并返回tabID:(提取信息:$= JObject.Parse({rawResponse}).SelectToken("data"))
// 获取当前激活的标签页
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const activeTab = tabs[0];
// 创建新标签页
chrome.tabs.create({
url: "https://getquicker.net/KC",
index: activeTab.index + 1
}, function(tab) {
// 获取新建标签页ID
const newTabId = tab.id;
// 回复给Quicker
sendReplyToQuicker(true, "ok", newTabId, qk_msg_serial);
});
});
21.将指定tabid的标签页分到一个新的群组里
$$
function groupTabsIntoNewGroup(tabIds) {
chrome.tabs.group({ tabIds: tabIds });
}
// 调用函数,将指定标签页ID分到一个新的组里
groupTabsIntoNewGroup([{tabId},{tabId1},{tabId2},{tabId3}]);
22.「后台」打开「无痕」「新窗口」并打开「指定链接」,并返回第一个新标签的「中等详细信息」
$$
chrome.windows.create({
url: "{url}",
state: "minimized",
incognito: true // 设置为 true 表示以无痕模式打开
}, function(window){
// 调用 sendReplyToQuicker 方法传回窗口 ID
sendReplyToQuicker(true, "ok", window.tabs[0], qk_msg_serial);
});