Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	browser-extension/plugin/src/ui-components/pages/Preferences.jsx
#	uli-website/package-lock.json
#	uli-website/package.json
  • Loading branch information
duggalsu committed Nov 29, 2023
2 parents 9851c58 + fb7c6d6 commit 0dea63b
Show file tree
Hide file tree
Showing 31 changed files with 222 additions and 22,261 deletions.
2 changes: 1 addition & 1 deletion browser-extension/plugin/manifest.firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "uli",
"description": "Moderate your Twitter Feed",
"version": "0.1.14",
"version": "0.1.15",
"author": "tattlemade|cis",
"content_security_policy": "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": [
Expand Down
2 changes: 1 addition & 1 deletion browser-extension/plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "uli",
"description": "Moderate your Twitter Feed",
"version": "0.1.14",
"version": "0.1.15",
"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';"
Expand Down
24 changes: 15 additions & 9 deletions browser-extension/plugin/src/transform-general.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { replaceSlur } from './slur-replace';
import { log } from './logger';
import repository from './repository';
const { getPreferenceData } = repository;

// Traverse dom nodes to find leaf node that are text nodes and process
function bft(node) {
Expand Down Expand Up @@ -51,16 +53,20 @@ const processNewlyAddedNodesGeneral = function (firstBody) {
log('processing new nodes');
const config = { attributes: true, childList: true, subtree: true };

const callback = () => {
let elems = firstBody.children;
const nodes = Array.from(elems);
let relevant_elements = nodes.filter((element) =>
['P', 'DIV'].includes(element.nodeName)
);
const callback = async () => {
const pref = await getPreferenceData();
const { enableSlurReplacement } = pref;
if (enableSlurReplacement) {
let elems = firstBody.children;
const nodes = Array.from(elems);
let relevant_elements = nodes.filter((element) =>
['P', 'DIV'].includes(element.nodeName)
);

relevant_elements.map((element) => {
bft(element);
});
relevant_elements.map((element) => {
bft(element);
});
}
};
const observer = new MutationObserver(callback);
observer.observe(firstBody, config);
Expand Down
2 changes: 1 addition & 1 deletion browser-extension/plugin/src/twitter/tweet-controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Api from '../ui-components/pages/Api';
import Theme from '../ui-components/atoms/Theme';
const { getUserData, getPreferenceData } = repository;
const { invokeNetwork } = Api;
const axios = require('axios');
import axios from 'axios';

function UnfocussedButton({ onClick, children }) {
return (
Expand Down
78 changes: 43 additions & 35 deletions browser-extension/plugin/src/ui-components/pages/Preferences.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import browserUtils from '../../chrome';
import { langNameMap } from '../atoms/language';
const { savePreference } = Api;
import { UserContext, NotificationContext } from '../atoms/AppContext';
import { userBrowser, userBrowserTabs } from '../../browser-compat';
import { userBrowserTabs } from '../../browser-compat';
const { setPreferenceData, getPreferenceData } = repository;

const defaultValue = {};
Expand Down Expand Up @@ -86,8 +86,38 @@ export function Preferences() {
};
}, [user]);

console.log('User Browser - ', userBrowser);
// console.log('User Browser Tab - ', userBrowserTabs);
async function handleSlurReplacement(enableSlurReplacement) {
try {
const confirmed = window.confirm(
'This action requires a page reload. Do you want to continue?'
);
if (confirmed) {
const tabsCurrent = await userBrowserTabs.query({
active: true,
currentWindow: true
});
const tabId = tabsCurrent[0].id;

await setPreferenceData({
...localPreferences,
enableSlurReplacement
});

userBrowserTabs.sendMessage(tabId, {
type: 'ULI_ENABLE_SLUR_REPLACEMENT',
payload: enableSlurReplacement
});
userBrowserTabs.reload(tabId);
}
} catch (error) {
console.log(error);
}
}

async function changeEnableSlurReplacementOption(checked) {
console.log(checked);
setEnableSlurReplacement(checked);
}

async function clickSave(preference) {
const preferenceInLS = await getPreferenceData();
Expand All @@ -104,33 +134,16 @@ export function Preferences() {
enable,
enableML,
storeLocally,
language
language,
enableSlurReplacement
});

const enableSlurReplacementChanged =
enableSlurReplacement !== preferenceInLS.enableSlurReplacement;

if (enableSlurReplacementChanged) {
console.log('enable val changed', enableSlurReplacementChanged);
const confirmed = window.confirm(
'This action requires a page reload. Do you want to continue?'
);
if (confirmed) {
const tabsCurrent = await userBrowserTabs.query({
active: true,
currentWindow: true
});
setEnableSlurReplacement(enableSlurReplacement);
await setPreferenceData({
...preferenceRemote.data,
enableSlurReplacement: enableSlurReplacement
});
const tabId = tabsCurrent[0].id;
userBrowserTabs.sendMessage(tabId, {
type: 'ULI_ENABLE_SLUR_REPLACEMENT',
payload: enableSlurReplacement
});
userBrowserTabs.reload(tabId);
}
await handleSlurReplacement(enableSlurReplacement);
}

showNotification({
Expand All @@ -139,11 +152,11 @@ export function Preferences() {
});
browserUtils.sendMessage('updateData', undefined);
} catch (err) {
// alert(err);
showNotification({
type: 'error',
message: t('message_error_preference_data_save')
});
console.log(err);
}
}

Expand All @@ -156,14 +169,9 @@ export function Preferences() {
setStoreLocally(checked);
}

async function changeEnableMLOption(checked) {
setEnableMLOption(checked);
}

async function changeEnableSlurReplacementOption(checked) {
console.log(checked);
setEnableSlurReplacement(checked);
}
// async function changeEnableMLOption(checked) {
// setEnableMLOption(checked);
// }

return (
<Box fill gap={'medium'}>
Expand Down Expand Up @@ -199,13 +207,13 @@ export function Preferences() {
onChange={(e) => changeLocalStorageOption(e.target.checked)}
/>
</Box>
<Box direction="row" gap={'large'} align="center">
{/* <Box direction="row" gap={'large'} align="center">
<CheckBox
checked={enableML}
label={t('enable_ml')}
onChange={(e) => changeEnableMLOption(e.target.checked)}
/>
</Box>
</Box> */}
<Box direction="row" gap={'large'} align="center">
<CheckBox
checked={enableSlurReplacement}
Expand Down
1 change: 1 addition & 0 deletions uli-website/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
11 changes: 1 addition & 10 deletions uli-website/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ module.exports = {
"gatsby-plugin-styled-components",
"gatsby-plugin-image",
"gatsby-plugin-react-helmet",
{
resolve: "gatsby-plugin-mdx",
options: {
defaultLayouts: {
default: require.resolve(
"./src/components/molecules/ContentPageShell.jsx"
),
},
},
},
"gatsby-plugin-mdx",
"gatsby-plugin-sharp",
"gatsby-transformer-sharp",
{
Expand Down
14 changes: 14 additions & 0 deletions uli-website/gatsby-node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createFilePath } from "gatsby-source-filesystem"

export const onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
if (node.internal.type === 'Mdx') {
const relativeFilePath = createFilePath({ node, getNode })
console.log(relativeFilePath);
createNodeField({
node,
name: 'slug',
value: `${relativeFilePath}`
});
}
};
Loading

0 comments on commit 0dea63b

Please sign in to comment.