From f308fbfbb5fad2f45c03754a6d168521d8a1d77f Mon Sep 17 00:00:00 2001 From: Carmine Calabrese Date: Mon, 4 Sep 2023 17:17:04 +0200 Subject: [PATCH] Fixed some Bug - Now the scroll function works properly; - Edited the content of the footer; --- content.js | 7 +++++-- main.html | 10 ++++++---- popup.js | 31 ++++++++++++++++++------------- style.css | 4 ++-- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/content.js b/content.js index 78c0c3c..7951159 100644 --- a/content.js +++ b/content.js @@ -10,6 +10,8 @@ var verifiedElements = []; $(window).on("load", () => { console.log("Esecuzione Content Script"); + // createDB(); + chrome.runtime.sendMessage({ message: "content__retrieve", payload: "textComparison", @@ -40,8 +42,9 @@ $(window).on("load", () => { } if (request.message.includes("scrollTo")) { pos = request.payload; - console.log(verifiedElements[pos]); - verifiedElements[pos].scrollIntoView(); + if (pos > 0) { + verifiedElements[pos - 1].scrollIntoView(); + } } }); diff --git a/main.html b/main.html index de58882..261baf4 100644 --- a/main.html +++ b/main.html @@ -38,7 +38,8 @@
Dark Pattern
Identifier
# out of #
> - Type +

Hidden Information

+

https://example.com/

@@ -49,9 +50,10 @@
Dark Pattern
Identifier
diff --git a/popup.js b/popup.js index 2265d9b..4c70701 100644 --- a/popup.js +++ b/popup.js @@ -10,13 +10,15 @@ const listContent = $(".list__index"); const listDecrement = $("#list__dec"); const listIncrement = $("#list__inc"); const switchStatus = $("#switch__status"); +const darkPattern_Type = $("#DP_Type"); +const currentWebsite = $("#CUR__Website"); let currentIndex = 1; let maxIndex = 1; //Retrieving all the elements of DB at the start retrieveAllDatabase(); -testPrint(); +updateTextList(); //Updating Database when switch change status switchStatus.on("change", () => { @@ -64,18 +66,9 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { } }); -//Update Current Site URL -chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => { - let url = tabs[0].url; - var page = url.substring(0, url.indexOf("/", 9) + 1); - console.log(url); - console.log(page); - $("#CUR__Website").text(page); -}); - // Functions for the list management function updateCounterList(numDarkPatternIdentified) { - if (numDarkPatternIdentified > 0) { + if (numDarkPatternIdentified >= 0) { maxIndex = numDarkPatternIdentified; currentIndex = 0; updateTextList(); @@ -88,7 +81,7 @@ function nextItemList() { //Send a message to content to change focus if (switchStatus.is(":checked")) { if (currentIndex + 1 > maxIndex) { - currentIndex = 1; + currentIndex = 0; } else { currentIndex = currentIndex + 1; } @@ -106,7 +99,7 @@ function previousItemList() { //Click (<): Change Focus on the object //Send a message to content to change focus if (switchStatus.is(":checked")) { - if (currentIndex - 1 <= 0) { + if (currentIndex - 1 < 0) { currentIndex = maxIndex; } else { currentIndex = currentIndex - 1; @@ -123,8 +116,20 @@ function updateTextList() { if (switchStatus.is(":checked")) { let newString = currentIndex + " out of " + maxIndex; listContent.text(newString); + darkPattern_Type.text("Hidden Information"); + + //Update Current Site URL + chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => { + let url = tabs[0].url; + var page = url.substring(0, url.indexOf("/", 9) + 1); + console.log(url); + console.log(page); + currentWebsite.text(page); + }); } else { listContent.text("Activate Switch to track DP"); + darkPattern_Type.text(" "); + currentWebsite.text("..."); } } diff --git a/style.css b/style.css index 2acab8b..337a0cf 100644 --- a/style.css +++ b/style.css @@ -108,9 +108,9 @@ body{ /* FOOTER SECTION */ .footer{ - border: 2px solid purple; + /* border: 2px solid purple; */ height: 20%; - margin-top: 1em; + margin-top: 1.4em; } .footer__text{