Skip to content
Snippets Groups Projects
GreaterGood-CTG-AutoClicker.js 2.85 KiB
Newer Older
Jan's avatar
Jan committed
// ==UserScript==
// @name         GreaterGood CTG AutoClicker
Jan's avatar
Jan committed
// @description  Automatically clicks through all the buttons on all subsites of the GreaterGood ClickToGive program every two hours.
// @description:de Klickt sich automatisch alle zwei Std. durch alle Buttons auf allen Seiten des GreaterGood-ClickToGive-Programms.
Jan's avatar
Jan committed
// @version      1.3.1
Jan's avatar
Jan committed
// @author       Rsge
// @copyright    2021+, Jan G. (Rsge)
// @license      Mozilla Public License 2.0
// @icon         https://http-aws.greatergood.com/img/ggc/favicon-96x96.png

// @namespace    https://github.com/Rsge/GreaterGood-CTG-AutoClicker
// @homepageURL  https://github.com/Rsge/GreaterGood-CTG-AutoClicker
// @supportURL   https://github.com/Rsge/GreaterGood-CTG-AutoClicker/issues

// @match      https://greatergood.com/clicktogive/*
Jan's avatar
Jan committed
// @match      https://greatergood.com/clickToGive/*
// @match      https://*.greatergood.com/clicktogive/*
Jan's avatar
Jan committed
// @match      https://*.greatergood.com/clickToGive/*
Jan's avatar
Jan committed
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Max amount of seconds to wait before clicking button
    const MAX_RANDOM_TO_CLICK_SECONDS = 3;
    // Minutes between possible click-throughs
    // Set to at least 1 min more than minimum time because of random button click delay
    const INTERVAL_MINUTES = 121;


    // Click-To-Give site options
    const SITES = [" Hunger", " Breast Cancer", " Animals", " Veterans", " Autism", " Alzheimer's",
        " Diabetes", " Literacy", " Rainforest", " GreaterGood"];

Jan's avatar
Jan committed

    // On button site, click button
Jan's avatar
Jan committed
    var i;
    var buttons = document.getElementsByTagName("BUTTON");
    var buttonFound = false
Jan's avatar
Jan committed
    for (i = 0; i < buttons.length; i++) {
        var buttonHTML = buttons[i].innerHTML;
        //console.log(buttonHTML);
        if (buttonHTML == "Click to Give - it's FREE!") {
            buttonFound = true
            break
Jan's avatar
Jan committed
        }
    }
    if (buttonFound) {
        var millisecondsToClick = (Math.floor(Math.random() * MAX_RANDOM_TO_CLICK_SECONDS) + 1) * 1000;
        setTimeout(function(){buttons[i].click()}, millisecondsToClick);
        return;
    }
Jan's avatar
Jan committed

    // On thanks site, choose new site if not all are already clicked
Jan's avatar
Jan committed
    var divs = document.getElementsByTagName("DIV");
    for (i = 0; i < divs.length; i++) {
        var divClass = divs[i].className;
        //console.log(divClass);
        if (divClass.includes("-site col-xs-3 col-sm-4 button-to-count") &&
            !divClass.includes("click-more-clickAttempted") &&
            SITES.includes(divs[i].innerText)) {
Jan's avatar
Jan committed
            var link = divs[i].firstElementChild.href;
            //console.log(link);
            window.open(link, "_top");
            return;
        }
    }
Jan's avatar
Jan committed
    // Wait for 2 h, then reload page to click through again
    var intervalMilliseconds = INTERVAL_MINUTES * 60 * 1000;
    setTimeout(function(){location.reload(true);}, intervalMilliseconds);
Jan's avatar
Jan committed
})();