fix: open omni failed in new tab

This commit is contained in:
panjiangyi 2024-01-09 12:47:33 +08:00
parent bc330ceeb2
commit 9e95543899
4 changed files with 20 additions and 10 deletions

View file

@ -8,10 +8,10 @@ const clearActions = () => {
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']};
if (response.mutedInfo.muted) {
if (response?.mutedInfo?.muted) {
muteaction = {title:"Unmute tab", desc:"Unmute the current tab", type:"action", action:"unmute", emoji:true, emojiChar:"🔈", keycheck:true, keys:['⌥','⇧', 'M']};
}
if (response.pinned) {
if (response?.pinned) {
pinaction = {title:"Unpin tab", desc:"Unpin the current tab", type:"action", action:"unpin", emoji:true, emojiChar:"📌", keycheck:true, keys:['⌥','⇧', 'P']};
}
actions = [
@ -475,10 +475,17 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
}
break;
case "search":
chrome.search.query(
{text:message.query,disposition:message.disposition}
)
break;
var query = () =>
chrome.search.query({
text: message.query,
disposition: message.disposition,
});
if (message.__inNewTab__) {
setTimeout(query, 125);
} else {
query();
}
break;
case "restore-new-tab":
restoreNewTab();
break;

View file

@ -20,10 +20,11 @@ $(document).ready(() => {
// Request actions from the background
chrome.runtime.sendMessage({request:"get-actions"}, (response) => {
actions = response.actions;
populateOmni()
});
// New tab page workaround
if (window.location.href == "chrome-extension://mpanekjjajcabgnlbabmopeenljeoggm/newtab.html") {
if (window.__inNewTab__) {
isOpen = true;
$("#omni-extension").removeClass("omni-closing");
window.setTimeout(() => {
@ -131,7 +132,7 @@ $(document).ready(() => {
// Close the omni
function closeOmni() {
if (window.location.href == "chrome-extension://mpanekjjajcabgnlbabmopeenljeoggm/newtab.html") {
if (window.__inNewTab__) {
chrome.runtime.sendMessage({request:"restore-new-tab"});
} else {
isOpen = false;
@ -304,7 +305,8 @@ $(document).ready(() => {
window.open($(".omni-item-active").attr("data-url"), "_self");
}
} else {
chrome.runtime.sendMessage({request:action.action, disposition:(e.altKey||e.metaKey)? "NEW_TAB":"CURRENT_TAB", tab:action, query:$(".omni-extension input").val()});
var disposition = window.__inNewTab__ ? "CURRENT_TAB" : e.altKey || e.metaKey ? "NEW_TAB" : "CURRENT_TAB";
chrome.runtime.sendMessage({request:action.action,__inNewTab__:window.__inNewTab__, disposition:disposition, tab:action, query:$(".omni-extension input").val()});
switch (action.action) {
case "bookmark":
if (e.ctrlKey || e.metaKey) {

View file

@ -11,7 +11,7 @@
</style>
</head>
<body>
<script src="newtab.js"></script>
<script src="jquery.js"></script>
<script src="content.js"></script>
<script src="virtualized-list.min.js"></script>

1
src/newtab.js Normal file
View file

@ -0,0 +1 @@
window.__inNewTab__ = true;