chore: safeguard in webext against running in upend
parent
7af13e7d5f
commit
1f6d7fe090
|
@ -7,6 +7,8 @@
|
|||
|
||||
const api = new UpEndApi("http://localhost:8093");
|
||||
|
||||
let visitngUpEnd = false;
|
||||
|
||||
let opening = false;
|
||||
let openError: string | undefined;
|
||||
|
||||
|
@ -44,6 +46,14 @@
|
|||
let currentUrl: string | undefined;
|
||||
let contentType: string | undefined;
|
||||
onMount(async () => {
|
||||
browser.tabs
|
||||
.executeScript(undefined, {
|
||||
code: `document.querySelector('meta[name="application-name"]')?.content`,
|
||||
})
|
||||
.then((result) => {
|
||||
visitngUpEnd = (result[0] as string | undefined) === "UpEnd";
|
||||
});
|
||||
|
||||
currentUrl = await getCurrentUrl();
|
||||
|
||||
browser.tabs.onUpdated.addListener(async () => {
|
||||
|
@ -211,86 +221,90 @@
|
|||
</script>
|
||||
|
||||
<main>
|
||||
<div class="primary-controls">
|
||||
<button
|
||||
class="button"
|
||||
disabled={primaryAction == PRIMARY_ACTION.UNKNOWN}
|
||||
on:click={performPrimary}
|
||||
>
|
||||
{primaryAction} as {primaryType}
|
||||
</button>
|
||||
<div class="sublabel">Content type: {contentType || "???"}</div>
|
||||
</div>
|
||||
<div class="controls row">
|
||||
<div class="labeled-button">
|
||||
{#if !visitngUpEnd}
|
||||
<div class="primary-controls">
|
||||
<button
|
||||
class="button"
|
||||
disabled={urlEntriesCount === undefined}
|
||||
on:click={performUrl}
|
||||
disabled={primaryAction == PRIMARY_ACTION.UNKNOWN}
|
||||
on:click={performPrimary}
|
||||
>
|
||||
{urlEntriesCount === undefined
|
||||
? "???"
|
||||
: urlEntriesCount > 0
|
||||
? "Open"
|
||||
: "Save"} URL
|
||||
{primaryAction} as {primaryType}
|
||||
</button>
|
||||
<div class="sublabel">
|
||||
{#if urlAdded}
|
||||
Added at {urlAdded.toLocaleString()}
|
||||
{:else}
|
||||
---
|
||||
{/if}
|
||||
<div class="sublabel">Content type: {contentType || "???"}</div>
|
||||
</div>
|
||||
<div class="controls row">
|
||||
<div class="labeled-button">
|
||||
<button
|
||||
class="button"
|
||||
disabled={urlEntriesCount === undefined}
|
||||
on:click={performUrl}
|
||||
>
|
||||
{urlEntriesCount === undefined
|
||||
? "???"
|
||||
: urlEntriesCount > 0
|
||||
? "Open"
|
||||
: "Save"} URL
|
||||
</button>
|
||||
<div class="sublabel">
|
||||
{#if urlAdded}
|
||||
Added at {urlAdded.toLocaleString()}
|
||||
{:else}
|
||||
---
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="labeled-button">
|
||||
<button
|
||||
class="button"
|
||||
disabled={contentEntriesCount === undefined}
|
||||
on:click={performContent}
|
||||
>
|
||||
{contentEntriesCount === undefined
|
||||
? "???"
|
||||
: contentEntriesCount > 0
|
||||
? "Open"
|
||||
: "Save"} Content
|
||||
</button>
|
||||
<div class="sublabel">
|
||||
{#if contentAdded}
|
||||
Added at {contentAdded.toLocaleString()}
|
||||
{:else}
|
||||
---
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="labeled-button">
|
||||
<button
|
||||
class="button"
|
||||
disabled={contentEntriesCount === undefined}
|
||||
on:click={performContent}
|
||||
>
|
||||
{contentEntriesCount === undefined
|
||||
? "???"
|
||||
: contentEntriesCount > 0
|
||||
? "Open"
|
||||
: "Save"} Content
|
||||
</button>
|
||||
<div class="sublabel">
|
||||
{#if contentAdded}
|
||||
Added at {contentAdded.toLocaleString()}
|
||||
{:else}
|
||||
---
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if opening && !openError}
|
||||
<div class="status-label">Working, please wait...</div>
|
||||
{/if}
|
||||
{#if openError}
|
||||
<div class="status-label error">{openError}</div>
|
||||
{/if}
|
||||
<hr />
|
||||
<div class="row">
|
||||
<label>
|
||||
Instance URL
|
||||
<input
|
||||
class="instance-input"
|
||||
type="url"
|
||||
bind:value={instanceUrl}
|
||||
class:modified={instanceUrlModified}
|
||||
/>
|
||||
</label>
|
||||
<button class="button" on:click={() => ($instanceUrlStore = instanceUrl)}>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
<div class="version">
|
||||
Status: {#if !instanceVersionError}
|
||||
{`OK, v.${instanceVersion}` || "???"}
|
||||
{:else}
|
||||
<div class="error">{instanceVersionError}</div>
|
||||
{#if opening && !openError}
|
||||
<div class="status-label">Working, please wait...</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if openError}
|
||||
<div class="status-label error">{openError}</div>
|
||||
{/if}
|
||||
<hr />
|
||||
<div class="row">
|
||||
<label>
|
||||
Instance URL
|
||||
<input
|
||||
class="instance-input"
|
||||
type="url"
|
||||
bind:value={instanceUrl}
|
||||
class:modified={instanceUrlModified}
|
||||
/>
|
||||
</label>
|
||||
<button class="button" on:click={() => ($instanceUrlStore = instanceUrl)}>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
<div class="version">
|
||||
Status: {#if !instanceVersionError}
|
||||
{`OK, v.${instanceVersion}` || "???"}
|
||||
{:else}
|
||||
<div class="error">{instanceVersionError}</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="visitingUpEnd">You rock :)</div>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<style lang="scss">
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<meta name="application-name" content="UpEnd" />
|
||||
|
||||
<title>UpEnd</title>
|
||||
|
||||
|
|
Loading…
Reference in New Issue