yoharnu / Goodreads Giveaway Script

// ==UserScript==
// @name         Goodreads Giveaway Script
// @namespace    yoharnuGoodreads
// @version      0.2
// @description  Automatically do the last step of giveaway entry
// @author       yoharnu
// @match        http*://www.goodreads.com/giveaway/enter_*_giveaway/*
// @match http*://www.goodreads.com/giveaway/show/*
// @match http*://www.goodreads.com/book/show/*
// @downloadurl https://openuserjs.org/install/yoharnu/Goodreads_Giveaway_Script.user.js
// @copyright 2019, yoharnu (https://openuserjs.org/users/yoharnu)
// @license MIT
// @grant        none
// ==/UserScript==

(function () {
  'use strict';
  if (window.location.href.indexOf("goodreads.com/giveaway/show/") > -1) {
    var bookURL = document.getElementsByClassName('bookTitle')[0].getAttribute('href');
    window.location.href = bookURL;
  }
  else if (window.location.href.indexOf("goodreads.com/book/show/") > -1) {
    if (document.referrer.indexOf("goodreads.com/giveaway/show/") > -1) {
      var forms = document.getElementsByTagName('form');
      for (var i = 0; i < forms.length; i++) {
        var action = forms[i].getAttribute('action');
        console.log(action);
        if (action.indexOf("/review/destroy/") > -1) {
          forms[i].submit();
          break;
        }
      }
    }
  }
  else {
    var termsCheckbox = document.getElementById('termsCheckBox');
    termsCheckbox.checked = true;
    document.entry_form.submit();
  }
})();