mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
33 lines
903 B
TypeScript
33 lines
903 B
TypeScript
|
|
import { DefinedTool } from '@tools/defineTool';
|
||
|
|
|
||
|
|
const bookmarkedToolsKey = 'bookmarkedTools';
|
||
|
|
|
||
|
|
export function getBookmarkedTools(): string[] {
|
||
|
|
return localStorage.getItem(bookmarkedToolsKey)?.split(',') ?? [];
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isBookmarked(tool: DefinedTool): boolean {
|
||
|
|
return getBookmarkedTools().some((path) => path === tool.path);
|
||
|
|
}
|
||
|
|
|
||
|
|
export function toggleBookmarked(tool: DefinedTool) {
|
||
|
|
if (isBookmarked(tool)) {
|
||
|
|
unbookmark(tool);
|
||
|
|
} else {
|
||
|
|
bookmark(tool);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function bookmark(tool: DefinedTool) {
|
||
|
|
localStorage.setItem(
|
||
|
|
bookmarkedToolsKey,
|
||
|
|
tool.path + localStorage.getItem(bookmarkedToolsKey)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
function unbookmark(tool: DefinedTool) {
|
||
|
|
const bookmarked = localStorage.getItem(bookmarkedToolsKey)?.split(',') ?? [];
|
||
|
|
const unbookmarked = bookmarked.filter((path) => path != tool.path);
|
||
|
|
localStorage.setItem(bookmarkedToolsKey, unbookmarked.join(','));
|
||
|
|
}
|