-
Notifications
You must be signed in to change notification settings - Fork 0
/
raffleminer.user.js
82 lines (69 loc) · 2.44 KB
/
raffleminer.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// ==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();
})();