diff --git a/src/background.js b/src/background.js index e88331f..ab73958 100644 --- a/src/background.js +++ b/src/background.js @@ -208,14 +208,15 @@ function getBookmarks() { for (var i = 0; i < bookmarks.length; i++) { var bookmark = bookmarks[i]; if (bookmark.url) { - actions.push({title:bookmark.title, desc:"Bookmark", id:bookmark.id, url:bookmark.url, type:"bookmark", action:"bookmark", emoji:true, emojiChar:"⭐️", keycheck:false}) + actions.push({title:bookmark.title, desc:"Bookmark", id:bookmark.id, url:bookmark.url, type:"bookmark", action:"bookmark", emoji:true, emojiChar:"⭐️", keycheck:false}) } if (bookmark.children) { - process_bookmark(bookmark.children); + process_bookmark(bookmark.children); } } } - chrome.bookmarks.getTree(process_bookmark); + + chrome.bookmarks.getRecent(100, process_bookmark); } // Lots of different actions @@ -389,11 +390,37 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { action.emoji = true; action.emojiChar = "🏛"; action.action = "history"; - action.desc = "Browsing history"; + action.keyCheck = false; }); sendResponse({history:data}); }) return true; + case "search-bookmarks": + chrome.bookmarks.search({query:message.query}).then(function(data){ + // The index property of the bookmark appears to be causing issues, iterating separately... + data.filter(x => x.index == 0).forEach(function(action, index){ + if (!action.url) { + data.splice(index, 1); + } + action.type = "bookmark"; + action.emoji = true; + action.emojiChar = "⭐️"; + action.action = "bookmark"; + action.keyCheck = false; + }) + data.forEach(function(action, index){ + if (!action.url) { + data.splice(index, 1); + } + action.type = "bookmark"; + action.emoji = true; + action.emojiChar = "⭐️"; + action.action = "bookmark"; + action.keyCheck = false; + }) + sendResponse({bookmarks:data}); + }) + return true; case "remove": if (message.type == "bookmark") { removeBookmark(message.action); diff --git a/src/content.js b/src/content.js index 4615da4..c790a69 100644 --- a/src/content.js +++ b/src/content.js @@ -1,6 +1,7 @@ $(document).ready(function(){ var isOpen = false; var actions = []; + var isFiltered = false; // Append the omni into the current page $.get(chrome.runtime.getURL('/content.html'), function(data) { @@ -39,8 +40,9 @@ $(document).ready(function(){ $(".omni-extension #omni-results").html(actions.length+" results"); } - // Add actions to the omni - function populateOmniHistory(actions) { + // Add filtered actions to the omni + function populateOmniFilter(actions) { + isFiltered = true; $("#omni-extension #omni-list").html(""); actions.forEach(function(action, index){ var keys = ""; @@ -101,10 +103,24 @@ $(document).ready(function(){ query = value.replace("/history ", ""); } chrome.runtime.sendMessage({request:"search-history", query:query}, function(response){ - populateOmniHistory(response.history); + populateOmniFilter(response.history); + }); + } else if (value.startsWith("/bookmarks")) { + var tempvalue = value.replace("/bookmarks ", ""); + var query = ""; + if (tempvalue != "/bookmarks" || "/bookmarks ") { + query = value.replace("/bookmarks ", ""); + } else { + + } + chrome.runtime.sendMessage({request:"search-bookmarks", query:query}, function(response){ + populateOmniFilter(response.bookmarks); }); } else { - populateOmni(); + if (isFiltered) { + populateOmni(); + isFiltered = false; + } $("#omni-extension #omni-list .omni-item").filter(function(){ if (value.startsWith("/tabs")) { var tempvalue = value.replace("/tabs ", ""); @@ -114,14 +130,6 @@ $(document).ready(function(){ tempvalue = value.replace("/tabs ", ""); $(this).toggle(($(this).find(".omni-item-name").text().toLowerCase().indexOf(tempvalue) > -1 || $(this).find(".omni-item-desc").text().toLowerCase().indexOf(tempvalue) > -1) && $(this).attr("data-type") == "tab"); } - } else if (value.startsWith("/bookmarks")) { - var tempvalue = value.replace("/bookmarks ", ""); - if (tempvalue == "/bookmarks") { - $(this).toggle($(this).attr("data-type") == "bookmark"); - } else { - tempvalue = value.replace("/bookmarks ", ""); - $(this).toggle(($(this).find(".omni-item-name").text().toLowerCase().indexOf(tempvalue) > -1 || $(this).find(".omni-item-desc").text().toLowerCase().indexOf(tempvalue) > -1) && $(this).attr("data-type") == "bookmark"); - } } else if (value.startsWith("/remove")) { var tempvalue = value.replace("/remove ", ""); if (tempvalue == "/remove") { @@ -223,24 +231,24 @@ $(document).ready(function(){ var down = []; $(document).keydown(function(e) { - down[e.keyCode] = true; - if (down[38]) { - // Up key - if ($(".omni-item-active").prevAll("div").not(":hidden").first().length) { - var previous = $(".omni-item-active").prevAll("div").not(":hidden").first(); - $(".omni-item-active").removeClass("omni-item-active"); - previous.addClass("omni-item-active"); - previous[0].scrollIntoView({block:"nearest", inline:"nearest"}); - } - } else if (down[40]) { - // Down key - if ($(".omni-item-active").nextAll("div").not(":hidden").first().length) { - var next = $(".omni-item-active").nextAll("div").not(":hidden").first(); - $(".omni-item-active").removeClass("omni-item-active"); - next.addClass("omni-item-active"); - next[0].scrollIntoView({block:"nearest", inline:"nearest"}); - } + down[e.keyCode] = true; + if (down[38]) { + // Up key + if ($(".omni-item-active").prevAll("div").not(":hidden").first().length) { + var previous = $(".omni-item-active").prevAll("div").not(":hidden").first(); + $(".omni-item-active").removeClass("omni-item-active"); + previous.addClass("omni-item-active"); + previous[0].scrollIntoView({block:"nearest", inline:"nearest"}); } + } else if (down[40]) { + // Down key + if ($(".omni-item-active").nextAll("div").not(":hidden").first().length) { + var next = $(".omni-item-active").nextAll("div").not(":hidden").first(); + $(".omni-item-active").removeClass("omni-item-active"); + next.addClass("omni-item-active"); + next[0].scrollIntoView({block:"nearest", inline:"nearest"}); + } + } }).keyup(function(e) { if (down[18] && down[16] && down[80]) { if (actions.find(x => x.action == "pin") != undefined) {