Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sarverott/8c71e58e78ef53ee08b56fdfbaf574be to your computer and use it in GitHub Desktop.
Save Sarverott/8c71e58e78ef53ee08b56fdfbaf574be to your computer and use it in GitHub Desktop.
const CSS_SELECTOR = {
displayed_chat: ".x78zum5.xdt5ytf.x1iyjqo2.x6ikm8r.x1odjw0f.xish69e.x16o0dkt",
message_block: "div.x78zum5.xdt5ytf.x1n2onr6[role]"
}
function scrollingToCheckPast( docHook = CSS_SELECTOR.displayed_chat ){
document.querySelectorAll( // szuka WSZYSTKICH
docHook // selektor CSS ()
)[ 1 ].scrollTo(0,0) // scrolling do góry, wtedy ładuje
}
function getOutput( docHook = CSS_SELECTOR.message_block ){
const DOM_COLLECTION = document.querySelectorAll( docHook );
const ARRAY_LIST = Array.from( DOM_COLLECTION );
var raw_output = ARRAY_LIST.filter(
( item )=>item.classList.length==3
);
//for(var message of raw_output)
raw_output = raw_output.map(
( record )=>Array.from(
record.querySelectorAll("span")
).map(
( txtBox )=>txtBox.innerText
)
);
return raw_output;
//Array.from(output[8].querySelectorAll("span")).map((x)=>x.innerText)
}
// testowane na chrome, dotyczy chatu po otwarciu "otwórz w messengerze"
//var OUTPUT = []; //
//var previousOutputLength = 0; // do sprawdzania czy ładuje nowe
// testowane na chrome, dotyczy chatu po otwarciu "otwórz w messengerze"
//var OUTPUT = []; //
//var previousOutputLength = 0; // do sprawdzania czy ładuje nowe
var DYNKSOWNICA = null;
DYNKSOWNICA={
delay:3000, // 3000 ms
intervalRef:null,
get ON(){
this.intervalRef=setInterval(
()=>{
scrollingToCheckPast();
this.OUTPUT=getOutput();
var diffLen=this.OUTPUT.length-this.previousOutLen;
var nowPtr=Date.now();
this.outLenLogs[nowPtr-this.UNIXUSAT]=diffLen;
console.table([
"ITERATION:",
Object.keys(this.outLenLogs).length,
nowPtr-this.UNIXUSAT,
diffLen,
]);
//console.log(this.PRINT);
this.previousOutLen=this.OUTPUT.length;
},
this.delay
);
},
get OFF(){
clearInterval(this.intervalRef);
},
get PRINT(){
console.log(JSON.stringify(this.OUTPUT, null, " "));
return JSON.stringify(this.OUTPUT, null, " ");
},
UNIXUSAT:Date.now(),
OUTPUT:[],
previousOutLen:0,
outLenLogs:null
}
DYNKSOWNICA.outLenLogs = {UNIXUSAT:DYNKSOWNICA.UNIXUSAT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment