Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Run in your browser console to auto-load LinkedIn threads.
- Optionally archive posts to an off-site AJAX receiver. */
- /* Button clicker */
- function eventFire(el, etype){
- if (el.fireEvent) {
- el.fireEvent('on' + etype);
- } else {
- var evObj = document.createEvent('Events');
- evObj.initEvent(etype, true, false);
- el.dispatchEvent(evObj);
- }
- }
- var totalDone = 0;
- /* Each load: 10 new posts | To reload without archiving; skipComs = 1. */
- function liLo(loTimes, skipComs) {
- var moBu = document.getElementsByClassName('js-view-next-comments');
- if (moBu) {
- elLi = moBu[0];
- }
- intv = 3000; // Load more: Interval (ms)
- waiter = 0;
- for(lo = 1; lo <= loTimes; lo++) {
- if (elLi) {
- (function(loops) {
- setTimeout(function() {
- eventFire(elLi, 'click');
- console.log('Loading more... Loop: ' + loops);
- }, waiter);
- })(lo);
- }
- else {
- console.log('All is loaded!');
- }
- waiter = waiter + intv;
- if (!skipComs) { // If we're just loading.
- if (lo % 4 == 0 || lo == loTimes) { // Chunk it up a bit more.
- setTimeout(function() {
- getCom();
- }, waiter + intv);
- }
- }
- }
- }
- /* AJAX post routine */
- var ajaxHandler = 'https://--------.net/logs/ajax_logger.php'; // Your logger here.
- /* Your logger must send the following headers to avoid cross-origin issues:
- header('Access-Control-Allow-Origin: *');
- header('Access-Control-Allow-Headers: Content-Type');
- header('Content-Type: text/plain'); */
- function aPost(aData, aTgtId) {
- var xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if (xhttp.readyState == 4 && xhttp.status == 200) {
- console.log(xhttp.responseText);
- }
- };
- // console.log('Sending ' + aData.length + ' chars...');
- xhttp.open("post", ajaxHandler, true);
- xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xhttp.send(aData);
- }
- /* Get comments; send them in; remove from the page. */
- var hashChk = {};
- function getCom() {
- comList = document.getElementsByClassName('comment-view');
- i = comList.length;
- e = i;
- // waiter = 100;
- // intv = 200;
- var postList = [];
- var totalLength = 0;
- while (i--) {
- var liCom = {};
- totalDone++;
- liCom["user"] = comList[i].getElementsByClassName('js-author-name name')[0].innerHTML;
- liCom["date"] = comList[i].getElementsByClassName('comment-timestamp')[0].title;
- liCom["text"] = comList[i].getElementsByClassName('text')[0].innerHTML;
- liCom["likes"] = comList[i].getElementsByClassName('js-like-count')[0].innerHTML;
- d = new Date();
- liCom["logid"] = d.getTime() + ':' + i;
- liCom["order"] = totalDone;
- // comList[i].parentElement.removeChild(comList[i]);
- var doneRef = liCom["text"].slice(0,50).replace(/(<([^>]+)>)/ig,'');
- comList[i].innerHTML = liCom["user"] + '; ' + liCom["date"] + '; DONE; ' + totalDone + ' | ' + doneRef;
- comList[i].className = '';
- var hash = liCom["user"] +':'+ liCom["date"] +':'+ liCom["text"].length+':';
- for (x=1; x < liCom["text"].length; x = x + 20) {
- hash += liCom["text"][x];
- }
- if (hashChk[hash]) {
- liCom["dupl"] = 1;
- console.log('Duplicate! ' + JSON.stringify(liCom) );
- // continue;
- }
- hashChk[hash] = true;
- jsonStr = JSON.stringify(liCom);
- totalLength += jsonStr.length;
- postList.push(encodeURIComponent(jsonStr));
- // waiter = waiter + intv;
- }
- var postList = postList.join("\n");
- if (postList.length > 0) {
- console.log('Parsed ' + e + ' @ ' + totalLength + ' chars | Total Done: ' + totalDone + ' posts');
- aPost('c=' + postList);
- } else {
- console.log('Not loaded yet?');
- }
- }
- /* Iterate N loops of 10 posts */
- // liLo(1); // 10 more posts; load & archive
- // liLo(10); // 100 more posts; load & archive
- // liLo(100); // 1000 more posts; load & archive
- // liLo(10, 1); // 100 more posts; load only
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement