Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox MV3 Migration #462

Merged
merged 17 commits into from
May 22, 2024
Prev Previous commit
Next Next commit
Changed popup info implementation
  • Loading branch information
OliverWang13 committed Apr 18, 2024
commit 566630e37b1807de33b4b98a3770ec420292272b
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