usrxprd

nab_voting.js

Apr 15th, 2022
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*==========================================================
  2.     Notabug voting script
  3.     ----------------------------------------------------
  4.  
  5.     USAGE
  6.  
  7.      - Read the comments.
  8.      - Adjust variables as needed.
  9.      - Run in browser console.
  10.  
  11.     Helped as an example:
  12.  
  13.     https://notabug.io/t/userscripts/comments/c8fb995bc7e3411d314d904754e9a017832286b6/
  14. ==========================================================*/
  15.  
  16. /* the number of times to vote */
  17. var times = 10;
  18.  
  19. /* The time in milliseconds between each vote.
  20.    Sometimes if the voting is too slow, some errors would occur and less votes
  21.    than specified would be given, so set this interval to something higher if
  22.    that happens. */
  23. var interval_ms = 5000;
  24.  
  25. /* The index number of the target upvote button in the array of upvote buttons
  26.    present on page. This value must be changed if the target upvote button index
  27.    isn't correct. The following call will return the array:
  28.  
  29.     document.getElementsByClassName("arrow up login-required access-required");
  30.  
  31.    Some browsers will show you the location of each element on screen when you
  32.    hover the pointer over the returned array elements in the console.
  33.  
  34.    The reason the default is set to 25 is because there will usually be 26
  35.    upvote buttons on screen once you load a post with no comments present. The
  36.    post's upvote button in this case should be the last in the array. 25 of
  37.    these buttons are present in chat, so the array will increase once more chat
  38.    messages are loaded. */
  39. var up_button_index = 25;
  40.  
  41. /* calls the click function at specified intervals */
  42. var intID = setInterval(
  43.     function(){
  44.         /* simulate click on the upvote button */
  45.         document.getElementsByClassName("arrow up login-required access-required")[up_button_index].click();
  46.     },
  47.     interval_ms
  48. );
  49.  
  50. /* sets the timeout before executing clearInterval, which would stop the
  51.    execution of the clicking function */
  52. setTimeout(
  53.     function(){
  54.         clearInterval(intID);
  55.     },
  56.     ((times+1)*interval_ms)
  57. );
Advertisement
Add Comment
Please, Sign In to add comment