chore: safeguard in webext against running in upend
parent
7af13e7d5f
commit
1f6d7fe090
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
const api = new UpEndApi("http://localhost:8093");
|
const api = new UpEndApi("http://localhost:8093");
|
||||||
|
|
||||||
|
let visitngUpEnd = false;
|
||||||
|
|
||||||
let opening = false;
|
let opening = false;
|
||||||
let openError: string | undefined;
|
let openError: string | undefined;
|
||||||
|
|
||||||
|
@ -44,6 +46,14 @@
|
||||||
let currentUrl: string | undefined;
|
let currentUrl: string | undefined;
|
||||||
let contentType: string | undefined;
|
let contentType: string | undefined;
|
||||||
onMount(async () => {
|
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();
|
currentUrl = await getCurrentUrl();
|
||||||
|
|
||||||
browser.tabs.onUpdated.addListener(async () => {
|
browser.tabs.onUpdated.addListener(async () => {
|
||||||
|
@ -211,86 +221,90 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div class="primary-controls">
|
{#if !visitngUpEnd}
|
||||||
<button
|
<div class="primary-controls">
|
||||||
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">
|
|
||||||
<button
|
<button
|
||||||
class="button"
|
class="button"
|
||||||
disabled={urlEntriesCount === undefined}
|
disabled={primaryAction == PRIMARY_ACTION.UNKNOWN}
|
||||||
on:click={performUrl}
|
on:click={performPrimary}
|
||||||
>
|
>
|
||||||
{urlEntriesCount === undefined
|
{primaryAction} as {primaryType}
|
||||||
? "???"
|
|
||||||
: urlEntriesCount > 0
|
|
||||||
? "Open"
|
|
||||||
: "Save"} URL
|
|
||||||
</button>
|
</button>
|
||||||
<div class="sublabel">
|
<div class="sublabel">Content type: {contentType || "???"}</div>
|
||||||
{#if urlAdded}
|
</div>
|
||||||
Added at {urlAdded.toLocaleString()}
|
<div class="controls row">
|
||||||
{:else}
|
<div class="labeled-button">
|
||||||
---
|
<button
|
||||||
{/if}
|
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>
|
</div>
|
||||||
<div class="labeled-button">
|
{#if opening && !openError}
|
||||||
<button
|
<div class="status-label">Working, please wait...</div>
|
||||||
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}
|
{/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>
|
</main>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
|
<meta name="application-name" content="UpEnd" />
|
||||||
|
|
||||||
<title>UpEnd</title>
|
<title>UpEnd</title>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue