aboutsummaryrefslogtreecommitdiff
path: root/extension/src/entries/options/components/Privacy.vue
blob: d54f679fd187ef7431daec3b96546fca87f8e8af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<template>
    <div class="flex flex-col w-full mt-4 sm:px-2">
        <div class="flex flex-row gap-1">
            <div class="text-2xl">
                Tracking protection
            </div>
            <div class="mt-auto" :class="[isOriginProtectionOn ? 'text-primary-600' : 'text-red-500']">
                {{ isOriginProtectionOn ? 'active' : 'inactive' }}
            </div>
        </div>
        <div class="">
            <div class="p-2">
                <div class="my-1">
                    <form @submit.prevent="allowOrigin()">
                        <input class="w-full max-w-xs input primary" type="text" v-model="newOrigin" placeholder="Add new origin"/>
                        <button type="submit" class="ml-1 btn xs" >
                            <fa-icon icon="plus" />
                        </button>
                    </form>
                </div>
                <label class="font-semibold">Whitelist:</label>
                <ul class="pl-1 list-disc list-inside">
                    <li v-for="origin in allowedOrigins" :key="origin" class="my-1 text-sm">
                       <span class="">
                         {{ origin }}
                       </span>
                       <span>
                            <button class="ml-1 text-xs text-red-500" @click="store.dissallowOrigin(origin)">
                                remove
                            </button>
                       </span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { useStore } from '../../store';
import { useFormToaster } from '@vnuge/vnlib.browser';
import { ref } from 'vue';

const store = useStore()
const { isOriginProtectionOn, allowedOrigins } = storeToRefs(store)
const newOrigin = ref('')
const { error, info } = useFormToaster()

const allowOrigin = async () =>{
   try {
        await store.allowOrigin(newOrigin.value)
    }
    catch (err: any) {
        error({
            title: 'Failed to allow origin',
            text: err.message
        })
        return;
    }
    info({
        title: 'Origin allowed',
        text: `Origin ${newOrigin.value} has been allowed`
    })
    newOrigin.value = ''
}

</script>