-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode.js
More file actions
182 lines (163 loc) · 6.09 KB
/
Copy pathcode.js
File metadata and controls
182 lines (163 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
const newStyle = document.createElement('style');
newStyle.innerText = `
.scroll-arrow {
display: none !important;
}
.ui-mode-pointer .games-list.games-list {
height: auto !important;
}
.ui-mode-pointer .games-list.games-list .slider {
height: auto !important;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
transform: none !important;
}
.ui-mode-pointer .games-list-tile.games-list-tile.games-list-tile {
width: 100%;
height: 100%;
margin: 0;
}
.psp-search-bar {
position: fixed;
z-index: 100;
display: block;
padding: 1em;
width: calc(100% - 10px);
top: 50px;
left: 0;
}
.ui-mode-pointer.ui-mode-pointer .category-tile>.title {
padding: 2em 1.2em;
position: sticky;
top: 53px;
background: inherit;
z-index: 99;
}
.ui-mode-pointer.ui-mode-pointer .category-tile {
background: #222;
}
.ui-mode-pointer.ui-mode-pointer .category-tile:nth-child(odd) {
background: #333;
}
.catalog-list {
padding-top: 53px;
display: flex;
flex-direction: column;
}
.PLAYHISTORY {
order: -1;
}
.games-list-tile[data-game-platform]:after {
position: absolute;
content: attr(data-game-platform);
bottom: 0;
left: 0;
display: inline-block;
}
`;
const PSPP_WaitForCatalogListLoad = () => {
// Observe DOM mutations (changes to the structure)
const observer = new MutationObserver(async () => {
const catalogList = document.querySelector(".catalog-list");
// Check if catalog list is loaded
if (catalogList) {
// Remove observer
observer.disconnect();
// Create input for search
const input = document.createElement('input');
input.classList.add('psp-search-bar');
input.placeholder = 'Search (loading...)';
catalogList.prepend(input);
PSPP_RemoveDuplicates();
await PSPP_LoadGameNames();
input.placeholder = 'Search';
const games = Array.from(document.querySelectorAll('[data-game]'));
// Listen for input changes
input.addEventListener('input', () => {
// Filter games based on search query
const v = input.value.toLowerCase();
games.forEach((game) => {
const gameName = game.getAttribute('data-game-name');
if ((gameName && gameName.toLowerCase().includes(v)) || v == '') {
game.style.display = 'block';
} else {
game.style.display = 'none';
}
});
});
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
document.querySelector('body').appendChild(newStyle);
};
// Load all the lists to retrieve the game names
const PSPP_LoadGameNames = async () => {
const promises = [];
const lists = await PSPP_GetGameLists();
lists.forEach((el) => {
const url = `${el}?start=0&size=1000`;
promises.push(fetch(url).then((response) => response.json()));
});
return Promise.all(promises).then((data) => {
data.forEach(({links}) => {
links.forEach(({ name, id, playable_platform }) => {
const tiles = Array.from(document.querySelectorAll(`[data-game="${id}"]`));
tiles.forEach((tile) => {
tile.setAttribute('data-game-name', name);
if (playable_platform) {
tile.setAttribute('data-game-platform', playable_platform.join('/'));
}
});
});
});
});
};
// Get the base url from the store url
const PSPP_GetBaseUrl = () => {
return new Promise((resolve) => {
const newScript = document.createElement('script');
newScript.innerText = `
document.body.dataset.kamajiURL = GrandCentral.getConfig().kamajiHostUrl;
`;
document.querySelector('body').appendChild(newScript);
setTimeout(() => {
const URL = document.querySelector('body').dataset.kamajiURL + 'user/stores';
fetch(URL)
.then((response) => response.json())
.then(({data}) => {
resolve(data.base_url);
});
});
}, 100);
}
// Use the base url to get the game lists
const PSPP_GetGameLists = async () => {
const url = await PSPP_GetBaseUrl();
return new Promise((resolve) => {
fetch(url)
.then((response) => response.json())
.then(({links}) => {
resolve(links.map(({url}) => url));
});
});
}
// Sliders have duplicates, so we need to remove them
const PSPP_RemoveDuplicates = () => {
const sliders = Array.from(document.querySelectorAll('.games-list .slider'));
sliders.forEach((slider) => {
const ids = [];
const children = Array.from(slider.children);
children.forEach((entry) => {
const id = entry.getAttribute('data-game');
if (ids.includes(id)) {
entry.remove();
} else {
ids.push(id);
}
});
});
}
document.addEventListener("DOMContentLoaded", PSPP_WaitForCatalogListLoad);