Skip to content

Commit

Permalink
Added <clipboardPaste> and <paste> within Func:: event (#433)
Browse files Browse the repository at this point in the history
Refactor value.ts to handle clipboard paste and local storage paste
  • Loading branch information
dharmesh-hemaram authored Sep 19, 2024
1 parent 87f8b92 commit 84d95e4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions libs/acf/util/src/lib/value.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import RandExp from 'randexp';

const LOCAL_STORAGE_COPY = 'auto-clicker-copy';

declare global {
interface Window {
__batchRepeat: number;
Expand All @@ -16,6 +18,8 @@ export const VALUE_MATCHER = {
BATCH_REPEAT: /<batchRepeat>/,
ACTION_REPEAT: /<actionRepeat>/,
SESSION_COUNT: /<sessionCount>/,
CLIPBOARD_PASTE: /<clipboardPaste>/,
PASTE: /<paste>/,
};

export const Value = (() => {
Expand Down Expand Up @@ -51,6 +55,17 @@ export const Value = (() => {
return value;
};

const getClipboardPaste = async (value: string): Promise<string> => {
const clipText = await navigator.clipboard.readText();
return value.replaceAll('<clipboardPaste>', clipText);
};

const getPaste = (value: string): string => {
const copyContent = localStorage.getItem(LOCAL_STORAGE_COPY);
if (copyContent) return value.replaceAll('<paste>', copyContent);
return value;
};

const getValue = async (value: string): Promise<string> => {
/// For select box value is boolean true
if (typeof value !== 'string') {
Expand All @@ -75,6 +90,12 @@ export const Value = (() => {
if (VALUE_MATCHER.API.test(value)) {
value = getApiValue(value);
}
if (VALUE_MATCHER.CLIPBOARD_PASTE.test(value)) {
value = await getClipboardPaste(value);
}
if (VALUE_MATCHER.PASTE.test(value)) {
value = getPaste(value);
}
return value;
};

Expand Down

0 comments on commit 84d95e4

Please sign in to comment.