ryanjj245

Instagram / Twitter Giveaway Raffle

Feb 26th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. copied from:
  4.  
  5. https://pastebin.com/udFkAV7b
  6.  
  7.  - Updated this Mar 30, 2019 at 4:09 PM to accommodate the new "+" button
  8.  
  9. - you have to go to the post first by clicking on the ellipses at the top right
  10.  
  11. */
  12.  
  13. raffleGiverAwayer = "gibiofficial";
  14. clickMoreIntervals = [800, 1200]; // click every 0.8 seconds to 1.2 seconds
  15. raffleGiverAwayer = raffleGiverAwayer.replace(/^@/, "")
  16. moreCommentsBtn = null;
  17. numClickMoreClicks = 1;
  18. lastNumEntries = null;
  19. doneClicking = false;
  20. function clickMoreComments() {
  21.   setTimeout(function() {
  22.     moreCommentsBtn = document.querySelector("div[class*=IwRSH] button[class*=afkep]");
  23.     if(!moreCommentsBtn) {
  24.       moreCommentsBtn = document.querySelector("ul[class*=k59kT] button[class*=sqdOP]");
  25.     }
  26.     if(numClickMoreClicks % 10 == 0) {
  27.       totalElems = getNumGathered();
  28.       // no more click more button
  29.       if(moreCommentsBtn == null
  30.          || (lastNumEntries != null && (typeof totalElems) == "number" && lastNumEntries == totalElems)
  31.         ) {
  32.         gShowSoFar = false;
  33.         doneClicking = true;
  34.         getAllListItems(false);    
  35.         return;    
  36.       }
  37.       tmpLastNumEntries = getNumGathered();
  38.       if((typeof tmpLastNumEntries) == "number") {
  39.         lastNumEntries = tmpLastNumEntries;
  40.       }
  41.     }  
  42.     if((numClickMoreClicks + 1) % 5 == 0) {
  43.       if(!gShowSoFar) {
  44.         displayRaffleMsg(getNumGathered() + " elements gathered so far", 450, 45);
  45.       }
  46.     }
  47.     if(moreCommentsBtn) {
  48.       if(moreCommentsBtn.getAttribute("disabled") == null) {
  49.         evt = new MouseEvent("click", {view: window, bubbles: true, cancelable: true, clientX: 20});
  50.         moreCommentsBtn.dispatchEvent(evt);
  51.       }
  52.       clickInterval = Math.random() * (clickMoreIntervals[1] - clickMoreIntervals[0]) + clickMoreIntervals[0];
  53.       setTimeout(function() {
  54.           if(!gShowSoFar) {
  55.             clickAllViewReplies();
  56.           }
  57.       }, clickInterval);
  58.     } else {
  59.       doneClicking = true;
  60.       getAllListItems(false);    
  61.     }
  62.     numClickMoreClicks++;
  63.   }, 250);
  64. }
  65.  
  66. // get number of elements gathered so far
  67. function getNumGathered() {
  68.       tmpLastNumEntries = document.querySelectorAll("ul[class*=Mr508] li[class*=rUo9f]").length;
  69.       if((typeof tmpLastNumEntries) == "number") {
  70.           if(tmpLastNumEntries == 0) {
  71.               tmpLastNumEntries = document.querySelectorAll("ul[class*=k59kT] li[class*=gElp9]").length;
  72.           }
  73.           if((typeof tmpLastNumEntries) == "number") {
  74.             tmpLastNumEntries2 = document.querySelectorAll("ul[class*=TCSYW] li[class*=rUo9f]").length;
  75.             if((typeof tmpLastNumEntries2) == "number") {
  76.               tmpLastNumEntries += tmpLastNumEntries2;
  77.             }        
  78.             return tmpLastNumEntries;
  79.           }
  80.       }
  81.   return false;
  82. }
  83.  
  84. // click all the View replies buttons
  85. numMoreReplyClicks = 0;
  86. function clickAllViewReplies(lastRepliesLeft) {
  87.     viewReplyBtns = document.querySelectorAll("ul[class*=TCSYW] li[class*=_61Di1] button[class*=sqdOP]");
  88.     replyCmntsLeft = 0;
  89.     for(repI = 0; repI < viewReplyBtns.length; repI++) {
  90.       replyBtn = viewReplyBtns[repI];
  91.       if(replyBtn.getAttribute("disabled") == null) {
  92.         if(replyMatches = replyBtn.innerText.match(/View\ replies\ \((\d+)\)/i)) {
  93.            replyCmntsLeft += parseInt(replyMatches[1]);
  94.           evt = new MouseEvent("click", {view: window, bubbles: true, cancelable: true, clientX: 20});
  95.           replyBtn.dispatchEvent(evt);       
  96.           break;
  97.         }
  98.       }
  99.     }
  100.     if(lastRepliesLeft != undefined && lastRepliesLeft == replyCmntsLeft) {
  101.         replyCmntsLeft = 0;
  102.     }
  103.     // all replies so far clicked
  104.     if(replyCmntsLeft == 0) {
  105.         // move replies iterator up
  106.         viewRepliesItr = viewReplyBtns.length;
  107.         // continue clicking clickMoreComments
  108.         setTimeout(function() {
  109.           if(!gShowSoFar) {
  110.             clickMoreComments();
  111.           }
  112.         }, clickInterval);
  113.     } else {
  114.         setTimeout(function() {
  115.           if(replyCmntsLeft == undefined) {
  116.               replyCmntsLeft = 0;
  117.           }
  118.           clickAllViewReplies(replyCmntsLeft);
  119.         }, clickInterval);
  120.     }
  121.   if(numMoreReplyClicks % 5 == 0) {
  122.       if(!gShowSoFar) {
  123.         displayRaffleMsg(getNumGathered() + " elements gathered so far", 450, 45);
  124.       }
  125.   }
  126.   numMoreReplyClicks++;
  127. }
  128.  
  129. function getAllListItems(showAllComments) {
  130.   unfilteredList = [];
  131.   filteredList = [];
  132.   excludedList = [];
  133.   if(showAllComments == undefined) { showAllComments = true; }
  134.   gShowAllComms = showAllComments;
  135.   mainItems = document.querySelectorAll("ul[class*=Mr508] li[class*=rUo9f]");
  136.   if(mainItems.length == 0) {
  137.     mainItems = document.querySelectorAll("ul[class*=k59kT] li[class*=gElp9]");
  138.   }
  139.   replyItems = document.querySelectorAll("ul[class*=TCSYW] li[class*=rUo9f]");
  140.    
  141.   for(listCommentsType = 0; listCommentsType < 1; listCommentsType++) {
  142.     if(listCommentsType == 0) {
  143.       listItems = mainItems;
  144.     } else if(listCommentsType == 1) {
  145.       listItems = replyItems;
  146.     }
  147.     for(listI = 0; listI < listItems.length; listI++) {
  148.       if(raffleUserHref = listItems[listI].querySelector("a[href]")) {
  149.         raffleUser = raffleUserHref.getAttribute("href");    
  150.         raffleUser = raffleUser.replace(/\//g, "");
  151.         comment = listItems[listI].innerText;
  152.         comment = comment.replace(/[\r\n]+/g, " ");
  153.         comment = comment.replace("@" + raffleGiverAwayer, "[at]" + raffleGiverAwayer);
  154.         comment = comment.replace(/\d+w\d+\ likes?Reply\s*$/, "");
  155.         comment = comment.replace(/\d+wReply\s*$/, "");
  156.         comment = comment.replace(/\d+d\d+\ likes?Reply\s*$/, "");
  157.         comment = comment.replace(/\d+dReply\s*$/, "");
  158.         comment = comment.replace(/\d+h\d+\ likes?Reply\s*$/, "");
  159.         comment = comment.replace(/\d+hReply\s*$/, "");    
  160.         comment = comment.replace(/\d+mReply\s*$/, "");    
  161.         comment = comment.replace(/\d+m\d+\ likes?Reply\s*$/, "");     
  162.         comment = comment.trim();
  163.         unfilteredList.push({user: raffleUser, "comment": comment});
  164.       }
  165.     }
  166.   }
  167.   unfilteredList.sort(function(a, b) {
  168.     if(a.user < b.user) { return -1; }
  169.     else if(a.user > b.user) { return 1; }
  170.     else {
  171.       if(a.comment < b.comment) { return -1; }
  172.       else if(a.comment > b.comment) { return 1; }
  173.       else return 0;
  174.     }
  175.   });
  176.   lastUser = null;
  177.   lastComment = null;  
  178.   for(listI = 0; listI < unfilteredList.length; listI++) {
  179.     if(lastComment == null || lastComment != unfilteredList[listI].comment) {
  180.       if(!showAllComments) {
  181.         if((lastUser == null || lastUser != unfilteredList[listI].user)
  182.              // has tagged another user
  183.              && (otherUserMatch = unfilteredList[listI].comment.match(/@([^@\s]{3,})(\s|$)/))
  184.              // other user is not them
  185.              && unfilteredList[listI].user.indexOf(otherUserMatch[1]) == -1
  186.              // other user is not Gibi
  187.              && otherUserMatch[1].indexOf(raffleGiverAwayer) == -1
  188.           ) {
  189.           filteredList.push(unfilteredList[listI]);
  190.         } else {
  191.           excludedList.push(unfilteredList[listI]);
  192.         }
  193.         lastUser = unfilteredList[listI].user;
  194.       } else {
  195.         filteredList.push(unfilteredList[listI]);
  196.       }
  197.     }
  198.     lastComment = unfilteredList[listI].comment;
  199.   }
  200.   outputStr = "";
  201.   for(listI = 0; listI < filteredList.length; listI++) {       
  202.     comment = filteredList[listI].comment;
  203.     comment = comment.replace(/\[at\]/g, "@");
  204.     outputStr += "@" + comment + "\r\n";
  205.   }
  206.   displayRaffleMsg(outputStr, 450, 450, showAllComments);
  207. }
  208.  
  209. gShowAllComms = true;
  210. gShowSoFar = false;
  211. function displayRaffleMsg(outputStr, dispWidth, dispHeight, showCheckBoxAll) {
  212.     if(dispWidth == undefined) { dispWidth = 400; }
  213.     if(dispHeight == undefined) { dispHeight = 400; }
  214.        
  215.     dispHeight = Math.max(60, dispHeight);
  216.     clearDispMsg();
  217.     dispResultsDiv = document.createElement("div");
  218.     dispResultsDiv.setAttribute("id", "dispResDiv");
  219.     dispResultsDiv.setAttribute("style", "position: fixed; left: 400px; min-width: " + dispWidth + "px; min-height: " + dispHeight + "px; background-color: rgb(210,235,2240); z-index: 10000; padding: 5px;");
  220.     dispResultsDiv.innerHTML = "click + press [enter] to make this go away";
  221.     if(gShowSoFar && !doneClicking) {
  222.       dispResultsDiv.innerHTML += "<br /><br />" + getNumGathered() + " elements gathered so far"
  223.     }
  224.     showResultsTextArea = document.createElement("textarea");
  225.     showResultsTextArea.setAttribute("id", "dispResText");
  226.     showResultsTextArea.setAttribute("spellcheck", "false");
  227.     showResultsTextArea.setAttribute("style", " z-index: 10001; min-width: " + (dispWidth - 20) + "px; min-height: " + (dispHeight - 40) + "px; margin: 14px; overflow: auto; background-color: rgb(210,235,224);");
  228.     mainCardDiv = document.querySelector("div[class*=ltEKP] div[class*=wKWK0]");
  229.     if(mainCardDiv == null) {
  230.         mainCardDiv = document.querySelector("div[class*=z8cbW] div[class*=RqtMr]");
  231.     }
  232.     if(mainCardDiv == null) {
  233.       mainCardDiv = document.querySelector("div[class*=KlCQn]");
  234.     }  
  235.     mainCardDiv.before(dispResultsDiv);
  236.     dispResultsDiv.append(showResultsTextArea);
  237.    
  238.    
  239.     // show checkbox for showing all
  240.     if(outputStr.length > 32) {
  241.       checkBoxAllDiv = document.createElement("div");
  242.       checkBoxAllDiv.setAttribute("style", "width: 450px; display: inline-block; padding: 5px;");
  243.       checkBoxAllElem = document.createElement("input");
  244.       checkBoxAllElem.setAttribute("type", "checkbox");
  245.       checkBoxAllElem.setAttribute("onchange", "checkUncheckShowAll();");
  246.       checkBoxAllElem.setAttribute("id", "showall_comments_checkbox");
  247.       checkBoxAllElem.setAttribute("style", "vertical-align: middle;");
  248.       if(showCheckBoxAll) {
  249.         checkBoxAllElem.setAttribute("checked", "checked");
  250.       }
  251.       checkBoxAllLabel = document.createElement("label");
  252.       checkBoxAllLabel.setAttribute("for", "showall_comments_checkbox");
  253.       checkBoxAllLabel.setAttribute("style", "vertical-align: middle;");
  254.       checkBoxAllLabel.innerHTML = " Show All";
  255.       checkBoxAllDiv.append(checkBoxAllElem);
  256.       checkBoxAllDiv.append(checkBoxAllLabel);
  257.       dispResultsDiv.append(checkBoxAllDiv);
  258.     }
  259.    
  260.     // show checkbox for showing everything so far
  261.     if(!doneClicking) {
  262.       checkBoxSoFarDiv = document.createElement("div");
  263.       checkBoxSoFarDiv.setAttribute("style", "width: 450px; display: inline-block; padding: 5px;");
  264.       checkBoxSoFarElem = document.createElement("input");
  265.       checkBoxSoFarElem.setAttribute("type", "checkbox");
  266.       checkBoxSoFarElem.setAttribute("onchange", "showSoFar();");
  267.       checkBoxSoFarElem.setAttribute("id", "showsofar_checkbox");
  268.       checkBoxSoFarElem.setAttribute("style", "vertical-align: middle;");
  269.      
  270.       checkBoxSoFarLabel = document.createElement("label");
  271.       checkBoxSoFarLabel.setAttribute("for", "showsofar_checkbox");
  272.       checkBoxSoFarLabel.setAttribute("style", "vertical-align: middle;");
  273.       if(gShowSoFar) {     
  274.         checkBoxSoFarLabel.innerHTML = " Resume";
  275.       } else {
  276.         checkBoxSoFarLabel.innerHTML = " Show Elements";
  277.       }
  278.       checkBoxSoFarDiv.append(checkBoxSoFarElem);
  279.       checkBoxSoFarDiv.append(checkBoxSoFarLabel);
  280.       dispResultsDiv.append(checkBoxSoFarDiv);     
  281.     }
  282.    
  283.     showResultsTextArea.value = outputStr; 
  284. }
  285. function showSoFar() {
  286.     gShowSoFar = ((gShowSoFar)? false : true);
  287.     if(gShowSoFar) {
  288.         getAllListItems(false);
  289.     } else {
  290.         clearDispMsg();
  291.         // resume clicking
  292.         clickMoreComments();
  293.         displayRaffleMsg(getNumGathered() + " elements gathered so far", 450, 45);
  294.     }
  295. }
  296.  
  297.  
  298. function checkUncheckShowAll() {
  299.   gShowAllComms = ((gShowAllComms)? false : true);
  300.   allShowAllElems = document.querySelectorAll('[id=showall_comments_checkbox]');
  301.   cboxAll = allShowAllElems[ allShowAllElems.length - 1 ];
  302.   if(gShowAllComms) {
  303.     getAllListItems(true);
  304.   } else {
  305.     getAllListItems(false);
  306.   }
  307. }
  308.  
  309. document.addEventListener("keyup", function(evt){
  310.   // [enter]
  311.   if(evt.keyCode == 13) {
  312.     if(document.querySelectorAll("div[id*=dispResDiv]").length) {
  313.       clickMoreComments = function() { };
  314.       clickAllViewReplies = function() {};
  315.       clearDispMsg();
  316.     }
  317.   }
  318. });
  319.  
  320. function clearDispMsg() {
  321.   allDispDivs = document.querySelectorAll("div[id*=dispResDiv]");
  322.   for(allDivI = 0; allDivI < allDispDivs.length; allDivI++) {
  323.     dispIdElems = allDispDivs[allDivI].querySelectorAll("[id]");
  324.     for(dispIdElemsI = 0; dispIdElemsI < dispIdElems.length; dispIdElemsI++) {
  325.         dispIdElems[dispIdElemsI].parentNode.removeChild(dispIdElems[dispIdElemsI]);
  326.     }
  327.     allDispDivs[allDivI].style.display = "none";
  328.     allDispDivs[allDivI].parentNode.removeChild(allDispDivs[allDivI]);
  329.   }
  330. }
  331.  
  332. clickMoreComments();
Add Comment
Please, Sign In to add comment