Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:(function() {
- if (!window.__karaKeepBookmarkletLog) window.__karaKeepBookmarkletLog = [];
- const log = msg => {
- window.__karaKeepBookmarkletLog.push({ time: Date.now(), msg });
- console.log("[🔍 KaraKeep Assistant] " + msg);
- };
- const ADD_SPACE_AFTER_FILTER = true;
- if (window.__karaKeepUIInjected) {
- log("UI already active. Use 'removeKaraKeepFilterUI()' to remove");
- return;
- }
- window.__karaKeepUIInjected = true;
- log("Activated! Click the 'Search Filters' button to add advanced filters");
- log("Version 1.3 - Compatible with KaraKeep v0.25.0+");
- log(`Space after filters: ${ADD_SPACE_AFTER_FILTER ? "ENABLED" : "DISABLED"}`);
- const searchInput = document.querySelector('input[placeholder="Search"]');
- if (!searchInput) {
- log("❌ Error: Search input not found");
- return;
- }
- const FILTERS = [
- { name: "Favorited", value: "is:fav", desc: "Favorited bookmarks" },
- { name: "Archived", value: "is:archived", desc: "Archived bookmarks" },
- { name: "Tagged", value: "is:tagged", desc: "Has one or more tags" },
- { name: "In List", value: "is:inlist", desc: "Is in at least one list" },
- { name: "Type: Link", value: "is:link", desc: "Type: link" },
- { name: "Type: Text", value: "is:text", desc: "Type: text" },
- { name: "Type: Media", value: "is:media", desc: "Type: media" },
- { name: "URL", value: "url:example.com", desc: "Match URL substring" },
- { name: "After Date", value: "after:2024-01-01", desc: "After date (YYYY-MM-DD)" },
- { name: "Before Date", value: "before:2025-01-01", desc: "Before date (YYYY-MM-DD)" },
- { name: "Tag", value: "#important", desc: "With tag" },
- { name: "List", value: 'list:"to review"', desc: "In specific list" },
- { name: "Feed", value: "feed:Hackernews", desc: "Imported from feed" },
- { name: "Age <1w", value: "age:<1w", desc: "Younger than 1 week" },
- { name: "Age >1y", value: "age:>1y", desc: "Older than 1 year" }
- ];
- const btn = document.createElement("button");
- btn.id = "karaKeepFilterBtn";
- btn.textContent = "Search Filters";
- btn.type = "button";
- btn.style.cssText = `
- display: inline-flex;
- align-items: center;
- justify-content: center;
- white-space: nowrap;
- border-radius: 0.375rem;
- padding: 0 1rem;
- height: 2.5rem;
- font-size: 0.875rem;
- font-weight: 500;
- cursor: pointer;
- background-color: transparent;
- border: none;
- color: hsl(var(--foreground));
- transition: background-color 0.2s ease;
- margin-left: 0.5rem;
- `;
- btn.onmouseenter = () => btn.style.backgroundColor = 'hsl(var(--accent))';
- btn.onmouseleave = () => btn.style.backgroundColor = 'transparent';
- const menu = document.createElement("div");
- menu.id = "karaKeepFilterMenu";
- menu.style.cssText = `
- display: none;
- position: fixed;
- z-index: 100000;
- background: #fff;
- box-shadow: 0 8px 20px rgba(0,0,0,.18);
- border: 1px solid #ccc;
- border-radius: 6px;
- padding: 8px 0;
- color: #222;
- font-size: 15px;
- max-height: 260px;
- overflow-y: auto;
- `;
- FILTERS.forEach(f => {
- const item = document.createElement("button");
- item.textContent = f.name;
- item.title = f.desc;
- item.style.cssText = `
- display: block;
- width: 100%;
- background: none;
- border: none;
- text-align: left;
- padding: 6px 20px;
- cursor: pointer;
- font-size: 15px;
- color: #222;
- outline: none;
- transition: background 0.2s;
- `;
- item.onmouseenter = () => item.style.background = "#e6f0fa";
- item.onmouseleave = () => item.style.background = "none";
- item.onclick = e => {
- e.preventDefault();
- searchInput.focus();
- let start = searchInput.selectionStart;
- let end = searchInput.selectionEnd;
- if (typeof start === "number") {
- const orig = searchInput.value;
- const insertText = f.value + (ADD_SPACE_AFTER_FILTER ? " " : "");
- searchInput.value = orig.slice(0, start) + insertText + orig.slice(end);
- searchInput.selectionStart = searchInput.selectionEnd = start + insertText.length;
- } else {
- searchInput.value += f.value + (ADD_SPACE_AFTER_FILTER ? " " : "");
- }
- menu.style.display = "none";
- log(`Added filter: '${f.value}${ADD_SPACE_AFTER_FILTER ? ' ' : ''}'`);
- };
- menu.appendChild(item);
- });
- btn.onclick = e => {
- e.stopPropagation();
- if (menu.style.display === "block") {
- menu.style.display = "none";
- } else {
- const rect = btn.getBoundingClientRect();
- menu.style.top = (rect.bottom + 4) + "px";
- menu.style.left = rect.left + "px";
- menu.style.display = "block";
- document.body.appendChild(menu);
- }
- };
- document.addEventListener("mousedown", e => {
- if (!btn.contains(e.target) && !menu.contains(e.target)) {
- menu.style.display = "none";
- }
- });
- const buttonsContainer = document.querySelector('.flex.min-w-max.flex-wrap.overflow-hidden');
- if (buttonsContainer) {
- const editButton = buttonsContainer.querySelector('button:not([disabled])');
- if (editButton) {
- buttonsContainer.insertBefore(btn, editButton);
- log("UI injected successfully!");
- } else {
- buttonsContainer.appendChild(btn);
- log("UI injected at end of buttons");
- }
- } else {
- document.body.appendChild(btn);
- log("Buttons container not found, added to body");
- }
- window.removeKaraKeepFilterUI = () => {
- btn.remove();
- if (menu.parentNode) menu.parentNode.removeChild(menu);
- window.__karaKeepUIInjected = false;
- log("Assistant removed. Refresh page to restore original UI");
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment