mirror of
https://github.com/alyssaxuu/omni.git
synced 2026-03-11 08:54:35 +00:00
Merge branch 'alyssaxuu:master' into master
This commit is contained in:
commit
4821163a9e
3 changed files with 108 additions and 55 deletions
|
|
@ -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);
|
||||
|
|
|
|||
126
src/content.js
126
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 = "";
|
||||
|
|
@ -91,56 +93,80 @@ $(document).ready(function(){
|
|||
$(this).addClass("omni-item-active");
|
||||
}
|
||||
|
||||
// Autocomplete commands. Since they all start with different letters, it can be the default behavior
|
||||
function checkShortHand(e, value) {
|
||||
var el = $(".omni-extension input");
|
||||
if (e.keyCode != 8) {
|
||||
if (value == "/t") {
|
||||
el.val("/tabs ")
|
||||
} else if (value == "/b") {
|
||||
el.val("/bookmarks ")
|
||||
} else if (value == "/h") {
|
||||
el.val("/history ");
|
||||
} else if (value == "/r") {
|
||||
el.val("/remove ");
|
||||
} else if (value == "/a") {
|
||||
el.val("/actions ");
|
||||
}
|
||||
} else {
|
||||
if (value == "/tabs" || value == "/bookmarks" || value == "/actions" || value == "/remove" || value == "/history") {
|
||||
el.val("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search for an action in the omni
|
||||
function search() {
|
||||
function search(e) {
|
||||
var value = $(this).val().toLowerCase();
|
||||
checkShortHand(e, value);
|
||||
value = $(this).val().toLowerCase();
|
||||
if (value.startsWith("/history")) {
|
||||
var tempvalue = value.replace("/tabs ", "");
|
||||
var tempvalue = value.replace("/history ", "");
|
||||
var query = "";
|
||||
if (tempvalue != "/history") {
|
||||
query = value.replace("/history ", "");
|
||||
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 ", "");
|
||||
if (tempvalue != "/bookmarks" && tempvalue != "") {
|
||||
var query = value.replace("/bookmarks ", "");
|
||||
chrome.runtime.sendMessage({request:"search-bookmarks", query:query}, function(response){
|
||||
populateOmniFilter(response.bookmarks);
|
||||
});
|
||||
} else {
|
||||
populateOmniFilter(actions.filter(x => x.type == "bookmark"));
|
||||
}
|
||||
} else {
|
||||
populateOmni();
|
||||
if (isFiltered) {
|
||||
populateOmni();
|
||||
isFiltered = false;
|
||||
}
|
||||
$("#omni-extension #omni-list .omni-item").filter(function(){
|
||||
if (value.startsWith("/tabs") || value.startsWith("/t")) {
|
||||
var targetAction = value.startsWith("/tabs") ? "/tabs" : "/t";
|
||||
var tempvalue = value.replace(targetAction + " ", "")
|
||||
if (tempvalue == targetAction) {
|
||||
if (value.startsWith("/tabs")) {
|
||||
var tempvalue = value.replace("/tabs ", "");
|
||||
if (tempvalue == "/tabs") {
|
||||
$(this).toggle($(this).attr("data-type") == "tab");
|
||||
} else {
|
||||
tempvalue = value.replace(targetAction + " ", "");
|
||||
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") || value.startsWith("/b")) {
|
||||
var targetAction = value.startsWith("/bookmarks") ? "/bookmarks" : "/b";
|
||||
var tempvalue = value.replace(targetAction + " ", "")
|
||||
var tempvalue = value.replace("/bookmarks ", "");
|
||||
if (tempvalue == targetAction) {
|
||||
$(this).toggle($(this).attr("data-type") == "bookmark");
|
||||
} else {
|
||||
tempvalue = value.replace(targetAction + " ", "");
|
||||
$(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") || value.startsWith("/r")) {
|
||||
var targetAction = value.startsWith("/remove") ? "/remove" : "/r";
|
||||
var tempvalue = value.replace(targetAction + " ", "")
|
||||
if (tempvalue == targetAction) {
|
||||
} else if (value.startsWith("/remove")) {
|
||||
var tempvalue = value.replace("/remove ", "")
|
||||
if (tempvalue == "/remove") {
|
||||
$(this).toggle($(this).attr("data-type") == "bookmark" || $(this).attr("data-type") == "tab");
|
||||
} else {
|
||||
tempvalue = value.replace(targetAction + " ", "");
|
||||
tempvalue = value.replace("/remove ", "");
|
||||
$(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" || $(this).attr("data-type") == "tab"));
|
||||
}
|
||||
} else if (value.startsWith("/actions") || value.startsWith("/a")) {
|
||||
var targetAction = value.startsWith("/actions") ? "/actions" : "/a";
|
||||
var tempvalue = value.replace(targetAction + " ", "")
|
||||
if (tempvalue == targetAction) {
|
||||
} else if (value.startsWith("/actions")) {
|
||||
var tempvalue = value.replace("/actions ", "")
|
||||
if (tempvalue == "/actions") {
|
||||
$(this).toggle($(this).attr("data-type") == "action");
|
||||
} else {
|
||||
tempvalue = value.replace(targetAction + " ", "");
|
||||
tempvalue = value.replace("/actions ", "");
|
||||
$(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") == "action");
|
||||
}
|
||||
} else {
|
||||
|
|
@ -228,24 +254,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) {
|
||||
|
|
@ -297,7 +323,7 @@ $(document).ready(function(){
|
|||
// Events
|
||||
$(document).on("click", "#open-page-omni-extension-thing", openShortcuts);
|
||||
$(document).on("mouseover", ".omni-extension .omni-item:not(.omni-item-active)", hoverItem);
|
||||
$(document).on("input", ".omni-extension input", search);
|
||||
$(document).on("keyup", ".omni-extension input", search);
|
||||
$(document).on("click", ".omni-item-active", handleAction);
|
||||
$(document).on("click", ".omni-extension #omni-overlay", closeOmni);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "Omni",
|
||||
"description": "Supercharge Chrome with commands, shortcuts, and more",
|
||||
"offline_enabled": true,
|
||||
"version": "1.1.5",
|
||||
"version": "1.2.5",
|
||||
"manifest_version": 3,
|
||||
"action": {
|
||||
"icons": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue