From d48d66516d3381849a230acb4d541f5effb067d3 Mon Sep 17 00:00:00 2001 From: hardik-pratap-singh <21bcs090@iiitdmj.ac.in> Date: Thu, 25 Jul 2024 09:45:49 +0530 Subject: [PATCH 01/19] v 1.0.0 prototype --- browser-extension/prototype/index.html | 57 ++++++++++ browser-extension/prototype/index.js | 141 +++++++++++++++++++++++++ browser-extension/prototype/info.png | Bin 0 -> 13149 bytes 3 files changed, 198 insertions(+) create mode 100644 browser-extension/prototype/index.html create mode 100644 browser-extension/prototype/index.js create mode 100644 browser-extension/prototype/info.png diff --git a/browser-extension/prototype/index.html b/browser-extension/prototype/index.html new file mode 100644 index 00000000..e5b08797 --- /dev/null +++ b/browser-extension/prototype/index.html @@ -0,0 +1,57 @@ + + + +
+ + ++ Lorem ipsum dolor sit amet consectetur crazy adipisicing elit. Quaerat alias iste quo exercitationem stupid + nesciunt ea? +
+ ++ + + + Lorem ipsum, dolor sit amet stupid mad adipisicing elit. Magni minima adipisci architecto. +
++ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa possimus quisquam temporibus + reprehenderit nesciunt dignissimos sunt ipsum, nostrum modi? Iusto libero sed alias! +
+ crazy ++ Lorem ipsum dolor crazy Lorem, ipsum dolor. sit stupid amet consectetur adipisicing elit. Aut architecto illum dolorum + mad. +
+ + + + + \ No newline at end of file diff --git a/browser-extension/prototype/index.js b/browser-extension/prototype/index.js new file mode 100644 index 00000000..7d1f1860 --- /dev/null +++ b/browser-extension/prototype/index.js @@ -0,0 +1,141 @@ +function checkFalseTextNode(text, actualLengthOfText) { + let totalNewlineAndWhitespaces = 0; + for (let i = 0; i < text.length; i++) { + if (text[i] === "\n" || text[i] === " " || text[i] === "\t") { // I think not only \n and " " , if a textNode is comprised of any escape characters and whitespace, it should be a false textNode + totalNewlineAndWhitespaces++; + } + } + return totalNewlineAndWhitespaces === actualLengthOfText; +} + +// Function to recursively get all text nodes under a given node +function getAllTextNodes(node, uliStore) { + if (node.nodeType === 3) { // Text node + if (!checkFalseTextNode(node.data, node.length)) { + uliStore.push({ node: node, parent: node.parentNode }); + } + } else { + let children = Array.from(node.childNodes); + children.forEach(child => getAllTextNodes(child, uliStore)); + } +} + + +function findPositions(word, text) { + let positions = {}; + + let len = word.length + let loc = [] + let index = text.toString().indexOf(word); + while (index !== -1) { + let obj = {}; + loc.push([index, index + len]); + index = text.toString().indexOf(word, index + 1); + } + + + if (loc.length !== 0) { + positions.slurText = word + positions.slurLocation = loc; + } + return positions; +} + + +function locateSlur(uliStore, targetWords) { + let n = uliStore.length; + + for (let i = 0; i < n; i++) { + let store = uliStore[i]; //This will contain the textNode + let parentNode = store.parent + let text = store.node.textContent + //We have to look into this store for all the slurWords + let slurs = []; + + targetWords.forEach(targetWord => { + let slurWord = targetWord; + let pos = findPositions(slurWord, text); + if (Object.keys(pos).length !== 0) { + slurs.push(pos) + } + + if (parentNode.innerHTML.includes(targetWord)) { + const className = `icon-container-${targetWord}`; + const parts = parentNode.innerHTML.split(targetWord); + const replacedHTML = parts.join(`${targetWord}`); + parentNode.innerHTML = replacedHTML + } + }) + uliStore[i].slurs = slurs; + } + return uliStore; //This will return the final uliStore (after appending slurs) +} + + +function addMetaData(targetWords) { + targetWords.forEach(targetWord => { + const className = `icon-container-${targetWord}` + const elements = Array.from(document.querySelectorAll(`.${className}`)) + elements.forEach(element => { + + let sup = document.createElement("sup"); + + let img = document.createElement("img"); + img.style.height = "2%" + img.style.width = "2%" + img.style.cursor = "pointer" + // img.src = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png" + img.src = "./info.png" + img.alt = "altText" + + let span = document.createElement("span") + span.style.display = "none" + span.style.position = "absolute" + span.style.backgroundColor = "antiquewhite" + span.style.border = "1px solid black" + span.style.borderRadius = "12px" + span.style.padding = "2px 6px" + span.style.width = "12rem" + span.style.textAlign = "justify" + span.innerHTML = `This is ${targetWord}` + + + if (targetWord === "crazy") { + span.innerHTML = `Referring to behaviors or situations as "crazy" can perpetuate stereotypes about mental health and may be hurtful to those with mental health conditions.` + } + else if (targetWord === "mad") { + span.innerHTML = `Using "mad" to describe someone negatively can be insensitive, as it historically stigmatizes mental health issues and can imply irrationality or instability.` + } + else if (targetWord === 'stupid') { + span.innerHTML = `Describing actions or decisions as "stupid" can be demeaning and hurtful, as it implies lack of intelligence or judgment, which can be offensive to individuals or groups.` + } + else { + span.innerHTML = `This word is considered offensive or derogatory due to its association with negative stereotypes about people with disabilities. Using such terms can perpetuate discrimination and harm individuals by devaluing their worth and capabilities.` + } + + + sup.appendChild(img) + sup.appendChild(span) + + element.append(sup) + let sups = element.children[0] + let spans = element.children[0].children[1] + const svgs = element.children[0].children[0]; + svgs.addEventListener('mouseover', function () { + sups.children[1].style.display = "inline-block" + }); + + svgs.addEventListener('mouseout', function () { + sups.children[1].style.display = "none" + }); + }) + }) +} + + +let targetWords = ["stupid", "crazy", "Crazy", "mad"] +let uliStore = [] +getAllTextNodes(document.body, uliStore) +abc = locateSlur(uliStore, targetWords) +console.log("uliStore", abc) +addMetaData(targetWords) diff --git a/browser-extension/prototype/info.png b/browser-extension/prototype/info.png new file mode 100644 index 0000000000000000000000000000000000000000..311011c6321e34669f055e688e9adb713e680d5e GIT binary patch literal 13149 zcmX|o2|U!@_y3GB#0-k;OZGCB$eKbWGPHQcHugbytfB16%qSI!#+t2dlo{J3gwSWQ z^&p4!;_zrik{x-Y#4Y#-$O41)ZP)Vxo{hM>lt%30E@QwuP
znjYzPIoA*FJ1Y*6
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/browser-extension/prototype/index2.js b/browser-extension/prototype/index2.js
new file mode 100644
index 00000000..bbd6c27a
--- /dev/null
+++ b/browser-extension/prototype/index2.js
@@ -0,0 +1,141 @@
+function checkFalseTextNode(text, actualLengthOfText) {
+ let totalNewlineAndWhitespaces = 0;
+ for (let i = 0; i < text.length; i++) {
+ if (text[i] === "\n" || text[i] === " " || text[i] === "\t") { // I think not only \n and " " , if a textNode is comprised of any escape characters and whitespace, it should be a false textNode
+ totalNewlineAndWhitespaces++;
+ }
+ }
+ return totalNewlineAndWhitespaces === actualLengthOfText;
+}
+
+// Function to recursively get all text nodes under a given node
+function getAllTextNodes(node, uliStore) {
+ if (node.nodeType === 3) { // Text node
+ if (!checkFalseTextNode(node.data, node.length)) {
+ uliStore.push({ node: node, parent: node.parentNode });
+ }
+ } else {
+ let children = Array.from(node.childNodes);
+ children.forEach(child => getAllTextNodes(child, uliStore));
+ }
+}
+
+
+function findPositions(word, text) {
+ let positions = {};
+
+ let len = word.length
+ let loc = []
+ let index = text.toString().indexOf(word);
+ while (index !== -1) {
+ let obj = {};
+ loc.push([index, index + len]);
+ index = text.toString().indexOf(word, index + 1);
+ }
+
+
+ if (loc.length !== 0) {
+ positions.slurText = word
+ positions.slurLocation = loc;
+ }
+ return positions;
+}
+
+
+function locateSlur(uliStore, targetWords) {
+ let n = uliStore.length;
+
+ for (let i = 0; i < n; i++) {
+ let store = uliStore[i]; //This will contain the textNode
+ let parentNode = store.parent
+ let text = store.node.textContent
+ //We have to look into this store for all the slurWords
+ let slurs = [];
+
+ targetWords.forEach(targetWord => {
+ let slurWord = targetWord;
+ let pos = findPositions(slurWord, text);
+ if (Object.keys(pos).length !== 0) {
+ slurs.push(pos)
+ }
+
+ if (parentNode.innerHTML.includes(targetWord)) {
+ const className = `icon-container-${targetWord}`;
+ const parts = parentNode.innerHTML.split(targetWord);
+ const replacedHTML = parts.join(`${targetWord}*`);
+ parentNode.innerHTML = replacedHTML
+ }
+ })
+ uliStore[i].slurs = slurs;
+ }
+ return uliStore; //This will return the final uliStore (after appending slurs)
+}
+
+
+function addMetaData(targetWords) {
+ targetWords.forEach(targetWord => {
+ const className = `icon-container-${targetWord}`
+ const elements = Array.from(document.querySelectorAll(`.${className}`))
+ elements.forEach(element => {
+
+ let sup = document.createElement("sup");
+
+ let img = document.createElement("img");
+ img.style.height = "2%"
+ img.style.width = "2%"
+ img.style.cursor = "pointer"
+ // img.src = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png"
+ img.src = "./info.png"
+ img.alt = "altText"
+
+ let span = document.createElement("span")
+ span.style.display = "none"
+ span.style.position = "absolute"
+ span.style.backgroundColor = "antiquewhite"
+ span.style.border = "1px solid black"
+ span.style.borderRadius = "12px"
+ span.style.padding = "2px 6px"
+ span.style.width = "12rem"
+ span.style.textAlign = "justify"
+ span.innerHTML = `This is ${targetWord}`
+
+
+ if (targetWord === "crazy") {
+ span.innerHTML = `Referring to behaviors or situations as "crazy" can perpetuate stereotypes about mental health and may be hurtful to those with mental health conditions.`
+ }
+ else if (targetWord === "mad") {
+ span.innerHTML = `Using "mad" to describe someone negatively can be insensitive, as it historically stigmatizes mental health issues and can imply irrationality or instability.`
+ }
+ else if (targetWord === 'stupid') {
+ span.innerHTML = `Describing actions or decisions as "stupid" can be demeaning and hurtful, as it implies lack of intelligence or judgment, which can be offensive to individuals or groups.`
+ }
+ else {
+ span.innerHTML = `This word is considered offensive or derogatory due to its association with negative stereotypes about people with disabilities. Using such terms can perpetuate discrimination and harm individuals by devaluing their worth and capabilities.`
+ }
+
+
+ sup.appendChild(img)
+ sup.appendChild(span)
+
+ element.append(sup)
+ let sups = element.children[0]
+ let spans = element.children[0].children[1]
+ const svgs = element.children[0].children[0];
+ svgs.addEventListener('mouseover', function () {
+ sups.children[1].style.display = "inline-block"
+ });
+
+ svgs.addEventListener('mouseout', function () {
+ sups.children[1].style.display = "none"
+ });
+ })
+ })
+}
+
+
+let targetWords = ["stupid", "crazy", "Crazy", "mad"]
+let uliStore = []
+getAllTextNodes(document.body, uliStore)
+abc = locateSlur(uliStore, targetWords)
+console.log("uliStore", abc)
+// addMetaData(targetWords)
diff --git a/browser-extension/prototype/index3.html b/browser-extension/prototype/index3.html
new file mode 100644
index 00000000..06c2df62
--- /dev/null
+++ b/browser-extension/prototype/index3.html
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/browser-extension/prototype/index3.js b/browser-extension/prototype/index3.js
new file mode 100644
index 00000000..5e49a7da
--- /dev/null
+++ b/browser-extension/prototype/index3.js
@@ -0,0 +1,171 @@
+function checkFalseTextNode(text, actualLengthOfText) {
+ let totalNewlineAndWhitespaces = 0;
+ for (let i = 0; i < text.length; i++) {
+ if (text[i] === "\n" || text[i] === " " || text[i] === "\t") { // I think not only \n and " " , if a textNode is comprised of any escape characters and whitespace, it should be a false textNode
+ totalNewlineAndWhitespaces++;
+ }
+ }
+ return totalNewlineAndWhitespaces === actualLengthOfText;
+}
+
+// Function to recursively get all text nodes under a given node
+function getAllTextNodes(node, uliStore) {
+ if (node.nodeType === 3) { // Text node
+ if (!checkFalseTextNode(node.data, node.length)) {
+ uliStore.push({ node: node, parent: node.parentNode });
+ }
+ } else {
+ let children = Array.from(node.childNodes);
+ children.forEach(child => getAllTextNodes(child, uliStore));
+ }
+}
+
+
+function findPositions(word, text) {
+ let positions = {};
+
+ let len = word.length
+ let loc = []
+ let index = text.toString().indexOf(word);
+ while (index !== -1) {
+ let obj = {};
+ loc.push([index, index + len]);
+ index = text.toString().indexOf(word, index + 1);
+ }
+
+
+ if (loc.length !== 0) {
+ positions.slurText = word
+ positions.slurLocation = loc;
+ }
+ return positions;
+}
+
+
+function locateSlur(uliStore, targetWords) {
+ let n = uliStore.length;
+
+ for (let i = 0; i < n; i++) {
+ let store = uliStore[i]; //This will contain the textNode
+ let parentNode = store.parent
+ let textnode = store.node
+ let text = store.node.textContent
+ let tempParent = document.createElement("span"); //I chose span over p because span is an inline element and p is a block element, injecting block
+ //element would cause a lot of change in the stylings and can damage the overall webpage to a greater extent
+ tempParent.textContent = text ;
+ //We have to look into this store for all the slurWords
+ let slurs = [];
+
+ targetWords.forEach(targetWord => {
+ let slurWord = targetWord;
+ let pos = findPositions(slurWord, text);
+ if (Object.keys(pos).length !== 0) {
+ slurs.push(pos)
+ }
+
+ if (tempParent.innerHTML.includes(targetWord)) {
+ const className = `icon-container-${targetWord}`;
+ const parts = tempParent.innerHTML.split(targetWord);
+ const replacedHTML = parts.join(`${targetWord}*`);
+ tempParent.innerHTML = replacedHTML
+ }
+ })
+
+
+
+ // for(let i = 0 ; i < )
+ // console.log("tempParent " , tempParent)
+ uliStore[i].nodeToParent = tempParent
+ uliStore[i].slurs = slurs;
+
+
+
+ parentNode.childNodes.forEach((node) => {
+ // Check if the node is a text node
+ // if (node.nodeType === Node.TEXT_NODE) {
+ // // Check if the text node contains the target text
+ // if (node.textContent.trim() === "Replace this text node") {
+ // // Create a new element to replace the text node
+ // let newElement = document.createElement('span');
+ // newElement.textContent = "This is the new element";
+
+ // // Replace the text node with the new element
+ // container.replaceChild(newElement, node);
+ // }
+ // }
+ if(node === textnode){
+ parentNode.replaceChild(tempParent , node)
+ }
+ });
+ }
+ return uliStore; //This will return the final uliStore (after appending slurs)
+}
+
+
+function addMetaData(targetWords) {
+ targetWords.forEach(targetWord => {
+ const className = `icon-container-${targetWord}`
+ const elements = Array.from(document.querySelectorAll(`.${className}`))
+ elements.forEach(element => {
+
+ let sup = document.createElement("sup");
+
+ let img = document.createElement("img");
+ img.style.height = "2%"
+ img.style.width = "2%"
+ img.style.cursor = "pointer"
+ // img.src = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png"
+ img.src = "./info.png"
+ img.alt = "altText"
+
+ let span = document.createElement("span")
+ span.style.display = "none"
+ span.style.position = "absolute"
+ span.style.backgroundColor = "antiquewhite"
+ span.style.border = "1px solid black"
+ span.style.borderRadius = "12px"
+ span.style.padding = "2px 6px"
+ span.style.width = "12rem"
+ span.style.textAlign = "justify"
+ span.innerHTML = `This is ${targetWord}`
+
+
+ if (targetWord === "crazy") {
+ span.innerHTML = `Referring to behaviors or situations as "crazy" can perpetuate stereotypes about mental health and may be hurtful to those with mental health conditions.`
+ }
+ else if (targetWord === "mad") {
+ span.innerHTML = `Using "mad" to describe someone negatively can be insensitive, as it historically stigmatizes mental health issues and can imply irrationality or instability.`
+ }
+ else if (targetWord === 'stupid') {
+ span.innerHTML = `Describing actions or decisions as "stupid" can be demeaning and hurtful, as it implies lack of intelligence or judgment, which can be offensive to individuals or groups.`
+ }
+ else {
+ span.innerHTML = `This word is considered offensive or derogatory due to its association with negative stereotypes about people with disabilities. Using such terms can perpetuate discrimination and harm individuals by devaluing their worth and capabilities.`
+ }
+
+
+ sup.appendChild(img)
+ sup.appendChild(span)
+
+ element.append(sup)
+ let sups = element.children[0]
+ let spans = element.children[0].children[1]
+ const svgs = element.children[0].children[0];
+ svgs.addEventListener('mouseover', function () {
+ sups.children[1].style.display = "inline-block"
+ });
+
+ svgs.addEventListener('mouseout', function () {
+ sups.children[1].style.display = "none"
+ });
+ })
+ })
+}
+
+
+let targetWords = ["stupid", "crazy", "Crazy", "mad"]
+let uliStore = []
+getAllTextNodes(document.body, uliStore)
+abc = locateSlur(uliStore, targetWords)
+console.log("uliStore", abc)
+// addMetaData(targetWords)
From 5eb7d3b529c239f7514b87ec06be02f8346b0493 Mon Sep 17 00:00:00 2001
From: hardik-pratap-singh <21bcs090@iiitdmj.ac.in>
Date: Thu, 15 Aug 2024 12:32:28 +0530
Subject: [PATCH 03/19] metadata ver 1.0.0
---
browser-extension/prototype/index3.js | 43 +++++++++------------------
browser-extension/prototype/new.js | 28 +++++++++++++++++
2 files changed, 42 insertions(+), 29 deletions(-)
create mode 100644 browser-extension/prototype/new.js
diff --git a/browser-extension/prototype/index3.js b/browser-extension/prototype/index3.js
index 5e49a7da..c4273773 100644
--- a/browser-extension/prototype/index3.js
+++ b/browser-extension/prototype/index3.js
@@ -48,11 +48,11 @@ function locateSlur(uliStore, targetWords) {
for (let i = 0; i < n; i++) {
let store = uliStore[i]; //This will contain the textNode
let parentNode = store.parent
- let textnode = store.node
+ let textnode = store.node
let text = store.node.textContent
let tempParent = document.createElement("span"); //I chose span over p because span is an inline element and p is a block element, injecting block
//element would cause a lot of change in the stylings and can damage the overall webpage to a greater extent
- tempParent.textContent = text ;
+ tempParent.textContent = text;
//We have to look into this store for all the slurWords
let slurs = [];
@@ -66,37 +66,21 @@ function locateSlur(uliStore, targetWords) {
if (tempParent.innerHTML.includes(targetWord)) {
const className = `icon-container-${targetWord}`;
const parts = tempParent.innerHTML.split(targetWord);
- const replacedHTML = parts.join(`${targetWord}*`);
+ const replacedHTML = parts.join(`${targetWord}`);
tempParent.innerHTML = replacedHTML
}
})
-
-
-
// for(let i = 0 ; i < )
// console.log("tempParent " , tempParent)
uliStore[i].nodeToParent = tempParent
uliStore[i].slurs = slurs;
-
parentNode.childNodes.forEach((node) => {
- // Check if the node is a text node
- // if (node.nodeType === Node.TEXT_NODE) {
- // // Check if the text node contains the target text
- // if (node.textContent.trim() === "Replace this text node") {
- // // Create a new element to replace the text node
- // let newElement = document.createElement('span');
- // newElement.textContent = "This is the new element";
-
- // // Replace the text node with the new element
- // container.replaceChild(newElement, node);
- // }
- // }
- if(node === textnode){
- parentNode.replaceChild(tempParent , node)
+ if (node === textnode) {
+ parentNode.replaceChild(tempParent, node)
}
- });
+ });
}
return uliStore; //This will return the final uliStore (after appending slurs)
}
@@ -111,11 +95,11 @@ function addMetaData(targetWords) {
let sup = document.createElement("sup");
let img = document.createElement("img");
- img.style.height = "2%"
- img.style.width = "2%"
+ img.style.height = "3%"
+ img.style.width = "3%"
img.style.cursor = "pointer"
- // img.src = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png"
- img.src = "./info.png"
+ img.src = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png"
+ // img.src = "./info.png"
img.alt = "altText"
let span = document.createElement("span")
@@ -162,10 +146,11 @@ function addMetaData(targetWords) {
})
}
-
-let targetWords = ["stupid", "crazy", "Crazy", "mad"]
+// let imgSrc = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png"
+// let imgAlt = "slur word desc"
+let targetWords = ["stupid", "crazy", "Crazy", "mad" , "Mad" , "MAD"]
let uliStore = []
getAllTextNodes(document.body, uliStore)
abc = locateSlur(uliStore, targetWords)
console.log("uliStore", abc)
-// addMetaData(targetWords)
+addMetaData(targetWords)
diff --git a/browser-extension/prototype/new.js b/browser-extension/prototype/new.js
new file mode 100644
index 00000000..b57a9d91
--- /dev/null
+++ b/browser-extension/prototype/new.js
@@ -0,0 +1,28 @@
+const iconSrc = './info.svg';
+const iconAlt = 'Icon description';
+const targetWords = ['crazy', 'stupid', 'mad']; // Replace with your list of target words
+
+// Find all elements that contain any of the target words
+document.querySelectorAll('*').forEach(element => {
+ targetWords.forEach(targetWord => {
+ if (element.innerHTML.includes(targetWord)) {
+ const className = `icon-container-${targetWord}`;
+ // Split the innerHTML into parts to handle replacements
+ const parts = element.innerHTML.split(targetWord);
+ const replacedHTML = parts.join(`${targetWord}`);
+
+ // Update the element with the replaced content
+ element.innerHTML = replacedHTML;
+
+ // Add icon after each occurrence of the target word
+ const iconContainers = element.querySelectorAll(`.${className}`);
+ iconContainers.forEach(container => {
+ const icon = document.createElement('img');
+ icon.src = iconSrc;
+ icon.alt = iconAlt;
+ container.appendChild(icon);
+
+ });
+ }
+ });
+});
\ No newline at end of file
From 8b6085ff02ae1a6cb8a6ec718ea1dc24f64d2e2c Mon Sep 17 00:00:00 2001
From: hardik-pratap-singh <21bcs090@iiitdmj.ac.in>
Date: Thu, 15 Aug 2024 13:31:40 +0530
Subject: [PATCH 04/19] removed O(n) complexity
---
browser-extension/prototype/index3.js | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/browser-extension/prototype/index3.js b/browser-extension/prototype/index3.js
index c4273773..42f5dab7 100644
--- a/browser-extension/prototype/index3.js
+++ b/browser-extension/prototype/index3.js
@@ -76,11 +76,16 @@ function locateSlur(uliStore, targetWords) {
uliStore[i].slurs = slurs;
- parentNode.childNodes.forEach((node) => {
- if (node === textnode) {
- parentNode.replaceChild(tempParent, node)
- }
- });
+ //Additional O(N) complexity
+ // parentNode.childNodes.forEach((node) => {
+ // if (node === textnode) {
+ // parentNode.replaceChild(tempParent, node)
+ // }
+ // });
+
+ //O(1) complexity
+ parentNode.replaceChild(tempParent, node)
+
}
return uliStore; //This will return the final uliStore (after appending slurs)
}
@@ -146,8 +151,7 @@ function addMetaData(targetWords) {
})
}
-// let imgSrc = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png"
-// let imgAlt = "slur word desc"
+
let targetWords = ["stupid", "crazy", "Crazy", "mad" , "Mad" , "MAD"]
let uliStore = []
getAllTextNodes(document.body, uliStore)
From 9e41b8240c948c588f2efc5a6969c47cbaf6e443 Mon Sep 17 00:00:00 2001
From: hardik-pratap-singh <21bcs090@iiitdmj.ac.in>
Date: Fri, 16 Aug 2024 10:26:49 +0530
Subject: [PATCH 05/19] integration work started
---
browser-extension/plugin/manifest.json | 24 ++-
.../plugin/src/content-script.js | 10 +-
browser-extension/plugin/src/slur-metadata.js | 163 +++++++++++++++
.../plugin/src/transform-general.js | 192 +++++++++++++-----
browser-extension/prototype/index3.js | 2 +-
5 files changed, 328 insertions(+), 63 deletions(-)
create mode 100644 browser-extension/plugin/src/slur-metadata.js
diff --git a/browser-extension/plugin/manifest.json b/browser-extension/plugin/manifest.json
index 0f72e6ec..1f13f924 100644
--- a/browser-extension/plugin/manifest.json
+++ b/browser-extension/plugin/manifest.json
@@ -5,22 +5,34 @@
"version": "0.1.16",
"author": "tattlemade|cis",
"content_security_policy": {
- "extension_pages": "default-src 'none'; connect-src https://ogbv-plugin.tattle.co.in/ https://uli-media.tattle.co.in/; font-src https://fonts.gstatic.com; object-src 'none'; script-src 'self'; style-src https://fonts.googleapis.com 'self' 'unsafe-inline'; img-src https://uli-media.tattle.co.in/; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; report-uri 'none';"
+ "extension_pages": "default-src 'none'; connect-src http://localhost:3000 ws://localhost; font-src https://fonts.gstatic.com; object-src 'none'; script-src 'self'; style-src https://fonts.googleapis.com 'self' 'unsafe-inline'; img-src https://uli-media.tattle.co.in/; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; report-uri 'none';"
},
- "permissions": ["storage", "contextMenus"],
- "host_permissions": ["https://ogbv-plugin.tattle.co.in/*"],
+ "permissions": [
+ "storage",
+ "contextMenus"
+ ],
+ "host_permissions": [
+ "https://ogbv-plugin.tattle.co.in/*"
+ ],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
- "matches": ["
- Lorem ipsum dolor sit amet consectetur crazy adipisicing elit. Quaerat alias iste quo exercitationem stupid - nesciunt ea? -
- -- - - - Lorem ipsum, dolor sit amet stupid mad adipisicing elit. Magni minima adipisci architecto. -
-- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa possimus quisquam temporibus - reprehenderit nesciunt dignissimos sunt ipsum, nostrum modi? Iusto libero sed alias! -
- crazy -- Lorem ipsum dolor crazy Lorem, ipsum dolor. sit stupid amet consectetur adipisicing elit. Aut architecto illum dolorum - mad. -
- - - -diff --git a/browser-extension/prototype/index4.js b/browser-extension/prototype/index4.js new file mode 100644 index 00000000..9c88a883 --- /dev/null +++ b/browser-extension/prototype/index4.js @@ -0,0 +1,212 @@ +let slurList = + 'जिहादी|छक्का|छिनाल|रंडी|रण्डी|रांड|रंडीखाना|रण्डी रोना|लुल्ली|गांड|कुतिया|कुत्ती|बत्तमीज़|कुल्टा|हरामजादी|साली|चुदाई|ma ki chui|मा के भोसड़े|भोस्डीके|भोछडी वाला |लोड़ू|बहन चोद|मादरचोद|लानती|छुतीये|चूतिये |चूत|लौड़ा|लौड़े|चरित्रहीन |लिब्राण्डू|नंगी पुंगी|पागल औरत |बाज़ारू औरत|बलात्कार|बदसूरत|मुजरा|जाहिल औरत|औरत-ए-जाहिल|भोसड़ीwala|चंडाल चौकड़ी|म्लेच्छा|सूअर|सूअर की औलाद|दोगली|🏹🏹|पनौती|हरामी|गधी|बुरखा धत्त|बुल्ली |कलमुंही |पिछवाड़ा|काम वाली बाई|पैर की जूती|गंदी नाली|हगना|सुल्ली|हिज़रापंती|naachne waali|तवाइफ़|सौ टका टंच माल|किन्नर|गद्दार|चमचा|चमची|आतंकवादी|मुलिया|Katwa|चाटुकार|बहन की लोड़ी|चुस्लिम|चुस्लामि|चुसल्मान|चूस|भीमटा|भीमटी|बैल बुद्धि|हलाला|भद्दी औरत|भांड औरत|भाड़े का टट्टू|दो कौड़ी की औरत|घटिया औरत|बेहूदा औरत|चालू औरत|झूठी औरत|मर क्यों नहीं जाती|नल्ली|भूतनी के|चूत के बाल|मादरजात|भड़वा|चूची|टट्टी|गटर पैदाइश|मुँह मैं ले|मूत|नाजायज़|कटा लुंड|काला टेंट|जूता खायेगी|बुरखे वाली|काली कलूटी|काले तवे|मोटी भैंस|देहातन|देहाती औरत|गणिका|हबशी|ओला हु उबर|ABLANARI|AblaNari|ablanari|chakka|jihidis|jihadi|Jihidi|zehadi|jehadan|jihadinon|Chakko|chakki|chaka|Chinal|Randi|ramdi|Randie|randya|randikhana|randi ke beej|Lulli|Gasti|Meetha|Halwa|Gud|Gaandu|Gaand|Gandiaal|lodu|kutiya|kutti|Chudail|Badchalan|Battameez|kulta|haramjadi|dyan|saali|sali|chod|chodu bhagat|chudai|chooda|chuda|Bhdsk|2BHK|Bhosi ke|bsdk|bhonsdi ke|bhosad|bhosdiwale|maa ka bhosra|Lodu|bhenchod|Madarchod|Maderchod|mcp|mc|Lanti|chutiye|chutiya|Chut|hutiye|chutie|chutia|chut ke dhakkan|chut marli|chutan|Lavde|Gandu|Rakhail|librandu|chal phut|nangi poongi|pagal aurat|bazaru|bazari aurat|ola hi uber hai|balatkar|Ugly|Mujra|mujra|jaahil aurat|Mulli|hilana|hilaogi|Mlechcha|Suar|suar ki aulad|doghli|Panauti|panooti|harami|gadhi|रनडwa|🅱️ulli|kalmuhi|pichwada|jhadu|bai|kaam wali bai|pair ki jutti|naali|hagna|tukde tukde gang|Sulli|नाचने वाली|Tawaif|sau taka tunch maal|Skirt waali bai|Dhimmi hood|Dhimmihood|izzlam|gaddar|chamcha|chamchi|aatankwadi|Mulliya|Uncut|chatukar|Bahan Ke loudi|Kachra|Chuslim|chuslami|Chusalmans|chus|Bhimta|bheem-meem walas|bail budhi|Budhdhi|हलाला|bhadi aurat|bhanndh aurat|bhadi ka tattu|2 Kaudi ki aurat|Gatiya|Ghatiya aurat|behuda aurat|chalu aurat|jhuti aurat|Kaali aurat|Kaali bhaand|marr kyun nahi jaati|nalli|dimaag se paidal|bhootni|bhootni ke|choot ke baal|madarjaat|bhadva|bhadvi|bhandve|chuchi|tatti|maa ka boba chusu|mooh|munh mein le|mutth|najayaz paidaish|najayaz aulaad|Gutter ki paidaish|kata Lund|kala tent|joota khayegi|burkhe waali|ladki kahin ka|victim card|Aurat card|kali kalutti|Kale tawe|naali saaf kar|moti bhains|sukkhi haddi|Pataka|choodiyan pehen lo|abba ka naam|Ganika|gaand phadna|chewtypa|atrocuty_act|RandiKutiya|sulli|Rice bags|ola u uber|lovejihad|dull-it|toxic aunty|Presstitutes|libtard|bimbo|slims|Black Pepper|faggot|Sissy|whore|chrislamocommies|piddilover|Dynast Sycophants|Deshdrohi Chinese|Pak agents|Chinese Corona|Chinks|chinky|Feminazi|Mulli|halala|Half M|Scumreds|scumbags|burnol|anti national tukde|pheminist|dented-painted|Muzlim|Buzlim|Izzlam|pissfull|Simp|Bitch| Ms |sekoolar|sickular|sc0undrel|Characterless woman|Drama Queen|Ferrorists|Cunt|Slut|pussy|ugly|stupid|promiscuous|crazy|fat|fag|homo|hoe|motherfucker|sisterfucker|bastard|bint|dyke|gash|muslimette|muttah|scag|gender nigger|assfucker|boobs|boobies|Melons|lesbain|moslem|nasty|redlight|nymph|piss|pimp|poop|pube|puke|retarded|slave|sissy|ola uh uber|pu55i|pu55y|mothafuck|mothafucka|mothafuckaz|mothafucked|mothafucker|mothafuckin|mothafucking |mothafuckings|motherfuck|motherfucked|motherfucker|motherfuckin|motherfucking|motherfuckings|lesbain|lesbayn|lesbian|lesbin|lesbo|nastyslut|nastywhore|nastybitch|nastyho|Koodhi|pottai|Potta Alith|Aththai|athai|loosu|fuck|cunt'; + + + + + +function checkFalseTextNode(text, actualLengthOfText) { + let totalNewlineAndWhitespaces = 0; + for (let i = 0; i < text.length; i++) { + if (text[i] === "\n" || text[i] === " " || text[i] === "\t") { + // I think not only \n and " " , if a textNode is comprised of any escape characters and whitespace, it should be a false textNode + totalNewlineAndWhitespaces++; + } + } + return totalNewlineAndWhitespaces === actualLengthOfText; +} + + +// Function to recursively get all text nodes under a given node +function getAllTextNodes(node, uliStore) { + if (node.nodeType === 3) { // Text node + if (!checkFalseTextNode(node.data, node.length)) { + uliStore.push({ node: node, parent: node.parentNode }); + } + } else { + let children = Array.from(node.childNodes); + children.forEach(child => getAllTextNodes(child, uliStore)); + } +} + + + +/* getAllTextNodes() ENDS HERE */ + + +/* locateSlur() STARTS HERE */ + +function findPositions(word, text) { + let positions = {}; + + let len = word.length + let loc = [] + let index = text.toString().indexOf(word); + while (index !== -1) { + let obj = {}; + loc.push([index, index + len]); + index = text.toString().indexOf(word, index + 1); + } + + + if (loc.length !== 0) { + positions.slurText = word + positions.slurLocation = loc; + } + return positions; +} + + + +function locateSlur(uliStore, targetWords) { + let n = uliStore.length; + + for (let i = 0; i < n; i++) { + let store = uliStore[i]; //This will contain the textNode + let parentNode = store.parent + let textnode = store.node + let text = store.node.textContent + let tempParent = document.createElement("span"); //I chose span over p because span is an inline element and p is a block element, injecting block + //element would cause a lot of change in the stylings and can damage the overall webpage to a greater extent + tempParent.textContent = text; + + let slurs = []; + let slurPresentInTempParent = false; + targetWords.forEach(targetWord => { + let slurWord = targetWord; + let pos = findPositions(slurWord, text); + if (Object.keys(pos).length !== 0) { + slurs.push(pos) + } + + if (tempParent.innerHTML.includes(targetWord)) { + const className = `icon-container-${targetWord}`; + const parts = tempParent.innerHTML.split(targetWord); + const replacedHTML = parts.join(`${targetWord}`); + tempParent.innerHTML = replacedHTML + slurPresentInTempParent = true; + } + }) + // for(let i = 0 ; i < ) + // console.log("tempParent " , tempParent) + uliStore[i].nodeToParent = tempParent + uliStore[i].slurs = slurs; + + //O(1) complexity + if (slurPresentInTempParent) { + // parentNode.replaceChild(tempParent, textnode) + textnode.replaceWith(tempParent) + // textnode.replaceWith(createTextNode(tempParent.innerHTML)) + + } + + } + return uliStore; +} + + +/* locateSlur() ENDS HERE */ + + + + +/* addMetaData() STARTS HERE */ + +function addMetaData(targetWords) { + targetWords.forEach(targetWord => { + const className = `icon-container-${targetWord}` + console.log("className " , className) + const elements = Array.from(document.querySelectorAll(`.${className}`)) + elements.forEach(element => { + + let sup = document.createElement("sup"); + + let img = document.createElement("img"); + img.style.height = "2%" + img.style.width = "2%" + img.style.cursor = "pointer" + img.src = "https://upload.wikimedia.org/wikipedia/commons/4/43/Minimalist_info_Icon.png" + // img.src = "./info.png" + img.alt = "altText" + + let span = document.createElement("span") + // span.style.all = "unset" + span.style.display = "none" + span.style.position = "absolute" + span.style.backgroundColor = "antiquewhite" + span.style.border = "1px solid black" + span.style.borderRadius = "12px" + span.style.padding = "2px 6px" + // span.style.width = "12rem" + span.style.textAlign = "justify" + span.style.fontWeight = "lighter" + span.style.color = "black" + span.style.zIndex = "1000000000"; // This ensures it appears above other elements + span.style.fontSize = "14px" + span.style.textDecoration = "none" + span.style.fontStyle = "normal" + // span.style.height = "fit-content" + span.innerHTML = `This is ${targetWord}` + + // span.style.display = "none"; + // span.style.position = "absolute"; + // span.style.backgroundColor = "antiquewhite !important"; + // span.style.border = "1px solid black !important"; + // span.style.borderRadius = "12px !important"; + // span.style.padding = "2px 6px !important"; + // span.style.width = "12rem !important"; + // span.style.textAlign = "justify !important"; + // span.innerHTML = `This is ${targetWord}`; + + + + + if (targetWord.toLowerCase() === "crazy") { + span.innerHTML = `It can perpetuate stereotypes about mental health and may be hurtful to those with mental health conditions.` + } + else if (targetWord.toLowerCase() === "mad") { + span.innerHTML = `Using "mad" to describe someone negatively can be insensitive.` + } + else if (targetWord.toLowerCase() === 'stupid') { + span.innerHTML = `Describing actions or decisions as "stupid" can be demeaning and hurtful.` + } + else { + span.innerHTML = `This word is considered offensive.` + } + + + sup.appendChild(img) + sup.appendChild(span) + + element.append(sup) + let sups = element.children[0] + let spans = element.children[0].children[1] + const svgs = element.children[0].children[0]; + svgs.addEventListener('mouseover', function () { + sups.children[1].style.display = "inline-block" + // sups.children[1].style.display = "block" + }); + + svgs.addEventListener('mouseout', function () { + sups.children[1].style.display = "none" + }); + }) + }) +} + + + +// let targetWords = ["stupid", "crazy", "Crazy", "mad" , "Mad" , "MAD"] +let targetWords = slurList.split("|"); +targetWords = targetWords.filter((x) => x.split(" ").length == 1) ; +// let removeHash = targetWords.filter((x) => x.includes("#")===false); + +console.log(targetWords) +// console.log(oneWordTargetWords) +// console.log(targetWords) ; +let uliStore = [] +getAllTextNodes(document.body, uliStore) +abc = locateSlur(uliStore, targetWords) +// console.log("uliStore", abc) +addMetaData(targetWords) + From 9f842866be7bd4c2a4efef0dae9e5aa5106700e9 Mon Sep 17 00:00:00 2001 From: hardik-pratap-singh <21bcs090@iiitdmj.ac.in> Date: Fri, 30 Aug 2024 09:54:02 +0530 Subject: [PATCH 09/19] updated manifest.json && deleted prototype --- browser-extension/plugin/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser-extension/plugin/manifest.json b/browser-extension/plugin/manifest.json index 1f13f924..0cd36a03 100644 --- a/browser-extension/plugin/manifest.json +++ b/browser-extension/plugin/manifest.json @@ -5,7 +5,7 @@ "version": "0.1.16", "author": "tattlemade|cis", "content_security_policy": { - "extension_pages": "default-src 'none'; connect-src http://localhost:3000 ws://localhost; font-src https://fonts.gstatic.com; object-src 'none'; script-src 'self'; style-src https://fonts.googleapis.com 'self' 'unsafe-inline'; img-src https://uli-media.tattle.co.in/; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; report-uri 'none';" + "extension_pages": "default-src 'none'; connect-src https://ogbv-plugin.tattle.co.in/ https://uli-media.tattle.co.in/; font-src https://fonts.gstatic.com; object-src 'none'; script-src 'self'; style-src https://fonts.googleapis.com 'self' 'unsafe-inline'; img-src https://uli-media.tattle.co.in/; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; report-uri 'none';" }, "permissions": [ "storage", From 463bcf592363b1027212938826f98a77e2329ed6 Mon Sep 17 00:00:00 2001 From: hardik-pratap-singh <21bcs090@iiitdmj.ac.in> Date: Fri, 30 Aug 2024 10:07:34 +0530 Subject: [PATCH 10/19] updated manifest.json && deleted prototype --- browser-extension/prototype/index.html | 57 ------- browser-extension/prototype/index.js | 141 ---------------- browser-extension/prototype/index2.html | 39 ----- browser-extension/prototype/index2.js | 141 ---------------- browser-extension/prototype/index3.html | 51 ------ browser-extension/prototype/index3.js | 160 ------------------ browser-extension/prototype/index4.js | 212 ------------------------ browser-extension/prototype/info.png | Bin 13149 -> 0 bytes browser-extension/prototype/new.js | 28 ---- 9 files changed, 829 deletions(-) delete mode 100644 browser-extension/prototype/index.html delete mode 100644 browser-extension/prototype/index.js delete mode 100644 browser-extension/prototype/index2.html delete mode 100644 browser-extension/prototype/index2.js delete mode 100644 browser-extension/prototype/index3.html delete mode 100644 browser-extension/prototype/index3.js delete mode 100644 browser-extension/prototype/index4.js delete mode 100644 browser-extension/prototype/info.png delete mode 100644 browser-extension/prototype/new.js diff --git a/browser-extension/prototype/index.html b/browser-extension/prototype/index.html deleted file mode 100644 index e5b08797..00000000 --- a/browser-extension/prototype/index.html +++ /dev/null @@ -1,57 +0,0 @@ - - - -
- - -
- - -
-