Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use "tabs.create" instead of "window.open" #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.history
.history
.idea
10 changes: 8 additions & 2 deletions firefox/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ browser.commands.onCommand.addListener((command) => {
browser.tabs.sendMessage(response.id, {request: "open-omni"});
} else {
browser.tabs.create({
url: "./newtab.html"
url: "./newtab.html"
}).then(() => {
newtaburl = response.url;
browser.tabs.remove(response.id);
Expand Down Expand Up @@ -241,7 +241,7 @@ const getTabs = () => {
// Get bookmarks to populate in the actions
const getBookmarks = () => {
const process_bookmark = (bookmarks) => {
for (const bookmark of bookmarks) {
for (const bookmark of bookmarks) {
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})
}
Expand Down Expand Up @@ -280,6 +280,9 @@ const duplicateTab = (tab) => {
browser.tabs.duplicate(response.id);
})
}
const createTab = (tab = {}) => {
browser.tabs.create(tab)
}
const createBookmark = (tab) => {
getCurrentTab().then((response) => {
browser.bookmarks.create({
Expand Down Expand Up @@ -373,6 +376,9 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
case "duplicate-tab":
duplicateTab(message.tab);
break;
case "new-tab":
createTab(message.tab);
break;
case "create-bookmark":
createBookmark(message.tab);
break;
Expand Down
8 changes: 4 additions & 4 deletions firefox/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ $(document).ready(() => {
});
keys += "</div>";
}

// 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;}';
Expand Down Expand Up @@ -280,7 +280,7 @@ $(document).ready(() => {
}
});
}

$(".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");
Expand Down Expand Up @@ -333,8 +333,8 @@ $(document).ready(() => {
elem.requestFullscreen();
break;
case "new-tab":
window.open("");
break;
browser.runtime.sendMessage({request:"new-tab"})
break;
case "email":
window.open("mailto:");
break;
Expand Down
10 changes: 8 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ chrome.commands.onCommand.addListener((command) => {
chrome.tabs.sendMessage(response.id, {request: "open-omni"});
} else {
chrome.tabs.create({
url: "./newtab.html"
url: "./newtab.html"
}).then(() => {
newtaburl = response.url;
chrome.tabs.remove(response.id);
Expand Down Expand Up @@ -243,7 +243,7 @@ const getTabs = () => {
// Get bookmarks to populate in the actions
const getBookmarks = () => {
const process_bookmark = (bookmarks) => {
for (const bookmark of bookmarks) {
for (const bookmark of bookmarks) {
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})
}
Expand Down Expand Up @@ -282,6 +282,9 @@ const duplicateTab = (tab) => {
chrome.tabs.duplicate(response.id);
})
}
const createTab = (tab = {}) => {
chrome.tabs.create(tab)
}
const createBookmark = (tab) => {
getCurrentTab().then((response) => {
chrome.bookmarks.create({
Expand Down Expand Up @@ -375,6 +378,9 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
case "duplicate-tab":
duplicateTab(message.tab);
break;
case "new-tab":
createTab(message.tab);
break;
case "create-bookmark":
createBookmark(message.tab);
break;
Expand Down
6 changes: 3 additions & 3 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ $(document).ready(() => {
});
keys += "</div>";
}

// 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;}';
Expand Down Expand Up @@ -279,7 +279,7 @@ $(document).ready(() => {
}
});
}

$(".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");
Expand Down Expand Up @@ -332,7 +332,7 @@ $(document).ready(() => {
elem.requestFullscreen();
break;
case "new-tab":
window.open("");
chrome.runtime.sendMessage({request:"new-tab"})
break;
case "email":
window.open("mailto:");
Expand Down