Skip to content

Commit

Permalink
remove dupes from classhashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Apr 1, 2024
1 parent 92d86a8 commit d2bef29
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
47 changes: 47 additions & 0 deletions src/deckyPatches/ClassHashMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { classMap } from "decky-frontend-lib";

export var classHashMap = new Map<string, string>();

export function initializeClassHashMap() {
const withoutLocalizationClasses = classMap.filter((module) => Object.keys(module).length < 1000);

const allClasses = withoutLocalizationClasses
.map((module) => {
let filteredModule = {};
Object.entries(module).forEach(([propertyName, value]) => {
// Filter out things that start with a number (eg: Breakpoints like 800px)
// I have confirmed the new classes don't start with numbers
if (isNaN(Number(value.charAt(0)))) {
filteredModule[propertyName] = value;
}
});
return filteredModule;
})
.filter((module) => {
// Some modules will be empty after the filtering, remove those
return Object.keys(module).length > 0;
});

const mappings = allClasses.reduce((acc, cur) => {
Object.entries(cur).forEach(([property, value]) => {
if (acc[property]) {
acc[property].push(value);
} else {
acc[property] = [value];
}
});
return acc;
}, {});

const hashMapNoDupes = Object.entries<string[]>(mappings).reduce<Map<string, string>>(
(acc, entry) => {
if (entry[1].length === 1) {
acc.set(entry[1][0], entry[0]);
}
return acc;
},
new Map()
);

classHashMap = hashMapNoDupes;
}
31 changes: 1 addition & 30 deletions src/deckyPatches/UnminifyMode.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
import { classMap } from "decky-frontend-lib";
import { classHashMap, initializeClassHashMap } from "./ClassHashMap";
import { getRootElements } from "./SteamTabElementsFinder";

const classHashMap = new Map<string, string>();

function initializeClassHashMap() {
const withoutLocalizationClasses = classMap.filter((module) => Object.keys(module).length < 1000);

const allClasses = withoutLocalizationClasses
.map((module) => {
let filteredModule = {};
Object.entries(module).forEach(([propertyName, value]) => {
// Filter out things that start with a number (eg: Breakpoints like 800px)
// I have confirmed the new classes don't start with numbers
if (isNaN(Number(value.charAt(0)))) {
filteredModule[propertyName] = value;
}
});
return filteredModule;
})
.filter((module) => {
// Some modules will be empty after the filtering, remove those
return Object.keys(module).length > 0;
});

allClasses.forEach((module: Record<string, string>) => {
Object.entries(module).forEach(([propertyName, value]) => {
classHashMap.set(value, propertyName);
});
});
}

export function unminifyElement(element: Element) {
if (element.classList.length === 0) return;

Expand Down

0 comments on commit d2bef29

Please sign in to comment.