Skip to content

Commit

Permalink
Changed popup info implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverWang13 committed Apr 18, 2024
1 parent ddc3c18 commit 566630e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 53 deletions.
30 changes: 18 additions & 12 deletions src/background/protection/protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,25 @@ async function updateDomainlist(details) {
//get the current parsed domain--this is used to store 3rd parties (using globalParsedDomain variable)

let currentDomain = await getCurrentParsedDomain();
//initialize the objects
if (!(activeTabID in domPrev3rdParties)){
domPrev3rdParties[activeTabID] = {};
}
if (!(currentDomain in domPrev3rdParties[activeTabID]) ){
domPrev3rdParties[activeTabID][currentDomain] = {};
}
//as they come in, add the parsedDomain to the object with null value (just a placeholder)
domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null;
// console.log("activeTabID: ",activeTabID);
// console.log("DP3P: ", domPrev3rdParties);
console.log("tabs: ", tabs);
let info = tabs[activeTabID]["REQUEST_DOMAINS"];
let data = Object.keys(info);

let data = JSON.stringify(domPrev3rdParties[activeTabID]);
console.log("setting to storage: ", data);
await storage.set(stores.thirdParties, data, "parties");
//initialize the objects
// if (!(activeTabID in domPrev3rdParties)){
// domPrev3rdParties[activeTabID] = {};
// }
// if (!(currentDomain in domPrev3rdParties[activeTabID]) ){
// domPrev3rdParties[activeTabID][currentDomain] = {};
// }
// //as they come in, add the parsedDomain to the object with null value (just a placeholder)
// domPrev3rdParties[activeTabID][currentDomain][parsedDomain] = null;

//let data = JSON.stringify(data);
console.log("setting to storage under ", currentDomain, ": ", data);
await storage.set(stores.thirdParties, data, currentDomain);

}

Expand Down
84 changes: 43 additions & 41 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ async function showProtectionInfo() {
listenerDropdown2Toggle();

let domain = await getCurrentParsedDomain();
let parties = await storage.get(stores.thirdParties, "parties");
parties = JSON.parse(parties);
console.log("parties: ", parties[domain]);
let parties = await storage.get(stores.thirdParties, domain);
//parties = JSON.parse(parties);
console.log("parties under ", domain, ": ", parties);

let requestsData = parties[domain];
let requestsData = parties;
console.log("request data: ", requestsData);
buildDomains(requestsData);

Expand Down Expand Up @@ -505,14 +505,16 @@ function addThirdPartyDomainDNSToggleListener(requestDomain) {
* @param {Object} requests - Contains all request domains for the current tab
* (requests = tabs[activeTabID].requestDomainS; passed from background page)
*/
async function buildDomains(requests) {
async function buildDomains(requests) {
let domain = await getCurrentParsedDomain();
let items = "";
const domainlistKeys = await storage.getAllKeys(stores.domainlist);
const domainlistValues = await storage.getAll(stores.domainlist);

// Sets the 3rd party domain elements
for (let requestDomain in requests) {
// Iterate through requests array
for (let i = 0; i < requests.length; i++) {
const requestDomain = requests[i]; // Get the domain name from the request array

if (requestDomain != domain) {
let checkbox = "";
let text = "";
Expand All @@ -527,46 +529,46 @@ async function buildDomains(requests) {
}

items += `
<li>
<div
class="blue-heading uk-flex-inline uk-width-1-1 uk-flex-center uk-text-center uk-text-bold uk-text-truncate"
style="font-size: medium"
id="domain"
>
${requestDomain}
</div>
<div uk-grid style="margin-top: 4%; ">
<div
id="dns-enabled-text-${requestDomain}"
class="uk-width-expand uk-margin-auto-vertical"
style="font-size: small;"
>
${text}
</div>
<div>
<div uk-grid>
<div class="uk-width-auto">
<label class="switch switch-smaller" id="switch-label-${requestDomain}">
<!-- Populate switch preference here -->
<!-- <input type="checkbox" id="input"/> -->
${checkbox}
<span class="tooltip-1"></span>
</label>
<li>
<div
class="blue-heading uk-flex-inline uk-width-1-1 uk-flex-center uk-text-center uk-text-bold uk-text-truncate"
style="font-size: medium"
id="domain"
>
${requestDomain}
</div>
</div>
</div>
</div>
<!-- Response info -->
<div uk-grid uk-grid-row-collapse style="margin-top:0px;">
</div>
</li>
`;
<div uk-grid style="margin-top: 4%; ">
<div
id="dns-enabled-text-${requestDomain}"
class="uk-width-expand uk-margin-auto-vertical"
style="font-size: small;"
>
${text}
</div>
<div>
<div uk-grid>
<div class="uk-width-auto">
<label class="switch switch-smaller" id="switch-label-${requestDomain}">
<!-- Populate switch preference here -->
${checkbox}
<span class="tooltip-1"></span>
</label>
</div>
</div>
</div>
</div>
<!-- Response info -->
<div uk-grid uk-grid-row-collapse style="margin-top:0px;">
</div>
</li>
`;
}
}
document.getElementById("dropdown-1-expandable").innerHTML = items;

// Sets the 3rd party domain toggle listeners
for (let requestDomain in requests) {
for (let i = 0; i < requests.length; i++) {
const requestDomain = requests[i];
if (requestDomain != domain) {
addThirdPartyDomainDNSToggleListener(requestDomain);
}
Expand Down

0 comments on commit 566630e

Please sign in to comment.