Skip to content

Commit 12efdfb

Browse files
committed
Use patch_url in web ext based on hostname closes #43
1 parent 8620c4c commit 12efdfb

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

web-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "patch-roulette-web-extension",
33
"displayName": "diffs.dev",
44
"description": "Streamlines opening diffs in the diffs.dev Diff Viewer.",
5-
"version": "0.0.8",
5+
"version": "0.0.9",
66
"private": true,
77
"type": "module",
88
"scripts": {

web-extension/src/common.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ export async function getViewerUrl() {
99
return url;
1010
}
1111

12-
export async function openInPatchRoulette(url: string) {
12+
export async function openInDiffViewer(url: string) {
1313
const viewerUrl = await getViewerUrl();
1414
try {
1515
if (url.startsWith(viewerUrl)) {
1616
return;
1717
}
18-
const newUrl = viewerUrl + "?github_url=" + encodeURIComponent(url);
18+
19+
const parsedUrl = new URL(url);
20+
let newUrl: string;
21+
if (parsedUrl.hostname === "github.com") {
22+
newUrl = viewerUrl + "?github_url=" + encodeURIComponent(url);
23+
} else {
24+
newUrl = viewerUrl + "?patch_url=" + encodeURIComponent(url);
25+
}
26+
1927
const activeTab = await getActiveTab();
2028
await chrome.tabs.create({
2129
url: newUrl,

web-extension/src/popup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getActiveTab, openInPatchRoulette } from "./common.ts";
1+
import { getActiveTab, openInDiffViewer } from "./common.ts";
22

33
const button = document.getElementById("open-button") as HTMLButtonElement;
44
const settingsButton = document.getElementById("settings-button") as HTMLButtonElement;
@@ -10,7 +10,7 @@ if (!button || !settingsButton) {
1010
button.addEventListener("click", async () => {
1111
const activeTab = await getActiveTab();
1212
if (activeTab && activeTab.url) {
13-
await openInPatchRoulette(activeTab.url);
13+
await openInDiffViewer(activeTab.url);
1414
window.close();
1515
}
1616
});

web-extension/src/worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { openInPatchRoulette } from "./common.ts";
1+
import { openInDiffViewer } from "./common.ts";
22
import browser from "webextension-polyfill";
33

44
function createContextMenu() {
@@ -18,6 +18,6 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
1818
url = tab.url;
1919
}
2020
if (url) {
21-
await openInPatchRoulette(url);
21+
await openInDiffViewer(url);
2222
}
2323
});

0 commit comments

Comments
 (0)