From 1067024c0b85d1348ff44412209e884556a986cf Mon Sep 17 00:00:00 2001 From: hardik-pratap-singh <21bcs090@iiitdmj.ac.in> Date: Sun, 8 Sep 2024 16:36:10 +0530 Subject: [PATCH] integrated slur_metadata.json --- .../api-server/assets/slur_metadata.json | 287 +++++++++++------- .../plugin/src/transform-general.js | 86 ++++-- .../src/ui-components/pages/Preferences.jsx | 4 +- 3 files changed, 231 insertions(+), 146 deletions(-) diff --git a/browser-extension/api-server/assets/slur_metadata.json b/browser-extension/api-server/assets/slur_metadata.json index a140d4c4..de3b386a 100644 --- a/browser-extension/api-server/assets/slur_metadata.json +++ b/browser-extension/api-server/assets/slur_metadata.json @@ -1,112 +1,177 @@ [ - { - "fuck": { - "Level of Severity": "Low", - "Casual": "Yes", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "a casual slur used to convey dislike, disrespect or lack of care. Sometimes also used aggresively or intensely", - "Categories": ["sexualized"] - } - }, - { - "cunt": { - "Level of Severity": "High", - "Casual": "Yes", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "slang for women's genetalia", - "Categories": ["sexualized"] - } - }, - { - "slut": { - "Level of Severity": "High", - "Casual": "No", - "Appropriated": "Yes", - "If, Appropriated, Is it by Community or Others?": "Community", - "What Makes it Problematic?": "", - "Categories": ["gendered", "sexualized", "body shaming"] - } - }, - { - "whore": { - "Level of Severity": "Low", - "Casual": "Yes", - "Appropriated": "Yes", - "If, Appropriated, Is it by Community or Others?": "Community", - "What Makes it Problematic?": "", - "Categories": ["gendered", "sexualized"] - } - }, - { - "Randi": { - "Level of Severity": "High", - "Casual": "No", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "", - "Categories": ["gendered", "sexualized"] - } - }, - { - "chutiya": { - "Level of Severity": "Low", - "Casual": "Yes", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "", - "Categories": [] - } - }, - { - "bsdk": { - "Level of Severity": "Low", - "Casual": "Yes", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "", - "Categories": ["sexualized"] - } - }, - { - "jihadi": { - "Level of Severity": "High", - "Casual": "No", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "", - "Categories": ["religion", "ethnicity", "political affiliation"] - } - }, - { - "Madarchod": { - "Level of Severity": "Medium", - "Casual": "Yes", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "sexualized act and describing incest, acted on a woman's (sister) body", - "Categories": ["gendered", "sexualized"] - } - }, - { - "bhenchod": { - "Level of Severity": "Medium", - "Casual": "Yes", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "sexualized act and describing incest, acted on a woman's (sister) body", - "Categories": ["gendered", "sexualized"] - } - }, - { - "motherfucker": { - "Level of Severity": "Medium", - "Casual": "Yes", - "Appropriated": "No", - "If, Appropriated, Is it by Community or Others?": "", - "What Makes it Problematic?": "slur based on incest which is a common theme for derogatory words. Incest based slurs imply immorality since it is a deviation from established moral codes. But such insults express action over female bodies", - "Categories": ["sexualized", "gendered"] - } - } -] + { + "fuck": { + "Level of Severity": "Low", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "a casual slur used to convey dislike, disrespect or lack of care. Sometimes also used aggresively or intensely", + "Categories": [ + "sexualized" + ] + } + }, + { + "cunt": { + "Level of Severity": "High", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "slang for women's genetalia", + "Categories": [ + "sexualized" + ] + } + }, + { + "slut": { + "Level of Severity": "High", + "Casual": "No", + "Appropriated": "Yes", + "If, Appropriated, Is it by Community or Others?": "Community", + "What Makes it Problematic?": "", + "Categories": [ + "gendered", + "sexualized", + "body shaming" + ] + } + }, + { + "whore": { + "Level of Severity": "Low", + "Casual": "Yes", + "Appropriated": "Yes", + "If, Appropriated, Is it by Community or Others?": "Community", + "What Makes it Problematic?": "", + "Categories": [ + "gendered", + "sexualized" + ] + } + }, + { + "Randi": { + "Level of Severity": "High", + "Casual": "No", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "", + "Categories": [ + "gendered", + "sexualized" + ] + } + }, + { + "chutiya": { + "Level of Severity": "Low", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "", + "Categories": [] + } + }, + { + "bsdk": { + "Level of Severity": "Low", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "", + "Categories": [ + "sexualized" + ] + } + }, + { + "jihadi": { + "Level of Severity": "High", + "Casual": "No", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "", + "Categories": [ + "religion", + "ethnicity", + "political affiliation" + ] + } + }, + { + "Madarchod": { + "Level of Severity": "Medium", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "sexualized act and describing incest, acted on a woman's (sister) body", + "Categories": [ + "gendered", + "sexualized" + ] + } + }, + { + "behenchod": { + "Level of Severity": "Medium", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "sexualized act and describing incest, acted on a woman's (sister) body", + "Categories": [ + "gendered", + "sexualized" + ] + } + }, + { + "motherfucker": { + "Level of Severity": "Medium", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "slur based on incest which is a common theme for derogatory words. Incest based slurs imply immorality since it is a deviation from established moral codes. But such insults express action over female bodies", + "Categories": [ + "sexualized", + "gendered" + ] + } + }, + { + "idiot": { + "Level of Severity": "Low", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "Used to demean someone's intelligence, often in a casual or aggressive manner.", + "Categories": [ + "intellectual ability" + ] + } + }, + { + "crazy": { + "Level of Severity": "Medium", + "Casual": "Yes", + "Appropriated": "Yes", + "If, Appropriated, Is it by Community or Others?": "Community", + "What Makes it Problematic?": "Historically used to refer to mental health issues, reinforcing negative stereotypes about mental illness.", + "Categories": [ + "mental health" + ] + } + }, + { + "stupid": { + "Level of Severity": "Low", + "Casual": "Yes", + "Appropriated": "No", + "If, Appropriated, Is it by Community or Others?": "", + "What Makes it Problematic?": "Used to insult someone's intelligence or capability, often belittling and dismissive.", + "Categories": [ + "intellectual ability" + ] + } + } +] \ No newline at end of file diff --git a/browser-extension/plugin/src/transform-general.js b/browser-extension/plugin/src/transform-general.js index eaa2de1b..ce8bb6dc 100644 --- a/browser-extension/plugin/src/transform-general.js +++ b/browser-extension/plugin/src/transform-general.js @@ -2,7 +2,7 @@ import { replaceSlur } from './slur-replace'; import { log } from './logger'; import repository from './repository'; const { getPreferenceData } = repository; -import {slurJSON} from '../../api-server/assets/slur_metadata.json' +const jsonData = require('../../api-server/assets/slur_metadata.json') // Traverse dom nodes to find leaf node that are text nodes and process function bft(node) { @@ -52,18 +52,21 @@ function setCaretPosition(element, offset) { const processNewlyAddedNodesGeneral2 = function (firstBody) { + + // const config = { attributes: true, childList: true, subtree: true }; console.log("HEY THERE !!!") - let targetWords = ["Blog", "BLOG", "Choose", "domain", "bad", "BAD", "Bad", "Stupid", "STUPID", "stupid", "crazy", "Crazy", "idiot" , "Idiot" , "IDIOT", "CRAZY","ABLANARI","AblaNari","ablanari","chakka","jihidis","Jihadi","jihadi","Jihidi","zehadi","jehadan","jihadinon","Chakko","chakki","chaka","Chinal","Randi","ramdi","randya","Lulli","Gasti","Meetha","Halwa","Gud","Gandu","Gaand","Gandiaal","lodu"] + let targetWords = ["Blog", "BLOG", "Choose", "bad", "BAD", "Bad", "Stupid", "STUPID", "stupid", "crazy", "Crazy", "idiot" , "Idiot" , "IDIOT", "CRAZY","ABLANARI","AblaNari","ablanari","chakka","jihidis","Jihadi","jihadi","Jihidi","zehadi","jehadan","jihadinon","Chakko","chakki","chaka","Chinal","Randi","ramdi","randya","Lulli","Gasti","Meetha","Halwa","Gud","Gandu","Gaand","Gandiaal","lodu","fuck","Fuck","Cunt","cunt","slut","Slut","Whore","whore","Chutiya","chutiya","Bsdk","bsdk","Madarchod","madarchod","behenchod","Bhenchod" , "Behenchod","motherfucker" + ] // let targetWords = slurList ; let uliStore = [] // getAllTextNodes(document.body, uliStore) getAllTextNodes(firstBody, uliStore) - console.log(uliStore) + // console.log(uliStore) abc = locateSlur(uliStore, targetWords) - console.log("uliStore", abc) + // console.log("uliStore", abc) addMetaData(targetWords) } @@ -232,7 +235,7 @@ function addMetaData(targetWords) { span.style.border = "1px solid black" span.style.borderRadius = "12px" span.style.padding = "2px 6px" - // span.style.width = "12rem" + span.style.width = "16rem" span.style.textAlign = "justify" span.style.fontWeight = "lighter" span.style.color = "black" @@ -241,34 +244,51 @@ function addMetaData(targetWords) { 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() === "idiot") { - 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.` - } - + span.innerHTML = `${targetWord} is an offensive word` + + + jsonData.forEach(slur => { + const slurWord = Object.keys(slur)[0]; // Get the slur word (the key) + if (slurWord.toLowerCase() === targetWord.toLowerCase()) { // Check if it matches the provided word + const slurDetails = slur[slurWord]; // Access the details of the slur + + let levelOfSeverity = slurDetails["Level of Severity"] ; + let casual = slurDetails["Casual"] ; + let approapriated = slurDetails["Appropriated"] ; + let reason = slurDetails["If, Appropriated, Is it by Community or Others?"] ; + let problematic = slurDetails["What Makes it Problematic?"]; + let categories = slurDetails["Categories"] ; + + let htmlContent = `` ; + if(levelOfSeverity){ + htmlContent += `

Level of Severity: ${levelOfSeverity}

` + } + + if(casual){ + htmlContent += `

Casual: ${casual}

` + } + + if(approapriated){ + htmlContent += `

Appropriated: ${approapriated}

` + } + + if(reason){ + htmlContent += `

If, Appropriated, Is it by Community or Others?: ${reason}

` + } + + if(problematic){ + htmlContent += `

What Makes it Problematic?: ${problematic}

` + } + + if(categories.length > 0){ + htmlContent += `

Categories: ${slurDetails["Categories"].join(', ')}

` + } + + + span.innerHTML = htmlContent; // Set the HTML content to the span element + } + }); + sup.appendChild(img) sup.appendChild(span) diff --git a/browser-extension/plugin/src/ui-components/pages/Preferences.jsx b/browser-extension/plugin/src/ui-components/pages/Preferences.jsx index af1d5965..6c5848d4 100644 --- a/browser-extension/plugin/src/ui-components/pages/Preferences.jsx +++ b/browser-extension/plugin/src/ui-components/pages/Preferences.jsx @@ -109,7 +109,7 @@ export function Preferences() { await setPreferenceData({ ...localPreferences, enableSlurReplacement, - // enableSlurMetadata + enableSlurMetadata }); userBrowserTabs.sendMessage(tabId, { @@ -140,7 +140,7 @@ export function Preferences() { await setPreferenceData({ ...localPreferences, enableSlurMetadata, - // enableSlurReplacement + enableSlurReplacement }); userBrowserTabs.sendMessage(tabId, {