Skip to content

Commit

Permalink
Added popup page
Browse files Browse the repository at this point in the history
  • Loading branch information
farazshuja committed Sep 2, 2022
1 parent 33c0879 commit 73a8b54
Show file tree
Hide file tree
Showing 16 changed files with 742 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = {
'@vue/eslint-config-typescript/recommended',
'@vue/eslint-config-prettier',
],
rules: {
'vue/multi-word-component-names': 'off',
},
parserOptions: {
ecmaVersion: 'latest',
'prettier/prettier': [
Expand Down
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare module '@vue/runtime-core' {
'Carbon:faceCool': typeof import('~icons/carbon/face-cool')['default']
CarbonApi: typeof import('~icons/carbon/api')['default']
CarbonArea: typeof import('~icons/carbon/area')['default']
CarbonBee: typeof import('~icons/carbon/bee')['default']
CarbonCharacterLowerCase: typeof import('~icons/carbon/character-lower-case')['default']
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
IconCommunity: typeof import('./src/components/icons/IconCommunity.vue')['default']
Expand Down
13 changes: 13 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"manifest_version": 3,
"name": "CRXJS Vue Vite Example",
"version": "1.0.0",
"action": { "default_popup": "src/popup/index.html" },
"permissions": ["storage"],
"icons": {
"16": "src/assets/bee16.png",
"32": "src/assets/bee32.png",
"48": "src/assets/bee48.png",
"128": "src/assets/bee128.png"
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
},
"dependencies": {
"@vueuse/core": "^9.1.1",
"vue": "^3.2.37"
},
"devDependencies": {
"@crxjs/vite-plugin": "^1.0.14",
"@iconify/json": "^2.1.101",
"@rushstack/eslint-patch": "^1.1.4",
"@types/chrome": "^0.0.196",
"@types/jsdom": "^20.0.0",
"@types/node": "^16.11.47",
"@vitejs/plugin-vue": "^3.0.1",
Expand Down
Binary file added src/assets/bee128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/bee16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/bee32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/bee48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/composables/useStorageLocal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { storage } from 'webextension-polyfill';
import type {
MaybeRef,
RemovableRef,
StorageLikeAsync,
UseStorageAsyncOptions,
} from '@vueuse/core';
import { useStorageAsync } from '@vueuse/core';

const storageLocal: StorageLikeAsync = {
removeItem(key: string) {
return storage.local.remove(key);
},

setItem(key: string, value: string) {
return storage.local.set({ [key]: value });
},

async getItem(key: string) {
debugger;
return (await storage.local.get(key))[key];
},
};

export const useStorageLocal = <T>(
key: string,
initialValue: MaybeRef<T>,
options?: UseStorageAsyncOptions<T>
): RemovableRef<T> => useStorageAsync(key, initialValue, storageLocal, options);
1 change: 1 addition & 0 deletions src/logic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './storage';
5 changes: 5 additions & 0 deletions src/logic/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useStorageLocal } from '@/composables/useStorageLocal';

export const storageDemo = useStorageLocal('webext-demo', 'Storage Demo', {
listenToStorageChanges: true,
});
22 changes: 22 additions & 0 deletions src/popup/Popup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script setup lang="ts">
import { storageDemo } from '@/logic/storage';
function openOptionsPage() {
chrome.runtime.openOptionsPage();
}
</script>

<template>
<main class="w-[300px] px-4 py-5 text-center text-gray-700">
<carbon-bee class="text-red-20 text-6xl m-auto" />
<p class="mt-2 opacity-50">This is the popup page</p>
<button
class="btn mt-2 bg-blue-300 px-4 py-1 rounded-md hover:bg-blue-400"
@click="openOptionsPage"
>
Open Options
</button>
<div class="mt-2">
<span class="opacity-50">Storage:</span> {{ storageDemo }}
</div>
</main>
</template>
12 changes: 12 additions & 0 deletions src/popup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base target="_blank">
<title>Popup</title>
</head>
<body style="min-width: 100px">
<div id="app"></div>
<script type="module" src="./main.ts"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions src/popup/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createApp } from 'vue';
import 'virtual:windi.css';
import App from './Popup.vue';
import '@/assets/main.css';

const app = createApp(App);
app.mount('#app');
4 changes: 3 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import IconsResolver from 'unplugin-icons/resolver';
import Components from 'unplugin-vue-components/vite';
import AutoImport from 'unplugin-auto-import/vite';
import WindiCSS from 'vite-plugin-windicss';
import { crx } from '@crxjs/vite-plugin';
import manifest from './manifest.json';
import windiConfig from './windi.config';

// export const r = (...args: string[]) => fileURLToPath(new URL('./src', import.meta.url);
Expand All @@ -16,7 +18,7 @@ import windiConfig from './windi.config';
export default defineConfig({
plugins: [
vue(),

crx({ manifest }),
AutoImport({
imports: [
'vue',
Expand Down
Loading

0 comments on commit 73a8b54

Please sign in to comment.