mirror of
https://github.com/nkcmr/HyperTab.git
synced 2026-04-05 08:57:01 +02:00
new feature: close tabs from list
This commit is contained in:
326
package-lock.json
generated
326
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -19,16 +19,17 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/chrome": "^0.0.251",
|
"@types/chrome": "^0.0.251",
|
||||||
"esbuild": "^0.19.5",
|
|
||||||
"npm-run-all": "^4.1.5",
|
|
||||||
"typescript": "^5.2.2",
|
|
||||||
"@types/lodash.uniq": "^4.5.9",
|
"@types/lodash.uniq": "^4.5.9",
|
||||||
"@types/react": "^18.2.37",
|
"@types/react": "^18.2.37",
|
||||||
"@types/react-dom": "^18.2.15",
|
"@types/react-dom": "^18.2.15",
|
||||||
|
"esbuild": "^0.19.5",
|
||||||
"fuse.js": "^7.0.0",
|
"fuse.js": "^7.0.0",
|
||||||
"lodash.uniq": "^4.5.0",
|
"lodash.uniq": "^4.5.0",
|
||||||
|
"npm-run-all": "^4.1.5",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-hotkeys-hook": "^4.4.1"
|
"react-hotkeys-hook": "^4.4.1",
|
||||||
|
"styled-components": "^6.1.9",
|
||||||
|
"typescript": "^5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
popup.css
35
popup.css
@@ -132,20 +132,25 @@ table {
|
|||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*:before,
|
||||||
|
*:after {
|
||||||
|
-webkit-box-sizing: inherit;
|
||||||
|
-moz-box-sizing: inherit;
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
width: 500px;
|
width: 500px;
|
||||||
color: black;
|
color: black;
|
||||||
font-family: system-ui;
|
font-family: system-ui;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ht-tab:hover {
|
|
||||||
background-color: #efefef;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ht-tab-location {
|
|
||||||
color: #e9e9e9;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
@@ -157,16 +162,4 @@ body {
|
|||||||
background-color: #2b2b2b;
|
background-color: #2b2b2b;
|
||||||
color: #f2f2f2;
|
color: #f2f2f2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ht-search-wrapper .ht-search-input {
|
|
||||||
background-color: #2b2b2b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ht-tab-location {
|
|
||||||
color: #e9e9e9;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ht-tab:hover {
|
|
||||||
background-color: #4e4e4e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,55 +35,65 @@ setInterval(() => {
|
|||||||
tabSwitches = uniq(tabSwitches);
|
tabSwitches = uniq(tabSwitches);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
async function listTabs(): Promise<chrome.tabs.Tab[]> {
|
||||||
|
const _tabs = await browser.tabs.query({});
|
||||||
|
// filter out file:///... things, safari does not really have
|
||||||
|
// safari://... things like chrome
|
||||||
|
const tabs = _tabs.filter((t) => t.url || t.title);
|
||||||
|
|
||||||
|
const hit = new Map<number, boolean>(
|
||||||
|
tabs.filter((t) => !!t.id).map((t) => [t.id!, false])
|
||||||
|
);
|
||||||
|
const tabsById = new Map<number, chrome.tabs.Tab>(
|
||||||
|
tabs.filter((t) => !!t.id).map((t) => [t.id!, t])
|
||||||
|
);
|
||||||
|
const resultTabs = [];
|
||||||
|
for (let tabId of tabSwitches.slice(1)) {
|
||||||
|
if (hit.get(tabId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hit.set(tabId, true);
|
||||||
|
const tab = tabsById.get(tabId);
|
||||||
|
if (!tab) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
resultTabs.push(tab);
|
||||||
|
}
|
||||||
|
for (let [tabId, didHit] of hit.entries()) {
|
||||||
|
if (didHit) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const tab = tabsById.get(tabId);
|
||||||
|
if (!tab) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
resultTabs.push(tab);
|
||||||
|
}
|
||||||
|
return resultTabs;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
browser.runtime.onConnect.addListener((port) => {
|
browser.runtime.onConnect.addListener((port) => {
|
||||||
port.onMessage.addListener((message) => {
|
port.onMessage.addListener(async (message) => {
|
||||||
switch (message.rpc) {
|
switch (message.rpc) {
|
||||||
|
case "closeTab":
|
||||||
|
await browser.tabs.remove(message.args.tabID);
|
||||||
|
port.postMessage({
|
||||||
|
result: await listTabs(),
|
||||||
|
id: message.id,
|
||||||
|
});
|
||||||
|
return;
|
||||||
case "listTabs":
|
case "listTabs":
|
||||||
console.time(`rpc:listTabs:${message.id}`);
|
console.time(`rpc:listTabs:${message.id}`);
|
||||||
browser.tabs
|
try {
|
||||||
.query({})
|
const resultTabs = await listTabs();
|
||||||
.then((tabs) => {
|
port.postMessage({
|
||||||
// filter out file:///... things, safari does not really have
|
result: resultTabs,
|
||||||
// safari://... things like chrome
|
id: message.id,
|
||||||
tabs = tabs.filter((t) => t.url || t.title);
|
|
||||||
|
|
||||||
const hit = new Map<number, boolean>(
|
|
||||||
tabs.filter((t) => !!t.id).map((t) => [t.id!, false])
|
|
||||||
);
|
|
||||||
const tabsById = new Map<number, chrome.tabs.Tab>(
|
|
||||||
tabs.filter((t) => !!t.id).map((t) => [t.id!, t])
|
|
||||||
);
|
|
||||||
const resultTabs = [];
|
|
||||||
for (let tabId of tabSwitches.slice(1)) {
|
|
||||||
if (hit.get(tabId)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
hit.set(tabId, true);
|
|
||||||
const tab = tabsById.get(tabId);
|
|
||||||
if (!tab) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
resultTabs.push(tab);
|
|
||||||
}
|
|
||||||
for (let [tabId, didHit] of hit.entries()) {
|
|
||||||
if (didHit) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const tab = tabsById.get(tabId);
|
|
||||||
if (!tab) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
resultTabs.push(tab);
|
|
||||||
}
|
|
||||||
port.postMessage({
|
|
||||||
result: resultTabs,
|
|
||||||
id: message.id,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
console.timeEnd(`rpc:listTabs:${message.id}`);
|
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
console.timeEnd(`rpc:listTabs:${message.id}`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
port.postMessage({
|
port.postMessage({
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import React, {
|
|||||||
} from "react";
|
} from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import { useHotkeys } from "react-hotkeys-hook";
|
import { useHotkeys } from "react-hotkeys-hook";
|
||||||
|
import { styled } from "styled-components";
|
||||||
import "./scrollIntoViewIfNeededPolyfill";
|
import "./scrollIntoViewIfNeededPolyfill";
|
||||||
|
|
||||||
function t(
|
function t(
|
||||||
@@ -31,6 +32,7 @@ const browser = chrome;
|
|||||||
|
|
||||||
interface BackgroundPage {
|
interface BackgroundPage {
|
||||||
listTabs(): Promise<chrome.tabs.Tab[]>;
|
listTabs(): Promise<chrome.tabs.Tab[]>;
|
||||||
|
closeTab(tabID: number): Promise<chrome.tabs.Tab[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function useBackgroundPage(): BackgroundPage {
|
function useBackgroundPage(): BackgroundPage {
|
||||||
@@ -80,6 +82,18 @@ function useBackgroundPage(): BackgroundPage {
|
|||||||
port.current.postMessage({ rpc: "listTabs", id });
|
port.current.postMessage({ rpc: "listTabs", id });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
closeTab(tabID) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const id = ++msgId.current;
|
||||||
|
waiter.current.set(id, {
|
||||||
|
reject,
|
||||||
|
resolve(value) {
|
||||||
|
resolve(value as chrome.tabs.Tab[]);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
port.current.postMessage({ rpc: "closeTab", id, args: { tabID } });
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,37 +147,41 @@ const HighlightMatches: FunctionComponent<{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// <big_sigh> ...
|
// // <big_sigh> ...
|
||||||
function faviconsWork(tabURL: string, size: number): Promise<boolean> {
|
// function faviconsWork(tabURL: string, size: number): Promise<boolean> {
|
||||||
return new Promise((resolve) => {
|
// return new Promise((resolve) => {
|
||||||
const hiddenDiv = document.createElement("div", {});
|
// const hiddenDiv = document.createElement("div", {});
|
||||||
hiddenDiv.setAttribute("style", "display:none;");
|
// hiddenDiv.setAttribute("style", "display:none;");
|
||||||
const testImg = document.createElement("img");
|
// const testImg = document.createElement("img");
|
||||||
testImg.src = faviconURL({ url: tabURL } as chrome.tabs.Tab, 32)!;
|
// testImg.src = faviconURL({ url: tabURL } as chrome.tabs.Tab, 32)!;
|
||||||
testImg.onerror = () => {
|
// testImg.onerror = () => {
|
||||||
document.body.removeChild(hiddenDiv);
|
// document.body.removeChild(hiddenDiv);
|
||||||
resolve(false);
|
// resolve(false);
|
||||||
};
|
// };
|
||||||
testImg.onload = () => {
|
// testImg.onload = () => {
|
||||||
document.body.removeChild(hiddenDiv);
|
// document.body.removeChild(hiddenDiv);
|
||||||
resolve(true);
|
// resolve(true);
|
||||||
};
|
// };
|
||||||
hiddenDiv.appendChild(testImg);
|
// hiddenDiv.appendChild(testImg);
|
||||||
document.body.appendChild(hiddenDiv);
|
// document.body.appendChild(hiddenDiv);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
function faviconURL(t: chrome.tabs.Tab, size: number): string | undefined {
|
function faviconURL(t: chrome.tabs.Tab, size: number): string | undefined {
|
||||||
if (t.favIconUrl) {
|
return (
|
||||||
return t.favIconUrl;
|
t.favIconUrl ??
|
||||||
}
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
|
||||||
if (!t.url) {
|
);
|
||||||
return;
|
// if (t.favIconUrl) {
|
||||||
}
|
// return t.favIconUrl;
|
||||||
const url = new URL(browser.runtime.getURL("/_favicon/"));
|
// }
|
||||||
url.searchParams.set("pageUrl", t.url);
|
// if (!t.url) {
|
||||||
url.searchParams.set("size", `${size}`);
|
// return;
|
||||||
return url.toString();
|
// }
|
||||||
|
// const url = new URL(browser.runtime.getURL("/_favicon/"));
|
||||||
|
// url.searchParams.set("pageUrl", t.url);
|
||||||
|
// url.searchParams.set("size", `${size}`);
|
||||||
|
// return url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
const prefersDarkMode = (): boolean => {
|
const prefersDarkMode = (): boolean => {
|
||||||
@@ -187,23 +205,116 @@ const useDarkMode = (): boolean => {
|
|||||||
return dm;
|
return dm;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const POPUP_WIDTH = 500;
|
||||||
|
|
||||||
|
const TAB_ITEM_WIDTH = POPUP_WIDTH;
|
||||||
|
const TAB_ITEM_PADDING_PX = 15;
|
||||||
|
const TAB_ITEM_FAVICON_SIZE = 30;
|
||||||
|
const TAB_ITEM_FLEX_GAP = 15;
|
||||||
|
const TAB_ITEM_MAIN_WIDTH =
|
||||||
|
TAB_ITEM_WIDTH -
|
||||||
|
TAB_ITEM_PADDING_PX * 2 -
|
||||||
|
TAB_ITEM_FAVICON_SIZE -
|
||||||
|
TAB_ITEM_FLEX_GAP;
|
||||||
|
|
||||||
|
const SEARCH_CONTAINER_WIDTH = POPUP_WIDTH;
|
||||||
|
const SEARCH_ICON_SIZE = 24;
|
||||||
|
const SEARCH_ICON_CONTAINER_SIZE = 30;
|
||||||
|
const SEARCH_ICON_PADDING = (SEARCH_ICON_CONTAINER_SIZE - SEARCH_ICON_SIZE) / 2;
|
||||||
|
const SEARCH_CONTAINER_FLEX_GAP = TAB_ITEM_FLEX_GAP;
|
||||||
|
const SEARCH_CONTAINER_PADDING = TAB_ITEM_PADDING_PX;
|
||||||
|
const SEARCH_INPUT_WIDTH =
|
||||||
|
SEARCH_CONTAINER_WIDTH -
|
||||||
|
SEARCH_CONTAINER_PADDING * 2 -
|
||||||
|
SEARCH_ICON_CONTAINER_SIZE -
|
||||||
|
SEARCH_CONTAINER_FLEX_GAP;
|
||||||
|
|
||||||
|
const TabList = styled.div`
|
||||||
|
max-height: 500px;
|
||||||
|
overflow: scroll;
|
||||||
|
`;
|
||||||
|
const TabListEmpty = styled.div`
|
||||||
|
padding: 1.5em;
|
||||||
|
font-size: 1.1em;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
`;
|
||||||
|
const TabItem = styled.div<{ $selected: boolean; $dark: boolean }>`
|
||||||
|
width: ${TAB_ITEM_WIDTH}px;
|
||||||
|
padding: ${TAB_ITEM_PADDING_PX}px;
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: ${(props) =>
|
||||||
|
props.$selected ? (props.$dark ? "#535353" : "#e9e9e9") : "inherit"};
|
||||||
|
display: flex;
|
||||||
|
gap: ${TAB_ITEM_FLEX_GAP}px;
|
||||||
|
align-items: center;
|
||||||
|
&:hover {
|
||||||
|
background-color: #efefef;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const TabItemFavicon = styled.div`
|
||||||
|
background-color: #d9d9d9;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 0.5em;
|
||||||
|
width: ${TAB_ITEM_FAVICON_SIZE}px;
|
||||||
|
height: ${TAB_ITEM_FAVICON_SIZE}px;
|
||||||
|
padding: 7px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
`;
|
||||||
|
const TabItemMain = styled.div`
|
||||||
|
width: ${TAB_ITEM_MAIN_WIDTH}px;
|
||||||
|
`;
|
||||||
|
const TabItemMainTitle = styled.div<{ $dark: boolean }>`
|
||||||
|
color: ${(props) => (props.$dark ? "#e9e9e9" : "#2b2b2b")};
|
||||||
|
font-size: 1.1em;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
`;
|
||||||
|
const TabItemMainHostname = styled.div`
|
||||||
|
color: #6e6e6e;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const SearchContainer = styled.div`
|
||||||
|
display: flex;
|
||||||
|
width: ${SEARCH_CONTAINER_WIDTH}px;
|
||||||
|
gap: ${TAB_ITEM_FLEX_GAP}px;
|
||||||
|
padding: ${TAB_ITEM_PADDING_PX}px;
|
||||||
|
align-items: center;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const SearchIconLeftContainer = styled.div`
|
||||||
|
padding: ${SEARCH_ICON_PADDING}px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const SearchInputRightContainer = styled.div``;
|
||||||
|
const SearchInput = styled.input`
|
||||||
|
width: ${SEARCH_INPUT_WIDTH}px;
|
||||||
|
outline: none;
|
||||||
|
border: none;
|
||||||
|
font-size: 1.2em;
|
||||||
|
`;
|
||||||
|
|
||||||
const Popup: FunctionComponent = () => {
|
const Popup: FunctionComponent = () => {
|
||||||
const darkMode = useDarkMode();
|
const darkMode = useDarkMode();
|
||||||
const [tabSelector, setTabSelector] = useState(0);
|
const [tabSelector, setTabSelector] = useState(0);
|
||||||
const [tabs, setTabs] = useState<chrome.tabs.Tab[]>([]);
|
const [tabs, setTabs] = useState<chrome.tabs.Tab[]>([]);
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
|
||||||
const FAVICON_NOT_SUPPORTED = 0;
|
// const FAVICON_NOT_SUPPORTED = 0;
|
||||||
const FAVICON_SUPPORTED_VIA_EXT_URL = 1;
|
// const FAVICON_SUPPORTED_VIA_EXT_URL = 1;
|
||||||
const FAVICON_SUPPORTED_VIA_TAB_DATA = 2;
|
// const FAVICON_SUPPORTED_VIA_TAB_DATA = 2;
|
||||||
const [enableFavicons, setEnabledFavicons] = useState(FAVICON_NOT_SUPPORTED);
|
// const [enableFavicons, setEnabledFavicons] = useState(FAVICON_NOT_SUPPORTED);
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
faviconsWork("https://www.google.com", 32).then((ok) => {
|
// faviconsWork("https://www.google.com", 32).then((ok) => {
|
||||||
if (enableFavicons === 0) {
|
// if (enableFavicons === 0) {
|
||||||
setEnabledFavicons(FAVICON_SUPPORTED_VIA_EXT_URL);
|
// setEnabledFavicons(FAVICON_SUPPORTED_VIA_EXT_URL);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}, []);
|
// }, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (tabs.length === 0) {
|
if (tabs.length === 0) {
|
||||||
@@ -278,9 +389,9 @@ const Popup: FunctionComponent = () => {
|
|||||||
bgpage
|
bgpage
|
||||||
.listTabs()
|
.listTabs()
|
||||||
.then((returnedTabs) => {
|
.then((returnedTabs) => {
|
||||||
if (returnedTabs.find((t) => !!t.favIconUrl)) {
|
// if (returnedTabs.find((t) => !!t.favIconUrl)) {
|
||||||
setEnabledFavicons(FAVICON_SUPPORTED_VIA_TAB_DATA);
|
// setEnabledFavicons(FAVICON_SUPPORTED_VIA_TAB_DATA);
|
||||||
}
|
// }
|
||||||
setTabs(returnedTabs);
|
setTabs(returnedTabs);
|
||||||
})
|
})
|
||||||
.finally(() => {});
|
.finally(() => {});
|
||||||
@@ -297,18 +408,16 @@ const Popup: FunctionComponent = () => {
|
|||||||
(selectedTabEle as any).current.scrollIntoViewIfNeeded(false);
|
(selectedTabEle as any).current.scrollIntoViewIfNeeded(false);
|
||||||
}, [selectedTabEle.current]);
|
}, [selectedTabEle.current]);
|
||||||
|
|
||||||
|
const [tabHover, setTabHover] = useState<number | null>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div
|
<SearchContainer>
|
||||||
style={{ padding: "1em", display: "flex" }}
|
<SearchIconLeftContainer>
|
||||||
className="ht-search-wrapper"
|
|
||||||
>
|
|
||||||
<div style={{ marginRight: "1em" }}>
|
|
||||||
<svg
|
<svg
|
||||||
style={{ scale: "0.85" }}
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
width="24"
|
width={SEARCH_ICON_SIZE}
|
||||||
height="24"
|
height={SEARCH_ICON_SIZE}
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
@@ -316,128 +425,100 @@ const Popup: FunctionComponent = () => {
|
|||||||
d="M23.809 21.646l-6.205-6.205c1.167-1.605 1.857-3.579 1.857-5.711 0-5.365-4.365-9.73-9.731-9.73-5.365 0-9.73 4.365-9.73 9.73 0 5.366 4.365 9.73 9.73 9.73 2.034 0 3.923-.627 5.487-1.698l6.238 6.238 2.354-2.354zm-20.955-11.916c0-3.792 3.085-6.877 6.877-6.877s6.877 3.085 6.877 6.877-3.085 6.877-6.877 6.877c-3.793 0-6.877-3.085-6.877-6.877z"
|
d="M23.809 21.646l-6.205-6.205c1.167-1.605 1.857-3.579 1.857-5.711 0-5.365-4.365-9.73-9.731-9.73-5.365 0-9.73 4.365-9.73 9.73 0 5.366 4.365 9.73 9.73 9.73 2.034 0 3.923-.627 5.487-1.698l6.238 6.238 2.354-2.354zm-20.955-11.916c0-3.792 3.085-6.877 6.877-6.877s6.877 3.085 6.877 6.877-3.085 6.877-6.877 6.877c-3.793 0-6.877-3.085-6.877-6.877z"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</SearchIconLeftContainer>
|
||||||
<input
|
<SearchInputRightContainer>
|
||||||
className="ht-search-input"
|
<SearchInput
|
||||||
type="text"
|
type="text"
|
||||||
autoFocus
|
autoFocus
|
||||||
placeholder={t("ui_search_tabs")}
|
placeholder={t("ui_search_tabs")}
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
style={{
|
onKeyDown={(e) => {
|
||||||
width: "100%",
|
if (e.key === "ArrowDown") {
|
||||||
outline: "none",
|
selectNext();
|
||||||
border: "none",
|
} else if (e.key === "ArrowUp") {
|
||||||
fontSize: "1.1em",
|
selectPrev();
|
||||||
}}
|
} else if (e.key === "Enter") {
|
||||||
onKeyDown={(e) => {
|
goToTab();
|
||||||
if (e.key === "ArrowDown") {
|
}
|
||||||
selectNext();
|
}}
|
||||||
} else if (e.key === "ArrowUp") {
|
spellCheck="false"
|
||||||
selectPrev();
|
autoCorrect="false"
|
||||||
} else if (e.key === "Enter") {
|
onChange={(e) => {
|
||||||
goToTab();
|
setSearchQuery(e.target.value);
|
||||||
}
|
}}
|
||||||
}}
|
/>
|
||||||
spellCheck="false"
|
</SearchInputRightContainer>
|
||||||
autoCorrect="false"
|
</SearchContainer>
|
||||||
onChange={(e) => {
|
|
||||||
setSearchQuery(e.target.value);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<hr style={{ opacity: "0.3", marginTop: "0px" }} />
|
<hr style={{ opacity: "0.3", marginTop: "0px" }} />
|
||||||
<div style={{ padding: "1em", fontWeight: "bold" }}>
|
<div style={{ padding: "1em", fontWeight: "bold" }}>
|
||||||
{t("ui_open_tabs", `${tabs.length}`)}
|
{t("ui_open_tabs", `${tabs.length}`)}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<TabList>
|
||||||
style={{
|
|
||||||
maxHeight: "500px",
|
|
||||||
overflow: "scroll",
|
|
||||||
// minHeight: "300px"
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{searchResults.length === 0 ? (
|
{searchResults.length === 0 ? (
|
||||||
<div
|
<TabListEmpty>No Results Found</TabListEmpty>
|
||||||
style={{
|
|
||||||
padding: "1.5em",
|
|
||||||
fontSize: "1.1em",
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
No Results Found
|
|
||||||
</div>
|
|
||||||
) : null}
|
) : null}
|
||||||
{searchResults.map((t, i) => {
|
{searchResults.map((t, i) => {
|
||||||
const favicURL = enableFavicons !== 0 ? faviconURL(t.item, 32) : null;
|
const favicURL = faviconURL(t.item, 32);
|
||||||
|
const showCloseAction = tabHover === t.item.id! && !t.item.pinned;
|
||||||
return (
|
return (
|
||||||
<div
|
<TabItem
|
||||||
key={t.item.id}
|
key={t.item.id}
|
||||||
className="ht-tab"
|
$dark={darkMode}
|
||||||
|
$selected={i === selectedTab}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
focusTab(t.item.id!, t.item.windowId);
|
focusTab(t.item.id!, t.item.windowId);
|
||||||
}}
|
}}
|
||||||
ref={i === tabSelector ? selectedTabEle : undefined}
|
ref={i === tabSelector ? selectedTabEle : undefined}
|
||||||
style={{
|
|
||||||
padding: "10px",
|
|
||||||
cursor: "pointer",
|
|
||||||
backgroundColor:
|
|
||||||
i === selectedTab
|
|
||||||
? darkMode
|
|
||||||
? "#535353"
|
|
||||||
: "#e9e9e9"
|
|
||||||
: undefined,
|
|
||||||
|
|
||||||
// favicon support
|
|
||||||
...(enableFavicons
|
|
||||||
? {
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{favicURL && (
|
<TabItemFavicon
|
||||||
<div
|
onMouseEnter={() => {
|
||||||
className="ht-tab-favicon"
|
setTabHover(t.item.id!);
|
||||||
style={{ marginRight: "1em", padding: ".5em" }}
|
}}
|
||||||
>
|
onMouseLeave={() => {
|
||||||
|
setTabHover(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{showCloseAction ? (
|
||||||
|
<div
|
||||||
|
title="Close Tab"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
bgpage.closeTab(t.item.id!).then((newtabs) => {
|
||||||
|
if (i < selectedTab) {
|
||||||
|
setTabSelector((n) => n - 1);
|
||||||
|
}
|
||||||
|
setTabs(newtabs);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path d="M12 0c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm4.151 17.943l-4.143-4.102-4.117 4.159-1.833-1.833 4.104-4.157-4.162-4.119 1.833-1.833 4.155 4.102 4.106-4.16 1.849 1.849-4.1 4.141 4.157 4.104-1.849 1.849z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<img width={16} height={16} src={favicURL} />
|
<img width={16} height={16} src={favicURL} />
|
||||||
</div>
|
)}
|
||||||
)}
|
</TabItemFavicon>
|
||||||
<div className="ht-tab-right" style={{ width: "93%" }}>
|
<TabItemMain>
|
||||||
<div
|
<TabItemMainTitle $dark={darkMode}>
|
||||||
className="ht-tab-title"
|
<HighlightMatches
|
||||||
style={{
|
text={t.item.title ?? ""}
|
||||||
color: darkMode ? "#e9e9e9" : "#2b2b2b",
|
match={t.matches?.find((m) => m.key === "title")}
|
||||||
whiteSpace: "nowrap",
|
/>
|
||||||
overflow: "hidden",
|
</TabItemMainTitle>
|
||||||
textOverflow: "ellipsis",
|
<TabItemMainHostname>
|
||||||
fontSize: "1.1em",
|
|
||||||
marginBottom: "6px",
|
|
||||||
width: "98%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{
|
|
||||||
<HighlightMatches
|
|
||||||
text={t.item.title ?? ""}
|
|
||||||
match={t.matches?.find((m) => m.key === "title")}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className="ht-tab-location"
|
|
||||||
style={{
|
|
||||||
color: "#6e6e6e",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t.item.url ? hostname(t.item.url) : ""}
|
{t.item.url ? hostname(t.item.url) : ""}
|
||||||
</div>
|
</TabItemMainHostname>
|
||||||
</div>
|
</TabItemMain>
|
||||||
</div>
|
</TabItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</TabList>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user