diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index cdcbd647369..ba36b04c3b1 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -1437,5 +1437,14 @@ }, "personalOwnershipPolicyInEffect": { "message": "An organization policy is affecting your ownership options." + }, + "excludedDomains": { + "message": "Excluded Domains" + }, + "excludedDomainsDesc": { + "message": "Bitwarden will not ask to save login details for these domains." + }, + "excludedDomainsInvalidDomain": { + "message": " is not a valid domain" } } diff --git a/src/popup/app-routing.module.ts b/src/popup/app-routing.module.ts index 5c3ea8dbbad..d4d37b07bd3 100644 --- a/src/popup/app-routing.module.ts +++ b/src/popup/app-routing.module.ts @@ -40,6 +40,7 @@ import { GroupingsComponent } from './vault/groupings.component'; import { PasswordHistoryComponent } from './vault/password-history.component'; import { ShareComponent } from './vault/share.component'; import { ViewComponent } from './vault/view.component'; +import { ExcludedDomainsComponent } from './settings/excluded-domains.component'; const routes: Routes = [ { @@ -200,6 +201,12 @@ const routes: Routes = [ canActivate: [AuthGuardService], data: { state: 'sync' }, }, + { + path: 'excluded-domains', + component: ExcludedDomainsComponent, + canActivate: [AuthGuardService], + data: { state: 'excluded-domains' }, + }, { path: 'premium', component: PremiumComponent, diff --git a/src/popup/app.module.ts b/src/popup/app.module.ts index 125f7a713e1..3b6bc204c27 100644 --- a/src/popup/app.module.ts +++ b/src/popup/app.module.ts @@ -46,6 +46,7 @@ import { GroupingsComponent } from './vault/groupings.component'; import { PasswordHistoryComponent } from './vault/password-history.component'; import { ShareComponent } from './vault/share.component'; import { ViewComponent } from './vault/view.component'; +import { ExcludedDomainsComponent } from './settings/excluded-domains.component'; import { A11yTitleDirective } from 'jslib/angular/directives/a11y-title.directive'; import { ApiActionDirective } from 'jslib/angular/directives/api-action.directive'; @@ -181,6 +182,7 @@ registerLocaleData(localeZhTw, 'zh-TW'); ColorPasswordPipe, CurrentTabComponent, EnvironmentComponent, + ExcludedDomainsComponent, ExportComponent, FallbackSrcDirective, FolderAddEditComponent, diff --git a/src/popup/settings/excluded-domains.component.html b/src/popup/settings/excluded-domains.component.html new file mode 100644 index 00000000000..7a104492829 --- /dev/null +++ b/src/popup/settings/excluded-domains.component.html @@ -0,0 +1,53 @@ +
+
+ +
+ {{'excludedDomains' | i18n}} +
+
+ +
+
+ +
+
+ +
+ + + +
+ + + + +
+
+ + + +
+
+
+ + {{'newUri' | i18n}} + +
+ +
+
+
\ No newline at end of file diff --git a/src/popup/settings/excluded-domains.component.ts b/src/popup/settings/excluded-domains.component.ts new file mode 100644 index 00000000000..5be9939e871 --- /dev/null +++ b/src/popup/settings/excluded-domains.component.ts @@ -0,0 +1,111 @@ +import { + Component, + OnInit, + NgZone, + OnDestroy +} from '@angular/core'; +import { Router } from '@angular/router'; + +import { I18nService } from 'jslib/abstractions/i18n.service'; +import { StorageService } from 'jslib/abstractions/storage.service'; +import { ConstantsService } from 'jslib/services/constants.service'; +import { BrowserApi } from '../../browser/browserApi'; +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; +import { Utils } from 'jslib/misc/utils'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; + +interface ExcludedDomain { + uri: string, + showCurrentUris: boolean +} + +const BroadcasterSubscriptionId = 'excludedDomains'; + +@Component({ + selector: 'app-excluded-domains', + templateUrl: 'excluded-domains.component.html', +}) +export class ExcludedDomainsComponent implements OnInit, OnDestroy { + excludedDomains: ExcludedDomain[] = []; + currentUris: string[]; + loadCurrentUrisTimeout: number; + + constructor(private storageService: StorageService, + private i18nService: I18nService, private router: Router, + private broadcasterService: BroadcasterService, private ngZone: NgZone, + private platformUtilsService: PlatformUtilsService) { + } + + async ngOnInit() { + const savedDomains = await this.storageService.get(ConstantsService.neverDomainsKey); + if (savedDomains) { + for (const uri of Object.keys(savedDomains)) { + this.excludedDomains.push({uri: uri, showCurrentUris: false}) + } + } + + this.loadCurrentUris(); + + this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => { + this.ngZone.run(async () => { + switch (message.command) { + case 'tabChanged': + case 'windowChanged': + if (this.loadCurrentUrisTimeout != null) { + window.clearTimeout(this.loadCurrentUrisTimeout); + } + this.loadCurrentUrisTimeout = window.setTimeout(() => this.loadCurrentUris(), 500); + break; + default: + break; + } + }); + }); + } + + ngOnDestroy() { + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + + async addUri() { + this.excludedDomains.push({uri: '', showCurrentUris: false}) + } + + async removeUri(i: number) { + this.excludedDomains.splice(i, 1); + } + + async submit() { + const savedDomains: {[name: string]: null} = {}; + for (const domain of this.excludedDomains) { + if (domain.uri && domain.uri !== '') { + const validDomain = Utils.getHostname(domain.uri); + if (!validDomain) { + this.platformUtilsService.showToast('error', null, + '\'' + domain.uri + '\'' + this.i18nService.t('excludedDomainsInvalidDomain')); + return; + } + savedDomains[validDomain] = null + } + } + await this.storageService.save(ConstantsService.neverDomainsKey, savedDomains); + this.router.navigate(['/tabs/settings']); + } + + trackByFunction(index: number, item: any) { + return index; + } + + toggleUriInput(domain: ExcludedDomain) { + domain.showCurrentUris = !domain.showCurrentUris; + } + + async loadCurrentUris() { + const tabs = await BrowserApi.tabsQuery({ windowType: 'normal' }); + if (tabs) { + const uriSet = new Set(tabs.map((tab) => Utils.getHostname(tab.url))); + uriSet.delete(null); + this.currentUris = Array.from(uriSet); + } + } +} \ No newline at end of file diff --git a/src/popup/settings/settings.component.html b/src/popup/settings/settings.component.html index fc1eeedfe79..7b1f81c1624 100644 --- a/src/popup/settings/settings.component.html +++ b/src/popup/settings/settings.component.html @@ -19,6 +19,10 @@
{{'sync' | i18n}}
+ +
{{'excludedDomains' | i18n}}
+ +