2023-02-13 19:20:50 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import RateSingle from '@/components/RateSingle.svelte'
|
|
|
|
import { getCurrentTab } from '@/utils/chrome-misc'
|
|
|
|
import { onMount } from 'svelte'
|
|
|
|
import { mainStore } from '@/utils/store'
|
|
|
|
import ImgLoader from './ImgLoader.svelte';
|
|
|
|
import { isUrlInvalid } from '@/utils/misc';
|
|
|
|
|
|
|
|
let tab = null
|
2023-02-17 22:12:40 +00:00
|
|
|
let url = new URL('http://127.0.0.1')
|
2023-02-13 19:20:50 +00:00
|
|
|
let isValid = true
|
|
|
|
let loading = true
|
|
|
|
let loader: ImgLoader
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
tab = (await getCurrentTab())[0]
|
|
|
|
isValid = !isUrlInvalid(tab?.url)
|
|
|
|
try {
|
2023-02-17 22:12:40 +00:00
|
|
|
if(tab?.url) {
|
|
|
|
url = new URL(tab?.url)
|
|
|
|
} else {
|
|
|
|
isValid = false
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
isValid = false
|
2023-02-13 19:20:50 +00:00
|
|
|
}
|
|
|
|
loading = false
|
|
|
|
})
|
|
|
|
|
|
|
|
$: {
|
|
|
|
if(loader && (!tab?.favIconUrl || !isValid) ) {
|
|
|
|
loader.onError()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="{`flex flex-col ${loading ? 'animate-pulse' :''}`}">
|
|
|
|
{#if url}
|
|
|
|
<div class="flex items-center flex-col text-[0.8rem] leading-4 mb-4">
|
|
|
|
<div class="mb relative">
|
2023-02-17 22:12:40 +00:00
|
|
|
<ImgLoader source={tab?.favIconUrl ?? ''} bind:this={loader}>
|
2023-02-13 19:20:50 +00:00
|
|
|
<img style="{ $mainStore.settings.theme === 'light'? 'filter: invert(0.9);' : '' }" slot="img" on:load={() => loader.onLoad()} on:error={() => loader.onError}
|
2023-02-17 22:12:40 +00:00
|
|
|
class="w-5 h-5 mt-2 rounded-full wicon" src="{tab?.favIconUrl ?? ''}" alt="favicon" />
|
2023-02-13 19:20:50 +00:00
|
|
|
<svg class="w-5 h-5 mt-2 rounded-full wicon" style="{ $mainStore.settings.theme === 'light'? 'filter: invert(0.9);' : '' }" slot="error" viewBox="0 0 512 512"><g><polygon points="40,38.999 40,468.998 215,293.998 270,348.998 360,258.998 470,358.998 470,38.999 " style="fill:#EFF3F6;"/>
|
|
|
|
<g><circle cx="150" cy="158.999" r="40" style="fill:#FCD884;"/></g><g><polygon points="470,358.998 470,468.998 385,468.998 385,463.998 270,348.998 360,258.998 " style="fill:#70993F;"/></g><g><polygon points="385,463.998 385,468.998 40,468.998 215,293.998 270,348.998" style="fill:#80AF52;"/></g></g><g/></svg>
|
|
|
|
</ImgLoader>
|
|
|
|
{#if isValid}
|
|
|
|
<h1 class="inline-flex text-[1.1rem] font-semibold mb-2">Rate Website</h1>
|
|
|
|
{:else}
|
|
|
|
<h1 class="inline-flex text-[1.1rem] font-semibold mb-2">Invalid URL</h1>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2023-02-17 22:12:40 +00:00
|
|
|
{#if url.hostname !== '127.0.0.1'}
|
2023-02-13 19:20:50 +00:00
|
|
|
<span>Hostname: {url.hostname.length > 18 ? url.hostname.slice(0,16) + '...': url.hostname }</span>
|
|
|
|
<span>URL: {url.href.length > 20 ? '...' + url.href.slice(-20) : url.href}</span>
|
2023-02-17 22:12:40 +00:00
|
|
|
{:else}
|
|
|
|
<span>Hostname: No Active Tab</span>
|
|
|
|
<span>URL: No Active Tab</span>
|
|
|
|
{/if}
|
2023-02-13 19:20:50 +00:00
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
2023-02-18 15:08:52 +00:00
|
|
|
{#key url.href}
|
|
|
|
<RateSingle url={url.href.replace(/\/$/gms, '') ?? ''} disabled={!isValid} />
|
|
|
|
{/key}
|
2023-02-13 19:20:50 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.wicon {
|
|
|
|
position: absolute;
|
|
|
|
top: 2px;
|
|
|
|
left: -24px;
|
|
|
|
background-color: #7878788f;
|
|
|
|
padding: 0.13rem;
|
|
|
|
}
|
|
|
|
</style>
|