Advertisement
MarkusAO

LinkedIn Groups: AJAX Thread Logger

Feb 23rd, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Run in your browser console to auto-load LinkedIn threads.
  2. Optionally archive posts to an off-site AJAX receiver. */
  3.  
  4. /* Button clicker */
  5.  
  6. function eventFire(el, etype){
  7.   if (el.fireEvent) {
  8.     el.fireEvent('on' + etype);
  9.   } else {
  10.     var evObj = document.createEvent('Events');
  11.     evObj.initEvent(etype, true, false);
  12.     el.dispatchEvent(evObj);
  13.   }
  14. }
  15.  
  16. var totalDone = 0;
  17.  
  18. /* Each load: 10 new posts | To reload without archiving; skipComs = 1. */
  19.  
  20. function liLo(loTimes, skipComs) {
  21.    
  22.     var moBu = document.getElementsByClassName('js-view-next-comments');
  23.     if (moBu) {
  24.         elLi = moBu[0];
  25.     }
  26.    
  27.     intv = 3000; // Load more: Interval (ms)
  28.     waiter = 0;
  29.    
  30.     for(lo = 1; lo <= loTimes; lo++) {
  31.        
  32.         if (elLi) {
  33.             (function(loops) {
  34.                 setTimeout(function() {
  35.                     eventFire(elLi, 'click');
  36.                     console.log('Loading more... Loop: ' + loops);
  37.                 }, waiter);
  38.             })(lo);
  39.         }
  40.         else {
  41.             console.log('All is loaded!');
  42.         }
  43.         waiter = waiter + intv;
  44.        
  45.         if (!skipComs) { // If we're just loading.
  46.            
  47.             if (lo % 4 == 0 || lo == loTimes) { // Chunk it up a bit more.
  48.                 setTimeout(function() {
  49.                     getCom();
  50.                 }, waiter + intv);         
  51.             }
  52.         }
  53.        
  54.     }
  55. }
  56.  
  57.  
  58. /* AJAX post routine */
  59.  
  60. var ajaxHandler = 'https://--------.net/logs/ajax_logger.php'; // Your logger here.
  61.  
  62. /* Your logger must send the following headers to avoid cross-origin issues:
  63.    header('Access-Control-Allow-Origin: *');
  64.    header('Access-Control-Allow-Headers: Content-Type');
  65.    header('Content-Type: text/plain'); */
  66.  
  67. function aPost(aData, aTgtId) {
  68.    
  69.     var xhttp = new XMLHttpRequest();
  70.     xhttp.onreadystatechange = function() {
  71.         if (xhttp.readyState == 4 && xhttp.status == 200) {
  72.             console.log(xhttp.responseText);
  73.         }
  74.     };
  75.     // console.log('Sending ' + aData.length + ' chars...');
  76.     xhttp.open("post", ajaxHandler, true);
  77.     xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  78.     xhttp.send(aData);
  79. }
  80.  
  81.  
  82. /* Get comments; send them in; remove from the page. */
  83.  
  84. var hashChk = {};
  85.  
  86. function getCom() {
  87.    
  88.     comList = document.getElementsByClassName('comment-view');
  89.     i = comList.length;
  90.     e = i;
  91.    
  92.     // waiter = 100;
  93.     // intv = 200;
  94.    
  95.     var postList = [];
  96.     var totalLength = 0;
  97.    
  98.     while (i--) {
  99.         var liCom = {};
  100.        
  101.         totalDone++;
  102.        
  103.         liCom["user"] = comList[i].getElementsByClassName('js-author-name name')[0].innerHTML;
  104.         liCom["date"] = comList[i].getElementsByClassName('comment-timestamp')[0].title;
  105.         liCom["text"] = comList[i].getElementsByClassName('text')[0].innerHTML;
  106.         liCom["likes"] = comList[i].getElementsByClassName('js-like-count')[0].innerHTML;
  107.        
  108.         d = new Date();
  109.         liCom["logid"] = d.getTime() + ':' + i;
  110.         liCom["order"] = totalDone;
  111.        
  112.         // comList[i].parentElement.removeChild(comList[i]);
  113.         var doneRef = liCom["text"].slice(0,50).replace(/(<([^>]+)>)/ig,'');
  114.         comList[i].innerHTML = liCom["user"] + '; ' + liCom["date"] + '; DONE; ' + totalDone + ' | ' +  doneRef;
  115.         comList[i].className = '';
  116.        
  117.         var hash = liCom["user"] +':'+ liCom["date"] +':'+ liCom["text"].length+':';
  118.        
  119.         for (x=1; x < liCom["text"].length; x = x + 20) {
  120.             hash += liCom["text"][x];
  121.         }
  122.        
  123.         if (hashChk[hash]) {
  124.             liCom["dupl"] = 1;
  125.             console.log('Duplicate! ' + JSON.stringify(liCom) );
  126.             // continue;
  127.         }
  128.         hashChk[hash] = true;
  129.        
  130.         jsonStr = JSON.stringify(liCom);
  131.         totalLength += jsonStr.length;
  132.        
  133.         postList.push(encodeURIComponent(jsonStr));
  134.        
  135.         // waiter = waiter + intv;
  136.     }
  137.    
  138.     var postList = postList.join("\n");
  139.    
  140.     if (postList.length > 0) {
  141.         console.log('Parsed ' + e + ' @ ' + totalLength + ' chars | Total Done: ' + totalDone + ' posts');
  142.        
  143.         aPost('c=' + postList);
  144.     } else {
  145.         console.log('Not loaded yet?');
  146.     }
  147. }
  148.  
  149.  
  150. /* Iterate N loops of 10 posts */
  151.  
  152. // liLo(1); // 10 more posts; load & archive
  153. // liLo(10); // 100 more posts; load & archive
  154. // liLo(100); // 1000 more posts; load & archive
  155. // liLo(10, 1); // 100 more posts; load only
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement