|
1183 | 1183 | return unprotectedDomain;
|
1184 | 1184 | }
|
1185 | 1185 | function computeLimitedSiteObject() {
|
1186 |
| - const topLevelHostname = getTabHostname(); |
| 1186 | + const tabURL = getTabUrl(); |
1187 | 1187 | return {
|
1188 |
| - domain: topLevelHostname, |
1189 |
| - url: getTabUrl()?.href || null |
| 1188 | + domain: tabURL?.hostname || null, |
| 1189 | + url: tabURL?.href || null |
1190 | 1190 | };
|
1191 | 1191 | }
|
1192 | 1192 | function getPlatformVersion(preferences) {
|
|
3650 | 3650 | __privateGet(this, _args).featureSettings = parseFeatureSettings(bundledConfig, enabledFeatures);
|
3651 | 3651 | }
|
3652 | 3652 | }
|
| 3653 | + /** |
| 3654 | + * Call this when the top URL has changed, to recompute the site object. |
| 3655 | + * This is used to update the path matching for urlPattern. |
| 3656 | + */ |
| 3657 | + recomputeSiteObject() { |
| 3658 | + if (__privateGet(this, _args)) { |
| 3659 | + __privateGet(this, _args).site = computeLimitedSiteObject(); |
| 3660 | + } |
| 3661 | + } |
3653 | 3662 | get args() {
|
3654 | 3663 | return __privateGet(this, _args);
|
3655 | 3664 | }
|
|
3903 | 3912 | __privateAdd(this, _messaging);
|
3904 | 3913 | /** @type {boolean} */
|
3905 | 3914 | __privateAdd(this, _isDebugFlagSet, false);
|
| 3915 | + /** |
| 3916 | + * Set this to true if you wish to listen to top level URL changes for config matching. |
| 3917 | + * @type {boolean} |
| 3918 | + */ |
| 3919 | + __publicField(this, "listenForUrlChanges", false); |
3906 | 3920 | /** @type {ImportMeta} */
|
3907 | 3921 | __privateAdd(this, _importConfig);
|
3908 | 3922 | this.setArgs(this.args);
|
|
6562 | 6576 | } else {
|
6563 | 6577 | applyRules(activeRules);
|
6564 | 6578 | }
|
6565 |
| - const historyMethodProxy = new DDGProxy(this, History.prototype, "pushState", { |
6566 |
| - apply(target, thisArg, args) { |
6567 |
| - applyRules(activeRules); |
6568 |
| - return DDGReflect.apply(target, thisArg, args); |
6569 |
| - } |
6570 |
| - }); |
6571 |
| - historyMethodProxy.overload(); |
6572 |
| - window.addEventListener("popstate", () => { |
6573 |
| - applyRules(activeRules); |
6574 |
| - }); |
| 6579 | + this.activeRules = activeRules; |
| 6580 | + } |
| 6581 | + urlChanged() { |
| 6582 | + if (this.activeRules) { |
| 6583 | + this.applyRules(this.activeRules); |
| 6584 | + } |
6575 | 6585 | }
|
6576 | 6586 | /**
|
6577 | 6587 | * Apply relevant hiding rules to page at set intervals
|
|
6626 | 6636 | // src/features/api-manipulation.js
|
6627 | 6637 | init_define_import_meta_trackerLookup();
|
6628 | 6638 | var ApiManipulation = class extends ContentFeature {
|
| 6639 | + constructor() { |
| 6640 | + super(...arguments); |
| 6641 | + __publicField(this, "listenForUrlChanges", true); |
| 6642 | + } |
6629 | 6643 | init() {
|
6630 | 6644 | const apiChanges = this.getFeatureSetting("apiChanges");
|
6631 | 6645 | if (apiChanges) {
|
|
6638 | 6652 | }
|
6639 | 6653 | }
|
6640 | 6654 | }
|
| 6655 | + urlChanged() { |
| 6656 | + this.init(); |
| 6657 | + } |
6641 | 6658 | /**
|
6642 | 6659 | * Checks if the config API change is valid.
|
6643 | 6660 | * @param {any} change
|
|
6763 | 6780 | ddg_feature_apiManipulation: ApiManipulation
|
6764 | 6781 | };
|
6765 | 6782 |
|
| 6783 | + // src/url-change.js |
| 6784 | + init_define_import_meta_trackerLookup(); |
| 6785 | + var urlChangeListeners = /* @__PURE__ */ new Set(); |
| 6786 | + function registerForURLChanges(listener) { |
| 6787 | + if (urlChangeListeners.size === 0) { |
| 6788 | + listenForURLChanges(); |
| 6789 | + } |
| 6790 | + urlChangeListeners.add(listener); |
| 6791 | + } |
| 6792 | + function handleURLChange() { |
| 6793 | + for (const listener of urlChangeListeners) { |
| 6794 | + listener(); |
| 6795 | + } |
| 6796 | + } |
| 6797 | + function listenForURLChanges() { |
| 6798 | + const urlChangedInstance = new ContentFeature("urlChanged", {}, {}); |
| 6799 | + if ("navigation" in globalThis && "addEventListener" in globalThis.navigation) { |
| 6800 | + globalThis.navigation.addEventListener("navigatesuccess", () => { |
| 6801 | + handleURLChange(); |
| 6802 | + }); |
| 6803 | + return; |
| 6804 | + } |
| 6805 | + if (isBeingFramed()) { |
| 6806 | + return; |
| 6807 | + } |
| 6808 | + const historyMethodProxy = new DDGProxy(urlChangedInstance, History.prototype, "pushState", { |
| 6809 | + apply(target, thisArg, args) { |
| 6810 | + const changeResult = DDGReflect.apply(target, thisArg, args); |
| 6811 | + handleURLChange(); |
| 6812 | + return changeResult; |
| 6813 | + } |
| 6814 | + }); |
| 6815 | + historyMethodProxy.overload(); |
| 6816 | + window.addEventListener("popstate", () => { |
| 6817 | + handleURLChange(); |
| 6818 | + }); |
| 6819 | + } |
| 6820 | + |
6766 | 6821 | // src/content-scope-features.js
|
6767 | 6822 | var initArgs = null;
|
6768 | 6823 | var updates = [];
|
|
6803 | 6858 | resolvedFeatures.forEach(({ featureInstance: featureInstance2, featureName }) => {
|
6804 | 6859 | if (!isFeatureBroken(args, featureName) || alwaysInitExtensionFeatures(args, featureName)) {
|
6805 | 6860 | featureInstance2.callInit(args);
|
| 6861 | + if (featureInstance2.listenForUrlChanges || featureInstance2.urlChanged) { |
| 6862 | + registerForURLChanges(() => { |
| 6863 | + featureInstance2.recomputeSiteObject(); |
| 6864 | + featureInstance2?.urlChanged(); |
| 6865 | + }); |
| 6866 | + } |
6806 | 6867 | }
|
6807 | 6868 | });
|
6808 | 6869 | while (updates.length) {
|
|
0 commit comments