Raffleminer.com throttle script

Automatically throttle raffleminer.com's CPU mining speed

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Raffleminer.com throttle script
// @namespace    jasonheecs
// @version      1.2
// @description  Automatically throttle raffleminer.com's CPU mining speed
// @author       Jason Hee
// @license      MIT
// @include https://www.raffleminer.com/
// @grant   GM_getValue
// @grant   GM_setValue
// @grant   GM_registerMenuCommand
// ==/UserScript==

(function () {
  'use strict';

  /**
     * Set a tampermonkey script's variable to be user definable
     * @param  {string} varName
     * @param  {*} defaultVal
     * @param  {Function} parseFunc
     * @return {Function}
     */
  function makeUserModifiable (varName, defaultVal, parseFunc) {
    if (typeof parseFunc !== 'function') {
      parseFunc = function (a) { return a; };
    }

    var currentVal = GM_getValue(varName, defaultVal);
    GM_registerMenuCommand('Set variable ' + varName, function () {
      var val = window.prompt('Value for ' + varName, currentVal);
      GM_setValue(varName, val);
      window.location.reload();
    });

    return parseFunc(currentVal);
  }

  /**
     * Observe mutation changes for a dom element
     * @param  {Node}   domEl
     * @param  {Function} callback
     */
  function observeNode (domEl, callback) {
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;

    var observer = new MutationObserver(function (mutationsList) {
      for (var mutation of mutationsList) {
        callback(mutation, domEl);
      }
    });

    observer.observe(domEl, { characterData: false, attributes: false, childList: true, subtree: false });
  }

  var $ = function (selector) {
    return document.getElementById(selector) || document.querySelector(selector);
  };

  var nanoWalletAddress = makeUserModifiable('nanoWalletAddress', '');
  var maxMiningSpeed = makeUserModifiable('maxMiningSpeed', '10', parseInt);
  var toggleMiningEl = $('toggle-mining');
  var decreaseMiningSpeedEl = $('throttle-dec');

  if (!nanoWalletAddress.length) {
    return;
  }

  $('nano_account').value = nanoWalletAddress;

  toggleMiningEl.addEventListener('click', function () {
    observeNode($('mine-status'), function (mutation) {
      if (mutation.addedNodes.length && mutation.addedNodes[0].data === 'You are generating hashes, good luck in the raffle!') {
        while (parseInt($('mine-throttle').textContent) > maxMiningSpeed) {
          decreaseMiningSpeedEl.click();
        }
      }
    });
  });

  toggleMiningEl.click();
})();