Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@
"message": "Use Autofill",
"description": "Use Autofill"
},
"autofill_mode": {
"message": "Autofill mode",
"description": "Label for autofill mode selector"
},
"autofill_mode_replace": {
"message": "Replace (dedicated OTP field)",
"description": "Autofill replaces the value in detected OTP field"
},
"autofill_mode_append": {
"message": "Append to focused field (password + OTP)",
"description": "Autofill appends the code to the currently focused input"
},
"use_high_contrast": {
"message": "Use High Contrast",
"description": "Use High Contrast"
Expand Down
1 change: 1 addition & 0 deletions src/components/Popup/EntryComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default Vue.extend({
chrome.tabs.sendMessage(tab.id, {
action: "pastecode",
code: entry.code,
mode: this.$store.state.menu.autofillMode,
});
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/components/Popup/PreferencesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
<option value="20">20%</option>
</a-select-input>
<a-toggle-input :label="i18n.use_autofill" v-model="useAutofill" />
<a-select-input
v-if="useAutofill"
:label="i18n.autofill_mode"
v-model="autofillMode"
style="margin-left: 10px"
>
<option value="replace">{{ i18n.autofill_mode_replace }}</option>
<option value="append">{{ i18n.autofill_mode_append }}</option>
</a-select-input>
<a-toggle-input
:label="i18n.browser_sync"
v-model="browserSync"
Expand Down Expand Up @@ -83,6 +92,14 @@ export default Vue.extend({
this.$store.commit("menu/setAutofill", useAutofill);
},
},
autofillMode: {
get(): "replace" | "append" {
return this.$store.state.menu.autofillMode;
},
set(autofillMode: "replace" | "append") {
this.$store.commit("menu/setAutofillMode", autofillMode);
},
},
smartFilter: {
get(): boolean {
return this.$store.state.menu.smartFilter;
Expand Down
14 changes: 12 additions & 2 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (!document.getElementById("__ga_grayLayout__")) {
alert(chrome.i18n.getMessage("updateSuccess"));
break;
case "pastecode":
pasteCode(message.code);
pasteCode(message.code, message.mode || "replace");
break;
case "stopCapture": {
const captureBox = document.getElementById("__ga_captureBox__");
Expand Down Expand Up @@ -282,7 +282,17 @@ async function qrDecode(
qr.src = url;
}

function pasteCode(code: string) {
function pasteCode(code: string, mode: "replace" | "append" = "replace") {
if (mode === "append") {
const activeEl = document.activeElement;
if (activeEl && activeEl.tagName === "INPUT") {
const inputBox = activeEl as HTMLInputElement;
inputBox.value = inputBox.value + code;
fireInputEvents(inputBox);
}
return;
}

const _inputBoxes = document.getElementsByTagName("input");
const inputBoxes: HTMLInputElement[] = [];
for (let i = 0; i < _inputBoxes.length; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/definitions/module-interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface MenuState {
zoom: number;
autolock: number;
useAutofill: boolean;
autofillMode: "replace" | "append";
smartFilter: boolean;
enableContextMenu: boolean;
theme: string;
Expand Down
1 change: 1 addition & 0 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface UserSettingsData {
// syncable settings
advisorIgnoreList?: string[];
autofill?: boolean;
autofillMode?: "replace" | "append";
autolock?: number;
enableContextMenu?: boolean;
encodedPhrase?: string;
Expand Down
10 changes: 10 additions & 0 deletions src/store/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class Menu implements Module {
version: chrome.runtime.getManifest()?.version || "0.0.0",
zoom: Number(UserSettings.items.zoom) || 100,
useAutofill: UserSettings.items.autofill === true,
autofillMode:
UserSettings.items.autofillMode === "append" ? "append" : "replace",
smartFilter: UserSettings.items.smartFilter === true,
enableContextMenu: UserSettings.items.enableContextMenu === true,
theme: UserSettings.items.theme || (isSafari ? "flat" : "normal"),
Expand Down Expand Up @@ -38,6 +40,14 @@ export class Menu implements Module {
UserSettings.items.autofill = useAutofill;
UserSettings.commitItems();
},
setAutofillMode(
state: MenuState,
autofillMode: "replace" | "append"
) {
state.autofillMode = autofillMode;
UserSettings.items.autofillMode = autofillMode;
UserSettings.commitItems();
},
setSmartFilter(state: MenuState, smartFilter: boolean) {
state.smartFilter = smartFilter;
UserSettings.items.smartFilter = smartFilter;
Expand Down