Skip to content

Commit

Permalink
Add mask ip option to IP info widget joelshepherd#657
Browse files Browse the repository at this point in the history
  • Loading branch information
BookCatKid committed Feb 9, 2025
2 parents 74da94c + f1a5e6c commit 4f222fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/plugins/widgets/ipInfo/IpInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const IpInfo: React.FC<Props> = ({
return null;
}

const info = [cache.ip];
const ip = data.maskIP ? cache.ip.split('.').map((s, i) => i > 0 && i < 3 ? s.replace(/[\d]+/, '*') : s).join('.') : cache.ip;
const info = [ip];
if (data.displayCity) info.push(cache.city);
if (data.displayCountry) info.push(cache.country);

Expand Down
11 changes: 11 additions & 0 deletions src/plugins/widgets/ipInfo/IpInfoSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ const IpInfoSettings: React.FC<Props> = ({ data = defaultData, setData }) => (
/>
Display Country
</label>

<label>
<input
type="checkbox"
checked={data.maskIP}
onChange={() =>
setData({ ...data, maskIP: !data.maskIP })
}
/>
Mask IP
</label>
</div>
);

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/widgets/ipInfo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { API } from "../../types";
type Data = {
displayCity: boolean;
displayCountry: boolean;
maskIP: boolean;
};

export type IpData = {
Expand All @@ -18,4 +19,5 @@ export type Props = API<Data, Cache>;
export const defaultData: Data = {
displayCity: true,
displayCountry: true,
maskIP: false,
};

0 comments on commit 4f222fb

Please sign in to comment.