-
Notifications
You must be signed in to change notification settings - Fork 0
/
privatemessages.js
53 lines (44 loc) · 2.03 KB
/
privatemessages.js
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
///////////////////////////////////////////////////////////////////////////////////////
// PRIVATE MESSAGES PAGE
///////////////////////////////////////////////////////////////////////////////////////
function findPrivateMessageDefaultParams(doc) {
if (!doc) return null;
return [...doc.querySelectorAll('#b-reception > form > input[type=hidden]')]
.map(fs => ({ name: fs.getAttribute('name'), value: fs.getAttribute('value') }));
}
async function sendPrivateMessagesToSpam(messageIds, onMpPage) {
const url = 'https://www.jeuxvideo.com/messages-prives/boite-reception.php';
let mpDoc = onMpPage ? document : await fetchHtml(url);
let mpFsElements = findPrivateMessageDefaultParams(mpDoc);
if (!mpFsElements) return;
let params = new URLSearchParams();
mpFsElements.forEach(fs => { params.append(fs.name, fs.value); });
params.append('conv_move', '666');
messageIds.forEach(m => { params.append('conv_select[]', m); });
await fetch(url, { method: 'POST', body: params })
.then(function (response) {
if (!response.ok) throw Error(response.statusText);
}).catch(function (err) {
console.error(err);
});
}
async function getPrivateMessageAuthor(messageId, hash) {
const url = 'https://www.jeuxvideo.com/messages-prives/ajax/ajax_mp_get_participants.php';
let params = new URLSearchParams();
params.append('idc', messageId);
params.append('h', hash);
const resDoc = await fetch(url, { method: 'POST', body: params })
.then(function (response) {
if (!response.ok) throw Error(response.statusText);
return response.text();
}).then(function (r) {
const resObj = JSON.parse(r);
return domParser.parseFromString(resObj.html, 'text/html');
}).catch(function (err) {
console.error(err);
});
if (!resDoc) return null;
const authorElem = resDoc.body.querySelector('ul > li > span');
if (!authorElem) return null;
return authorElem.textContent.trim();
}