25 lines
784 B
JavaScript
25 lines
784 B
JavaScript
export function openConfigUrl(domain) {
|
|||
|
|
if (!domain)
|
||
|
|
return;
|
||
|
|
const url = /^https?:\/\//i.test(domain) ? domain : "http://" + domain;
|
||
|
|
window.open(url, "_blank", "noopener");
|
||
|
|
}
|
||
|
|
export async function fetchTitleByDomain(domain) {
|
||
|
|
try {
|
||
|
|
const base = /^https?:\/\//i.test(domain) ? domain : "*://" + domain;
|
||
|
|
const patterns = [base];
|
||
|
|
if (!base.endsWith("*"))
|
||
|
|
patterns.push(base + "/*");
|
||
|
|
const tabs = await chrome.tabs.query({ url: patterns });
|
||
|
|
for (const tab of tabs) {
|
||
|
|
if (tab.title)
|
||
|
|
return tab.title;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (e) { }
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
export function closeAllMenus() {
|
||
|
|
document.querySelectorAll(".config-menu.open").forEach((m) => m.classList.remove("open"));
|
||
|
|
}
|