diff --git a/public/manifest.json b/public/manifest.json
index 18daff4..5af4a80 100644
--- a/public/manifest.json
+++ b/public/manifest.json
@@ -15,7 +15,7 @@
"content_scripts": [
{
"matches": ["*://www.workflowy.com/*", "*://workflowy.com/*"],
- "js": ["build/content_script.js"]
+ "js": ["build/content_scripts.js"]
}
],
"permissions": ["storage"]
diff --git a/rollup.config.js b/rollup.config.js
index 1734338..da3a462 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -21,7 +21,7 @@ function createConfig(filename, useSvelte = false) {
dev: !production,
// we'll extract any component CSS out into
// a separate file - better for performance
- css: css => {
+ css: (css) => {
css.write(`${filename}.css`, false);
},
preprocess: sveltePreprocess(),
@@ -49,4 +49,4 @@ function createConfig(filename, useSvelte = false) {
};
}
-export default [createConfig("options", true), createConfig("content_script")];
+export default [createConfig("options", true), createConfig("content_scripts")];
diff --git a/src/__tests__/time.test.ts b/src/__tests__/time.test.ts
index a8bef07..becb9f8 100644
--- a/src/__tests__/time.test.ts
+++ b/src/__tests__/time.test.ts
@@ -1,4 +1,4 @@
-import { getTagSeconds } from "../utils/time";
+import { getTagSeconds } from "../content_scripts/time";
describe("time tests", () => {
test("getTagSeconds test", () => {
diff --git a/src/utils/keyboard-keys.ts b/src/common/keyboard-keys.ts
similarity index 100%
rename from src/utils/keyboard-keys.ts
rename to src/common/keyboard-keys.ts
diff --git a/src/storage.ts b/src/common/storage.ts
similarity index 65%
rename from src/storage.ts
rename to src/common/storage.ts
index 88dc404..e1f0439 100644
--- a/src/storage.ts
+++ b/src/common/storage.ts
@@ -1,4 +1,4 @@
-import type { IHotkey } from "./utils/keyboard-keys";
+import type { IHotkey } from "./keyboard-keys";
export type IStorage = {
/** Filter by hashtags on hotkey */
@@ -8,14 +8,11 @@ export type IStorage = {
calcTotalTime: boolean;
/** Swap hashtags on hotkey */
- swapHashtags: {
- delete: string;
- insert: string;
- } & IHotkey;
+ swaps: Array<{ delete: string; insert: string } & IHotkey>;
};
export const defaultStorage: IStorage = {
filters: [],
calcTotalTime: true,
- swapHashtags: null,
+ swaps: [],
};
diff --git a/src/components/Hotkey.svelte b/src/components/Hotkey.svelte
deleted file mode 100644
index 8318314..0000000
--- a/src/components/Hotkey.svelte
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
diff --git a/src/components/Options.svelte b/src/components/Options.svelte
deleted file mode 100644
index 07e76e6..0000000
--- a/src/components/Options.svelte
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
-
-
-
diff --git a/src/content_scripts.ts b/src/content_scripts.ts
new file mode 100644
index 0000000..306908a
--- /dev/null
+++ b/src/content_scripts.ts
@@ -0,0 +1,21 @@
+import setHotkey from "hotkeys-js";
+import { defaultStorage, IStorage } from "./common/storage";
+import { startFiltersOnHotkey, startSwaps } from "./content_scripts/hotkey";
+import { createObserver, highlight, renderTotalTime } from "./content_scripts/time";
+
+// By default hotkeys are not enabled for INPUT, SELECT, TEXTAREA elements.
+setHotkey.filter = function (event) {
+ return true;
+};
+
+chrome.storage.sync.get(defaultStorage, ({ filters, calcTotalTime, swaps }: IStorage) => {
+ // Start calculate total time
+ if (calcTotalTime) {
+ highlight();
+ renderTotalTime();
+ createObserver();
+ }
+
+ startFiltersOnHotkey(filters);
+ startSwaps(swaps);
+});
diff --git a/src/utils/dom.ts b/src/content_scripts/dom.ts
similarity index 100%
rename from src/utils/dom.ts
rename to src/content_scripts/dom.ts
diff --git a/src/content_script.ts b/src/content_scripts/hotkey.ts
similarity index 66%
rename from src/content_script.ts
rename to src/content_scripts/hotkey.ts
index 3803823..4b2e65a 100644
--- a/src/content_script.ts
+++ b/src/content_scripts/hotkey.ts
@@ -1,22 +1,8 @@
import setHotkey from "hotkeys-js";
-import { defaultStorage, IStorage } from "./storage";
-import { createHashtag } from "./utils/dom";
-import { createObserver, highlight, renderTotalTime } from "./utils/time";
+import type { IStorage } from "../common/storage";
+import { createHashtag } from "./dom";
-// By default hotkeys are not enabled for INPUT, SELECT, TEXTAREA elements.
-setHotkey.filter = function (event) {
- return true;
-};
-
-chrome.storage.sync.get(defaultStorage, ({ filters, calcTotalTime, swapHashtags }: IStorage) => {
- // Start calculate total time
- if (calcTotalTime) {
- highlight();
- renderTotalTime();
- createObserver();
- }
-
- // Start filters by hotkey
+export function startFiltersOnHotkey(filters: IStorage["filters"]) {
for (const filter of filters) {
setHotkey(`${filter.specialKey}+${filter.key}`, function (event, handler) {
// Prevent the default refresh event under WINDOWS system
@@ -30,10 +16,11 @@ chrome.storage.sync.get(defaultStorage, ({ filters, calcTotalTime, swapHashtags
}
});
}
+}
- // Start swap hashtags on hotkey
- if (swapHashtags) {
- setHotkey(`${swapHashtags.specialKey}+${swapHashtags.key}`, function (event, handler) {
+export function startSwaps(swaps: IStorage["swaps"]) {
+ for (const swap of swaps) {
+ setHotkey(`${swap.specialKey}+${swap.key}`, function (event, handler) {
// Prevent the default refresh event under WINDOWS system
event.preventDefault();
@@ -41,8 +28,8 @@ chrome.storage.sync.get(defaultStorage, ({ filters, calcTotalTime, swapHashtags
const innerContentContainer = activeElement.querySelector(".innerContentContainer");
if (innerContentContainer) {
- const deleteTags = swapHashtags.delete ? swapHashtags.delete.split(" ") : [];
- const insertTags = swapHashtags.insert ? swapHashtags.insert.split(" ") : [];
+ const deleteTags = swap.delete ? swap.delete.split(" ") : [];
+ const insertTags = swap.insert ? swap.insert.split(" ") : [];
for (const tag of document.activeElement.querySelectorAll(".contentTag")) {
const contentTagText = tag.querySelector(".contentTagText");
@@ -68,4 +55,4 @@ chrome.storage.sync.get(defaultStorage, ({ filters, calcTotalTime, swapHashtags
}
});
}
-});
+}
diff --git a/src/utils/time.ts b/src/content_scripts/time.ts
similarity index 100%
rename from src/utils/time.ts
rename to src/content_scripts/time.ts
diff --git a/src/options.ts b/src/options.ts
index 20083b5..8fe1129 100644
--- a/src/options.ts
+++ b/src/options.ts
@@ -1,3 +1,3 @@
-import Options from "./components/Options.svelte";
+import Options from "./options/components/Options.svelte";
new Options({ target: document.body });
diff --git a/src/components/Fieldset.svelte b/src/options/components/Fieldset.svelte
similarity index 100%
rename from src/components/Fieldset.svelte
rename to src/options/components/Fieldset.svelte
diff --git a/src/options/components/HotkeyCols.svelte b/src/options/components/HotkeyCols.svelte
new file mode 100644
index 0000000..539a46c
--- /dev/null
+++ b/src/options/components/HotkeyCols.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ |
+
+
+ |
diff --git a/src/options/components/Options.svelte b/src/options/components/Options.svelte
new file mode 100644
index 0000000..ed2fb49
--- /dev/null
+++ b/src/options/components/Options.svelte
@@ -0,0 +1,176 @@
+
+
+
+
+
+ {#if options}
+
+
+
+
+
+
+
+
+ {#if successMessage}{successMessage}{/if}
+
+ {:else}
+
Loading...
+ {/if}
+
diff --git a/tsconfig.json b/tsconfig.json
index 45454b5..45ddbf5 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -9,4 +9,4 @@
"typeRoots": ["node_modules/@types"],
"types": ["svelte", "chrome", "jest"]
}
-}
\ No newline at end of file
+}