Skip to content

Instantly share code, notes, and snippets.

@zb3
Created March 20, 2023 13:58
Show Gist options
  • Save zb3/8e95c03096f349a69496bb1cec86b33b to your computer and use it in GitHub Desktop.
Save zb3/8e95c03096f349a69496bb1cec86b33b to your computer and use it in GitHub Desktop.
Search within wykop.pl PM's exchanged between a given user
(async function() {
const fetchOptions = {
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${localStorage.token}`,
'Cookie': document.cookie
},
method: 'GET'
};
const getMessages = async (url) => {
const response = await fetch(url, fetchOptions);
const json = await response.json();
if (json.error) {
throw new Error(json.error.message);
}
return json.data.messages;
};
async function getConversationWithHistory(username, pageCb) {
let key = null;
let result = [];
while (1) {
let url = `https://wykop.pl/api/v3/pm/conversations/${username}${key?'?prev_message='+key:''}`;
let messages = await getMessages(url);
if (messages.length === 0) {
break;
}
let localResult = [];
for (const message of messages) {
localResult.push({
date: message.created_at,
sent: message.type === 0,
content: message.content,
});
}
result.splice(0, 0, ...localResult);
pageCb && pageCb();
key = messages[0].key;
}
return result;
}
const attacker = JSON.parse(atob(localStorage.token.split('.')[1])).username;
const victim = prompt("Użytkownik:");
try {
document.body.innerHTML = 'Ładowanie';
let result = await getConversationWithHistory(victim, () => {
document.write('...');
});
const h = x => x.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>');
result = result.map(msg => `<div class="${!msg.sent?'reply ':''}"><b>${h(msg.sent ? attacker : victim)}</b> <span style="color: grey">${h(msg.date)}</span><br><br>${h(msg.content)}</div>`).join('');
document.body.innerHTML = `<style>
body {font-family: sans; padding: 0; margin: 0}
div {padding: .8em;border-bottom: 2px solid #8a8a8a;}
div.reply {background: #f3f3f3}
</style>
${result}`;
} catch(e) {
alert('Błąd... '+e);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment