From 6d06f7bc5f260205f5cbcbfe0076c21b11155946 Mon Sep 17 00:00:00 2001 From: Alyssa X Date: Mon, 17 Jan 2022 15:09:14 +0000 Subject: [PATCH] Some fixes and improvements --- src/background.js | 1 + src/content.css | 1 + src/content.js | 85 +++++++++++++++++++++++++++++++---------------- src/manifest.json | 2 +- 4 files changed, 59 insertions(+), 30 deletions(-) diff --git a/src/background.js b/src/background.js index ef21369..467a2ad 100644 --- a/src/background.js +++ b/src/background.js @@ -4,6 +4,7 @@ let newtaburl = ""; // Clear actions and append default ones const clearActions = () => { getCurrentTab().then((response) => { + actions = []; const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; let muteaction = {title:"Mute tab", desc:"Mute the current tab", type:"action", action:"mute", emoji:true, emojiChar:"🔇", keycheck:true, keys:['⌥','⇧', 'M']}; let pinaction = {title:"Pin tab", desc:"Pin the current tab", type:"action", action:"pin", emoji:true, emojiChar:"📌", keycheck:true, keys:['⌥','⇧', 'P']}; diff --git a/src/content.css b/src/content.css index f0cef66..7d32d49 100644 --- a/src/content.css +++ b/src/content.css @@ -119,6 +119,7 @@ html { z-index: 9999999999; height: 540px; transition: all 0.2s cubic-bezier(0.05, 0.03, 0.35, 1); + pointer-events: all; } .omni-extension #omni { position: absolute; diff --git a/src/content.js b/src/content.js index ccc96c9..801cb4e 100644 --- a/src/content.js +++ b/src/content.js @@ -6,16 +6,16 @@ document.onkeyup = (e) => { } } -$(document).ready(function(){ +$(document).ready(() => { var actions = []; var isFiltered = false; // Append the omni into the current page - $.get(chrome.runtime.getURL('/content.html'), function(data) { + $.get(chrome.runtime.getURL('/content.html'), (data) => { $(data).appendTo('body'); // Request actions from the background - chrome.runtime.sendMessage({request:"get-actions"}, function(response) { + chrome.runtime.sendMessage({request:"get-actions"}, (response) => { actions = response.actions; populateOmni(); }); @@ -24,16 +24,37 @@ $(document).ready(function(){ if (window.location.href == "chrome-extension://mpanekjjajcabgnlbabmopeenljeoggm/newtab.html") { isOpen = true; $("#omni-extension").removeClass("omni-closing"); - window.setTimeout(function(){ + window.setTimeout(() => { $("#omni-extension input").focus(); }, 100); } }); + function renderAction(action, index, keys, img) { + var skip = ""; + if (action.action == "search" || action.action == "goto") { + skip = "style='display:none'"; + } + if (index != 0) { + $("#omni-extension #omni-list").append("
"+img+"
"+action.title+"
"+action.desc+"
"+keys+"
Select
"); + } else { + $("#omni-extension #omni-list").append("
"+img+"
"+action.title+"
"+action.desc+"
"+keys+"
Select
"); + } + if (!action.emoji) { + var loadimg = new Image(); + loadimg.src = action.favIconUrl; + + // Favicon doesn't load, use a fallback + loadimg.onerror = () => { + $(".omni-item[data-index='"+index+"'] img").attr("src", chrome.runtime.getURL("/assets/globe.svg")); + } + } + } + // Add actions to the omni function populateOmni() { $("#omni-extension #omni-list").html(""); - actions.forEach(function(action, index){ + actions.forEach((action, index) => { var keys = ""; if (action.keycheck) { keys = "
"; @@ -42,18 +63,15 @@ $(document).ready(function(){ }); keys += "
"; } - var onload = 'if ("naturalHeight" in this) {if (this.naturalHeight + this.naturalWidth === 0) {this.onerror();return;}} else if (this.width + this.height == 0) {this.onerror();return;}'; - var img = "favicon"; - if (action.emoji) { - img = ""+action.emojiChar+"" - } - if (index != 0) { - $("#omni-extension #omni-list").append("
"+img+"
"+action.title+"
"+action.desc+"
"+keys+"
Select
"); + + // Check if the action has an emoji or a favicon + if (!action.emoji) { + var onload = 'if ("naturalHeight" in this) {if (this.naturalHeight + this.naturalWidth === 0) {this.onerror();return;}} else if (this.width + this.height == 0) {this.onerror();return;}'; + var img = "favicon"; + renderAction(action, index, keys, img); } else { - $("#omni-extension #omni-list").append("
"+img+"
"+action.title+"
"+action.desc+"
"+keys+"
Select
"); - } - if (action.type == "action" && action.action == "search") { - $(".omni-item[data-index='"+index+"']").hide(); + var img = ""+action.emojiChar+""; + renderAction(action, index, keys, img); } }) $(".omni-extension #omni-results").html(actions.length+" results"); @@ -63,7 +81,7 @@ $(document).ready(function(){ function populateOmniFilter(actions) { isFiltered = true; $("#omni-extension #omni-list").html(""); - actions.forEach(function(action, index){ + actions.forEach((action, index) => { var keys = ""; if (action.keycheck) { keys = "
"; @@ -87,14 +105,14 @@ $(document).ready(function(){ // Open the omni function openOmni() { - chrome.runtime.sendMessage({request:"get-actions"}, function(response) { + chrome.runtime.sendMessage({request:"get-actions"}, (response) => { isOpen = true; actions = response.actions; $("#omni-extension input").val(""); populateOmni(); $("html, body").stop(); $("#omni-extension").removeClass("omni-closing"); - window.setTimeout(function(){ + window.setTimeout(() => { $("#omni-extension input").focus(); }, 100); }); @@ -166,19 +184,23 @@ $(document).ready(function(){ checkShortHand(e, value); value = $(this).val().toLowerCase(); if (value.startsWith("/history")) { + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "search")+"']").hide(); + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "goto")+"']").hide(); var tempvalue = value.replace("/history ", ""); var query = ""; if (tempvalue != "/history") { query = value.replace("/history ", ""); } - chrome.runtime.sendMessage({request:"search-history", query:query}, function(response){ + chrome.runtime.sendMessage({request:"search-history", query:query}, (response) => { populateOmniFilter(response.history); }); } else if (value.startsWith("/bookmarks")) { + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "search")+"']").hide(); + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "goto")+"']").hide(); var tempvalue = value.replace("/bookmarks ", ""); if (tempvalue != "/bookmarks" && tempvalue != "") { var query = value.replace("/bookmarks ", ""); - chrome.runtime.sendMessage({request:"search-bookmarks", query:query}, function(response){ + chrome.runtime.sendMessage({request:"search-bookmarks", query:query}, (response) => { populateOmniFilter(response.bookmarks); }); } else { @@ -189,8 +211,10 @@ $(document).ready(function(){ populateOmni(); isFiltered = false; } - $("#omni-extension #omni-list .omni-item").filter(function(){ + $(".omni-extension #omni-list .omni-item").filter(function(){ if (value.startsWith("/tabs")) { + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "search")+"']").hide(); + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "goto")+"']").hide(); var tempvalue = value.replace("/tabs ", ""); if (tempvalue == "/tabs") { $(this).toggle($(this).attr("data-type") == "tab"); @@ -199,6 +223,8 @@ $(document).ready(function(){ $(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("/remove")) { + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "search")+"']").hide(); + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "goto")+"']").hide(); var tempvalue = value.replace("/remove ", "") if (tempvalue == "/remove") { $(this).toggle($(this).attr("data-type") == "bookmark" || $(this).attr("data-type") == "tab"); @@ -207,6 +233,8 @@ $(document).ready(function(){ $(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")) { + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "search")+"']").hide(); + $(".omni-item[data-index='"+actions.findIndex(x => x.action == "goto")+"']").hide(); var tempvalue = value.replace("/actions ", "") if (tempvalue == "/actions") { $(this).toggle($(this).attr("data-type") == "action"); @@ -231,6 +259,7 @@ $(document).ready(function(){ } }); } + $(".omni-extension #omni-results").html($("#omni-extension #omni-list .omni-item:visible").length+" results"); $(".omni-item-active").removeClass("omni-item-active"); $(".omni-extension #omni-list .omni-item:visible").first().addClass("omni-item-active"); @@ -302,7 +331,7 @@ $(document).ready(function(){ } // Fetch actions again - chrome.runtime.sendMessage({request:"get-actions"}, function(response) { + chrome.runtime.sendMessage({request:"get-actions"}, (response) => { actions = response.actions; populateOmni(); }); @@ -317,7 +346,7 @@ $(document).ready(function(){ // Check which keys are down var down = []; - $(document).keydown(function(e) { + $(document).keydown((e) => { down[e.keyCode] = true; if (down[38]) { // Up key @@ -342,14 +371,14 @@ $(document).ready(function(){ // Enter key handleAction(e); } - }).keyup(function(e) { + }).keyup((e) => { if (down[18] && down[16] && down[80]) { if (actions.find(x => x.action == "pin") != undefined) { chrome.runtime.sendMessage({request:"pin-tab"}); } else { chrome.runtime.sendMessage({request:"unpin-tab"}); } - chrome.runtime.sendMessage({request:"get-actions"}, function(response) { + chrome.runtime.sendMessage({request:"get-actions"}, (response) => { actions = response.actions; populateOmni(); }); @@ -359,7 +388,7 @@ $(document).ready(function(){ } else { chrome.runtime.sendMessage({request:"unmute-tab"}); } - chrome.runtime.sendMessage({request:"get-actions"}, function(response) { + chrome.runtime.sendMessage({request:"get-actions"}, (response) => { actions = response.actions; populateOmni(); }); @@ -383,8 +412,6 @@ $(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("keyup", ".omni-extension input", search); diff --git a/src/manifest.json b/src/manifest.json index 86957db..7287a3d 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "name": "Omni", "description": "Supercharge Chrome with commands, shortcuts, and more", "offline_enabled": true, - "version": "1.3.9", + "version": "1.4.0", "manifest_version": 3, "action": { "icons": {