Skip to content

Instantly share code, notes, and snippets.

@Mindgamesnl
Created August 26, 2023 20:54
Show Gist options
  • Save Mindgamesnl/142661e5dd6ae123c09646dafa6b7985 to your computer and use it in GitHub Desktop.
Save Mindgamesnl/142661e5dd6ae123c09646dafa6b7985 to your computer and use it in GitHub Desktop.
room.nl positie overzicht

Een heel lelijk scriptje om je positie te laten zien in het room.nl overzicht. Zo kan je beter beslissen waar je naar wilt kijken en wat je positie zou zijn, zonder eindeloos door te klikken.

image

async function processDiv(divNumber) {
console.log(`Processing div with number: ${divNumber}`);
const formData = new FormData();
formData.append('id', divNumber);
try {
const response = await fetch('https://www.room.nl/portal/object/frontend/getobject/format/json', {
method: 'POST',
body: formData
});
if (response.ok) {
const result = await response.json();
return result.result; // Return the extracted data
} else {
console.error('Failed to fetch data');
return null; // Return null if fetching fails
}
} catch (error) {
console.error('An error occurred:', error);
return null; // Return null if an error occurs
}
}
async function sortAndDisplayEntries() {
const divs = document.querySelectorAll('div[id^="object-tile-"]');
for (const div of divs) {
const id = div.id;
const match = id.match(/^object-tile-(\d+)$/);
async function process(match) {
if (match) {
const divNumber = parseInt(match[1]);
const entry = await processDiv(divNumber);
// get parent which is inside the list, could be used to possibly sort
// const inList = div.parentElement.parentElement.parentElement.parentElement
const reactieInformatie = div.querySelector('.reactie-informatie');
if (reactieInformatie) {
// add a big centered text with the position
const position = entry.reactionData.mogelijkePositie
const positionText = document.createElement('div')
positionText.style = "font-size: 30px; font-weight: bold; text-align: center; color: white; background-color: red; padding: 10px; margin: 10px;"
positionText.innerText = `Position: ${position}`
reactieInformatie.appendChild(positionText)
}
}
}
process(match)
}
}
// Call the function to sort and display the entries
sortAndDisplayEntries();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment