Skip to content

Commit

Permalink
handle statefulness of popup widget data current to the tab user is on
Browse files Browse the repository at this point in the history
  • Loading branch information
ablanathtanalba committed Sep 8, 2021
1 parent 4aeaa96 commit 7e28e76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/js/contentscripts/socialwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ function replaceIndividualButton(widget) {
// make an object for each widget type getting replaced, with option for multiple replacements of it on page
replacedWidgetsForPopup.name = widget.name;
replacedWidgetsForPopup.replacementUrls = [];
replacedWidgetsForPopup.tabUrl = window.location.href;

elsToReplace.forEach(function (el) {
createReplacementElement(widget, el, function (replacementEl) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function init() {
$('#expand-firstparty-popup').show();
}

// show replaced widgets section if there's more than zero replaced widgets on page
// show replaced widgets section if there are replaced widgets on page
if (POPUP_DATA.enabled && Object.keys(POPUP_DATA.replacedWidgets).length) {
$('#replaced-widgets-container').show();
$('#expand-widgets-popup').show();
Expand Down
15 changes: 12 additions & 3 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let constants = require("constants"),
/************ Local Variables *****************/
let tempAllowlist = {},
tempAllowedWidgets = {},
replacedWidgets = [];
replacedWidgets = {};

/***************** Blocking Listener Functions **************/

Expand Down Expand Up @@ -1063,8 +1063,10 @@ function dispatcher(request, sender, sendResponse) {
}

case "sendReplacedWidgetsToPopup": {
// this new set of replaced widgets on a given page should completely replace what might already be on badger object
replacedWidgets = request.widgetReplacementDetails;
// replace whatever previously stored widget data is already locally stored here
if (request.widgetReplacementDetails.replacementUrls.length) {
replacedWidgets = request.widgetReplacementDetails;
}
break;
}

Expand All @@ -1091,6 +1093,13 @@ function dispatcher(request, sender, sendResponse) {
}
}

// wipe out stored replacedWidgets var if user is on a new page with no widgets replaced
if (Object.keys(replacedWidgets).length) {
if (!replacedWidgets.tabUrl.includes(tab_host)) {
replacedWidgets = {};
}
}

sendResponse({
cookieblocked,
criticalError: badger.criticalError,
Expand Down

0 comments on commit 7e28e76

Please sign in to comment.