[A] getMessages() - GRP, E2E, GIF, metadata
This commit is contained in:
commit
17d331f4d2
4 changed files with 151 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# https://git-scm.com/docs/gitignore
|
||||
# https://help.github.com/articles/ignoring-files
|
||||
# Example .gitignore files: https://github.com/github/gitignore
|
||||
/bower_components/
|
||||
/node_modules/
|
||||
16
functions/getChats.js
Normal file
16
functions/getChats.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function getChats() {
|
||||
let chats = [];
|
||||
document.querySelectorAll('._2EXPL').forEach(chat => {
|
||||
const c = {
|
||||
profilePic: chat.querySelector('img') ? chat.querySelector('img').src : '',
|
||||
name: chat.querySelector('._1wjpf').textContent,
|
||||
message: chat.querySelector('._2_LEW ').textContent,
|
||||
time: chat.querySelector('._3T2VG').textContent,
|
||||
unreadMessages: false, // TODO unreadMessages
|
||||
unreadCount: 0, // TODO unreadCount
|
||||
}
|
||||
chats.push(c);
|
||||
})
|
||||
return chats;
|
||||
}
|
||||
getChats()
|
||||
128
functions/getMessages.js
Normal file
128
functions/getMessages.js
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
function getMessages() {
|
||||
let messages = [];
|
||||
document.querySelectorAll('.vW7d1').forEach(msg => {
|
||||
let m, meta = {
|
||||
type: 'message',
|
||||
direction: 'out',
|
||||
status: null,
|
||||
date: null,
|
||||
time: null,
|
||||
};
|
||||
// meta
|
||||
if (msg.querySelector('._1DZAH')) {
|
||||
// time
|
||||
meta.time = msg.querySelector('._3EFt_').textContent;
|
||||
//date
|
||||
if (msg.querySelector('.copyable-text')) {
|
||||
meta.date = msg.querySelector('.copyable-text').getAttribute('data-pre-plain-text').split('] ')[0].slice(1).split(', ')[1];
|
||||
} else if (messages.length > 0) {
|
||||
meta.date = messages[messages.length - 1].date;
|
||||
}
|
||||
// status
|
||||
if (msg.querySelector('._32uRw span')) {
|
||||
if (msg.querySelector('._32uRw span').getAttribute('data-icon').includes('dblcheck')) {
|
||||
meta.status = 'read';
|
||||
} else if (msg.querySelector('._32uRw span').getAttribute('data-icon').includes('check')) {
|
||||
meta.status = 'send';
|
||||
}
|
||||
} else {
|
||||
meta.direction = 'in';
|
||||
}
|
||||
console.log(meta.date, meta.time, meta.direction, meta.status)
|
||||
}
|
||||
// content
|
||||
if (msg.classList.contains('_3rjxZ')) {
|
||||
// SYSTEM MESSAGES
|
||||
if (msg.querySelector('._14b5J') != null) {
|
||||
// E2E _14b5J
|
||||
meta.type = 'e2e',
|
||||
m = {
|
||||
txt: msg.querySelector('._14b5J div').textContent,
|
||||
}
|
||||
} else if (msg.querySelector('._2ArBI') != null) {
|
||||
console.log('GRP ANNOUNCEMENT', msg)
|
||||
// GRP ANNOUNCEMENT _2ArBI
|
||||
meta.type = 'groupEvent',
|
||||
m = {
|
||||
txt: msg.querySelector('._2ArBI span').textContent,
|
||||
}
|
||||
} else {
|
||||
console.log('date', msg)
|
||||
// DATE
|
||||
meta.type = 'date';
|
||||
m = {
|
||||
txt: msg.querySelector('span').textContent,
|
||||
}
|
||||
}
|
||||
} else if (msg.querySelector('._3v3PK') != null) {
|
||||
console.log('media', msg)
|
||||
// img .message-out
|
||||
meta.type = 'media';
|
||||
m = {
|
||||
image: msg.querySelector('img').src,
|
||||
}
|
||||
// msg.querySelector('.WEu0O').style.backgroundImage
|
||||
} else if(msg.querySelector('._10MiG') != null) {
|
||||
console.log('GIF', msg)
|
||||
// gif ._10MiG
|
||||
meta.type = 'gif';
|
||||
m = {
|
||||
preview: msg.querySelector('.WEu0O').style.backgroundImage.slice(5, msg.querySelector('.WEu0O').style.backgroundImage.length-2),
|
||||
video: msg.querySelector('._1Y0rl').src
|
||||
}
|
||||
} else if(msg.querySelector('._2hOiI') != null) {
|
||||
// // ggf. alles gif ist in ._3CnDa
|
||||
// console.log('GIF2', msg)
|
||||
// // gif ._2hOiI
|
||||
// // DAS IST EIN GIF, DAS GERADE LÄUFT
|
||||
// meta.type = 'gif2';
|
||||
// m = {
|
||||
// preview: msg.querySelector('.WEu0O').style.backgroundImage.slice(5, msg.querySelector('.WEu0O').style.backgroundImage.length-2),
|
||||
// video: msg.querySelector('._1Y0rl').src
|
||||
// }
|
||||
} else if (msg.querySelector('._3FDzO') != null) {
|
||||
// link ._3FDzO
|
||||
meta.type = 'link';
|
||||
m = {
|
||||
preview: {
|
||||
img: msg.querySelector('._2H6ea').src,
|
||||
content: msg.querySelector('._3BCzw').textContent
|
||||
},
|
||||
message: msg.querySelector('._3zb-j.ZhF0n .selectable-text.copyable-text').textContent,
|
||||
}
|
||||
} else if (msg.querySelector('.quoted-mention') != null) {
|
||||
console.log('response', msg)
|
||||
// response .quoted-mention
|
||||
meta.type = 'response',
|
||||
m = {
|
||||
name: msg.querySelector('.copyable-text').getAttribute('data-pre-plain-text').split('] ')[1].replace(':', '').trim(),
|
||||
message: msg.querySelector('.copyable-text.selectable-text').textContent,
|
||||
r_name: msg.querySelector('._2a1Yw').textContent,
|
||||
r_message: msg.querySelector('.quoted-mention').textContent,
|
||||
}
|
||||
} else {
|
||||
console.log('message', msg)
|
||||
// message .Tkt2p
|
||||
m = {
|
||||
name: msg.querySelector('.copyable-text').getAttribute('data-pre-plain-text').split('] ')[1].replace(':', '').trim(),
|
||||
message: msg.querySelector('.copyable-text').textContent,
|
||||
}
|
||||
}
|
||||
// TODO message - function getText() bauen, welche statt textContent innerHTML nimmt und emojis im text verarbeitet & integriert
|
||||
messages.push({
|
||||
meta: meta ? meta : null,
|
||||
content: m ? m : null,
|
||||
});
|
||||
})
|
||||
return messages;
|
||||
}
|
||||
|
||||
function test() {
|
||||
let x = getMessages();
|
||||
console.log(x.length, 'messages', x);
|
||||
console.table(x.find(m => m.meta.type === 'message'))
|
||||
console.table(x.find(m => m.meta.type === 'response'))
|
||||
console.table(x.find(m => m.meta.type === 'gif'))
|
||||
console.table(x.find(m => m.meta.type === 'link'))
|
||||
}
|
||||
test()
|
||||
2
index.js
Normal file
2
index.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// TODO export functions
|
||||
// TODO build module
|
||||
Loading…
Reference in a new issue