From d39d33f1b776ebf53be5ce04334c50b350e43eff Mon Sep 17 00:00:00 2001 From: Carmelo Messina Date: Thu, 9 Mar 2023 16:19:14 +0100 Subject: [PATCH] add eye adblock setting page for windows --- build/bromite_patches_list.txt | 1 + .../00WIN-Add-adblock-plus-setting-page.patch | 569 ++++++++++++++++++ 2 files changed, 570 insertions(+) create mode 100644 build/patches/00WIN-Add-adblock-plus-setting-page.patch diff --git a/build/bromite_patches_list.txt b/build/bromite_patches_list.txt index c8c59554..e0c107d7 100644 --- a/build/bromite_patches_list.txt +++ b/build/bromite_patches_list.txt @@ -259,6 +259,7 @@ Add-kill-switch-for-unsupported-clangd-flags.patch 00AdblockPlus.patch 00Eyeo-Adblock-Remove-Privacy-Issues.patch +00WIN-Add-adblock-plus-setting-page.patch 00WIN-ADDTO-Eyeo-Adblock.patch 00WIN-ADDTO-Add-an-always-incognito-mode.patch diff --git a/build/patches/00WIN-Add-adblock-plus-setting-page.patch b/build/patches/00WIN-Add-adblock-plus-setting-page.patch new file mode 100644 index 00000000..952a7a4a --- /dev/null +++ b/build/patches/00WIN-Add-adblock-plus-setting-page.patch @@ -0,0 +1,569 @@ +From: Your Name +Date: Thu, 9 Mar 2023 13:39:38 +0000 +Subject: WIN Add adblock plus setting page + +--- + chrome/browser/resources/settings/BUILD.gn | 2 + + .../settings/adblock_page/adblock_page.html | 185 ++++++++++++++++ + .../settings/adblock_page/adblock_page.ts | 204 ++++++++++++++++++ + .../settings/basic_page/basic_page.html | 7 + + .../settings/basic_page/basic_page.ts | 1 + + .../resources/settings/page_visibility.ts | 1 + + chrome/browser/resources/settings/route.ts | 4 + + chrome/browser/resources/settings/router.ts | 1 + + chrome/browser/resources/settings/settings.ts | 1 + + .../settings/settings_menu/settings_menu.html | 5 + + tools/typescript/definitions/adblock.d.ts | 33 +++ + 11 files changed, 444 insertions(+) + create mode 100644 chrome/browser/resources/settings/adblock_page/adblock_page.html + create mode 100644 chrome/browser/resources/settings/adblock_page/adblock_page.ts + create mode 100644 tools/typescript/definitions/adblock.d.ts + +diff --git a/chrome/browser/resources/settings/BUILD.gn b/chrome/browser/resources/settings/BUILD.gn +--- a/chrome/browser/resources/settings/BUILD.gn ++++ b/chrome/browser/resources/settings/BUILD.gn +@@ -78,6 +78,7 @@ build_webui("build") { + "a11y_page/a11y_page.ts", + "a11y_page/live_caption_section.ts", + "about_page/about_page.ts", ++ "adblock_page/adblock_page.ts", + "appearance_page/appearance_fonts_page.ts", + "appearance_page/appearance_page.ts", + "appearance_page/home_url_input.ts", +@@ -396,6 +397,7 @@ build_webui("build") { + ts_composite = true + ts_definitions = [ + "//tools/typescript/definitions/autofill_private.d.ts", ++ "//tools/typescript/definitions/adblock.d.ts", + "//tools/typescript/definitions/chrome_send.d.ts", + "//tools/typescript/definitions/language_settings_private.d.ts", + "//tools/typescript/definitions/management.d.ts", +diff --git a/chrome/browser/resources/settings/adblock_page/adblock_page.html b/chrome/browser/resources/settings/adblock_page/adblock_page.html +new file mode 100644 +--- /dev/null ++++ b/chrome/browser/resources/settings/adblock_page/adblock_page.html +@@ -0,0 +1,185 @@ ++ ++ ++ ++ ++ ++ ++
++
++ ++
++ Built in Subscriptions ++
++
++ ++
++ ++
++
++ ++
++
++
++
++ ++
++ Allowed Domains ++
++
++ ++
++ ++
++
++ ++
++
++ ++ ++ Add ++ ++ ++
++
++
++
++
++
++ ++
++ Custom Subscriptions ++
++
++ ++
++ ++
++
++ ++
++
++ ++ ++ Add ++ ++ ++
++
++
++
++
++
++ ++
++ Custom Filters ++
++
++ ++
++ ++
++
++ ++
++
++ ++ ++ Add ++ ++ ++
++
++
++
++
++ ++
+diff --git a/chrome/browser/resources/settings/adblock_page/adblock_page.ts b/chrome/browser/resources/settings/adblock_page/adblock_page.ts +new file mode 100644 +--- /dev/null ++++ b/chrome/browser/resources/settings/adblock_page/adblock_page.ts +@@ -0,0 +1,204 @@ ++/* ++ This file is part of Bromite. ++ ++ Bromite is free software: you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation, either version 3 of the License, or ++ (at your option) any later version. ++ ++ Bromite is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with Bromite. If not, see . ++*/ ++import 'chrome://resources/cr_elements/cr_button/cr_button.js'; ++import 'chrome://resources/cr_elements/cr_shared_style.css.js'; ++import 'chrome://resources/polymer/v3_0/iron-collapse/iron-collapse.js'; ++import 'chrome://resources/polymer/v3_0/iron-flex-layout/iron-flex-layout-classes.js'; ++import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js'; ++import '../controls/controlled_button.js'; ++import '../controls/settings_toggle_button.js'; ++import '../settings_shared.css.js'; ++ ++ ++import { I18nMixin } from 'chrome://resources/cr_elements/i18n_mixin.js'; ++import { BaseMixin } from '../base_mixin.js'; ++import { PolymerElement } from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; ++import { SettingsToggleButtonElement } from '../controls/settings_toggle_button.js'; ++import { PrefsMixin } from '../prefs/prefs_mixin.js'; ++import { CrCheckboxElement } from 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.js'; ++import { getTemplate } from './adblock_page.html.js'; ++ ++ ++const SettingsAdblockPageElementBase = ++ I18nMixin(PrefsMixin(BaseMixin((PolymerElement)))); ++ ++export class SettingsAdblockPageElement extends ++ SettingsAdblockPageElementBase { ++ static get is() { ++ return 'settings-adblock-page'; ++ } ++ ++ static get template() { ++ return getTemplate(); ++ } ++ ++ // input fields updated by html ++ public customSubscriptionInput: string; ++ public customFilterInput: string; ++ public allowedDomainInput: string; ++ ++ // models that will fill templates lists in html ++ public customSubscriptions: Array = []; ++ public customFilters: Array = []; ++ public allowedDomains: Array = []; ++ public subscriptions: chrome.adblockPrivate.Subscription[] = []; ++ ++ private syncSubscriptions() { ++ this.subscriptions = [] ++ this.customSubscriptions = []; ++ ++ chrome.adblockPrivate.getBuiltInSubscriptions(list => { ++ chrome.adblockPrivate.getInstalledSubscriptions(activelist => { ++ let new_subscriptions: chrome.adblockPrivate.Subscription[] = []; ++ let custom_subscriptions: string[] = []; ++ ++ list.forEach(obj => { ++ new_subscriptions.push({ ++ title: obj.title, ++ enabled: false, ++ url: obj.url ++ }) ++ }) ++ ++ activelist.forEach(obj => { ++ var found = new_subscriptions.find(element => element.url == obj.url); ++ if (found != undefined) { ++ found.enabled = true; ++ } else { ++ custom_subscriptions.push(obj.url) ++ } ++ }) ++ ++ this.subscriptions = new_subscriptions; ++ this.customSubscriptions = custom_subscriptions; ++ }) ++ }); ++ } ++ ++ private syncCustomFilters() { ++ chrome.adblockPrivate.getCustomFilters(domain => { ++ this.customFilters = []; ++ domain.forEach(value => { ++ this.customFilters.push(value); ++ }) ++ }); ++ } ++ ++ private syncAllowedDomains() { ++ chrome.adblockPrivate.getAllowedDomains(domain => { ++ this.allowedDomains = []; ++ domain.forEach(value => { ++ this.allowedDomains.push(value); ++ }) ++ }); ++ } ++ ++ public override ready() { ++ super.ready(); ++ ++ this.syncSubscriptions(); ++ this.syncCustomFilters(); ++ this.syncAllowedDomains(); ++ } ++ ++ private onAdblockEnabled_(event: Event) { ++ if ((event.target as SettingsToggleButtonElement).checked) { ++ chrome.adblockPrivate.setEnabled(true); ++ } else { ++ chrome.adblockPrivate.setEnabled(false); ++ } ++ } ++ ++ private cleanUrl(url: string) : string { ++ let cleanedUrl : string = ""; ++ try { ++ cleanedUrl = new URL(url).host; ++ } catch (err) { ++ try { ++ // one last try by adding schema ++ cleanedUrl = new URL("https://" + url).host; ++ } ++ catch (err) { ++ console.log("malformed url " + url); ++ } ++ } ++ return cleanedUrl; ++ } ++ ++ private selectRecommendedSubscription(e: Event) { ++ const url = ((e.target as CrCheckboxElement).id); ++ const enabled = ((e.target as CrCheckboxElement).checked); ++ if (enabled) { ++ chrome.adblockPrivate.installSubscription(url); ++ } else { ++ chrome.adblockPrivate.uninstallSubscription(url); ++ } ++ } ++ ++ private removeCustomFilter(e: Event) { ++ const filter = ((e.target as HTMLElement).id); ++ chrome.adblockPrivate.removeCustomFilter(filter); ++ const i = this.customFilters.indexOf(filter); ++ this.splice('customFilters', i, 1); ++ } ++ ++ private addCustomFilter() { ++ if (this.customFilterInput == undefined || this.customFilterInput == "") return; ++ chrome.adblockPrivate.addCustomFilter(this.customFilterInput); ++ this.customFilterInput = ""; ++ this.syncCustomFilters(); ++ } ++ ++ private removeAllowedDomain(e: Event) { ++ const allowedDomain = ((e.target as HTMLElement).id); ++ chrome.adblockPrivate.removeAllowedDomain(allowedDomain); ++ const i = this.allowedDomains.indexOf(allowedDomain); ++ this.splice('allowedDomains', i, 1); ++ } ++ ++ private addAllowedDomain() { ++ if (this.allowedDomainInput == undefined || this.allowedDomainInput == "") return; ++ const cleanedUrl = this.cleanUrl(this.allowedDomainInput); ++ if (cleanedUrl == "") return; ++ chrome.adblockPrivate.addAllowedDomain(cleanedUrl); ++ this.allowedDomainInput = ""; ++ this.syncAllowedDomains(); ++ } ++ ++ private removeCustomSubscription(e: Event) { ++ const subscription = ((e.target as HTMLElement).id); ++ chrome.adblockPrivate.uninstallSubscription(subscription); ++ const i = this.customSubscriptions.indexOf(subscription); ++ this.splice('customSubscriptions', i, 1); ++ } ++ ++ private addCustomSubscription() { ++ if (this.customSubscriptionInput == undefined || this.customSubscriptionInput == "") return; ++ chrome.adblockPrivate.installSubscription(this.customSubscriptionInput); ++ this.customSubscriptionInput = ""; ++ this.syncSubscriptions(); ++ } ++} ++ ++declare global { ++ interface HTMLElementTagNameMap { ++ 'settings-adblock-page': SettingsAdblockPageElement; ++ } ++} ++ ++customElements.define( ++ SettingsAdblockPageElement.is, SettingsAdblockPageElement); +diff --git a/chrome/browser/resources/settings/basic_page/basic_page.html b/chrome/browser/resources/settings/basic_page/basic_page.html +--- a/chrome/browser/resources/settings/basic_page/basic_page.html ++++ b/chrome/browser/resources/settings/basic_page/basic_page.html +@@ -24,6 +24,13 @@ + + + ++ +