Skip to content
Merged
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
7 changes: 5 additions & 2 deletions omnibox/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Asearch } from "./deps/asearch.ts";
import { browser } from "./deps/webextension.ts";
import { ensureTabId } from "./utils.ts";
import { getData } from "./storage.ts";
import { isURL } from "./isURL.ts";

//
// browserActionボタンを押したときcontent_script.jsにメッセージを送る
Expand Down Expand Up @@ -80,10 +81,12 @@ function search(
// ユーザがメニューを選択したとき呼ばれるもの
//
browser.omnibox.onInputEntered.addListener(async (text) => {
if (text.match(/^http/)) {
if (isURL(text)) {
browser.tabs.update({ url: text });
} else {
const response = await fetch("https://goquick.org", { credentials: "include"}); // GoQuick.orgユーザはGoQuick.orgを利用
const response = await fetch("https://goquick.org", {
credentials: "include",
}); // GoQuick.orgユーザはGoQuick.orgを利用
const data = await response.text();
browser.tabs.update({
url: data.match("GoQuick Login")
Expand Down
1 change: 1 addition & 0 deletions omnibox/deps/testing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "https://deno.land/std@0.126.0/testing/asserts.ts";
11 changes: 11 additions & 0 deletions omnibox/isURL.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference lib="deno.ns" />
import { isURL } from "./isURL.ts";
import { assert } from "./deps/testing.ts";

Deno.test("isURL()", () => {
assert(isURL("https://example.com"));
assert(isURL("http://goquick.org"));
assert(isURL("file:///users/file.txt"));
assert(isURL("things:///show?id=xxx"));
assert(!isURL("helpfeel"));
});
10 changes: 10 additions & 0 deletions omnibox/isURL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** URLかどうか判定する */
export function isURL(text: string): boolean {
try {
new URL(text);
return true;
} catch (e: unknown) {
if (e instanceof TypeError) return false;
throw e;
}
}