Goodreads_Giveaway_Autonomous

This script will Auto-click "Enter Giveaway".

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Goodreads_Giveaway_Autonomous
// @namespace    https://greasyfork.org/en/scripts/431707-goodreads-giveaway-autonomous
// @version      1.06
// @description  This script will Auto-click "Enter Giveaway".
// @author       Davinna Mayawen
// @icon         https://media.tenor.com/images/e5b48218f76d06c730cae7f2928ad2c7/tenor.gif
// @include      *www.goodreads.com/giveaway*
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @license      https://opensource.org/licenses/MIT
// @copyright    Davinna Mayawen 2021
//=======================================================================================
// ==/UserScript==

$(document).ready(function () {
  //document variables
  var url;
  var $giveawayButtons = [];
  let giveawayButtonTimeout = 2000; //giveawayButtonTimeout every 2 seconds
  let reloadTimeout = 60000; //reload once a minute
  let lengthTimeout = 2000; //wait for DOM to finish loading the entries 2 seconds

  //change background color
  document.body.style.backgroundColor = "gray";
  $("div.mainContent ").css("background-color", "gray");
  $("div.mainContentFloat ").css("background-color", "gray");

  //===========Auto-click "Enter Giveaway"===========
  //wait for page to load
  window.addEventListener('load', function (event) {
    setTimeout(function() {
      //create the list of "Enter Giveaway" buttons
      $giveawayButtons = $('a.Button.Button--primary.Button--small');

      //delay loop to open Enter Giveaway window
      (function delayLoop(i) {
        setTimeout(function () {
          openWin($giveawayButtons[i - 1].href);
          //  decrement i and call delayLoop again if i > 0
          if (--i) delayLoop(i);
        }, giveawayButtonTimeout); //end giveawayButtonTimeout
        //
        if (i - 1 == 0) {
          setTimeout(function () {
            confirmFunction();
          }, reloadTimeout); //end of reloadTimeout
        }//end of if
      })($giveawayButtons.length); //end of delayLoop
    }, lengthTimeout); //end of lengthTimeout
  }); //end of event listener

  //Enter giveaway actions
  giveawaySelectors('a.addressLink');
  //add a short delay in milliseconds between clicks of terms checkbox
  setInterval(function () { giveawaySelectors('#termsCheckBox'); }, 1200);
  //add a short delay in milliseconds between clicks of check box and submit button
  setInterval(function () { giveawaySelectors('#giveawaySubmitButton'); }, 1000);

  //close enty windows once completed
  url = window.location.href;
  if (url != 'https://www.goodreads.com/giveaway?sort=ending_soon&format=print' && (($(".mediumTextBottomPadded:contains('You are entered to win.')").length > 0 || $('a.gr-button').length))) {
    window.close();
  };

});//end of .ready

//search all non-zero selectors
function giveawaySelectors(selector) {
  var x = $(selector);
  if (x.length > 0) {
    x[0].click();
  }
}

//open new window
function openWin(href) {
  window.open(href, "_blank", "left=1500,top=100,width=600,height=300");
}

//confirm function
function confirmFunction() {
  var r = confirm("Click 'OK' to reload Page");
  if (r == true) {
    location.reload();
  }
  else {
    return;
  }
}