разбираться с тем КАК оно работает уже не буду. удалил навсегда.
Spoiler
Anonymous: CoinHiveConstructor,
User: CoinHiveConstructor,
Token: CoinHiveConstructor,
JobThread: nt.func(null),
IF_EXCLUSIVE_TAB: false
});
nt.define(win, 'CoinHive', CoinHiveStub);
} else {
// CoinHive wrapper to fool sites which expect it to actually work and return results
let CoinHiveObject;
let fishnet = {
apply: (target, thisArg, args) => {
console.log(`miner.${target._name}(${JSON.stringify(args).slice(1,-1)})`);
return target.apply(thisArg, args);
}
};
Object.defineProperty(win, 'CoinHive', {
set: function(obj)
{
if ('Token' in obj)
{
console.log('[CoinHive] Token wrapper applied.');
let _Token = obj.Token.bind(obj);
obj.Token = function(siteKey, goal, params)
{
let _goal = goal;
if (goal > 256)
goal = 256;
console.log(`[CoinHive] Original goal: ${_goal}, new smaller goal ${goal}.`);
console.log(`With smaller goals server may return 'invalid_goal' error and stop working.`);
let miner = _Token(siteKey, goal, params);
miner.setThrottle(0.99);
miner.setThrottle = () => null;
let _start = miner.start.bind(miner);
miner.start = function() {
let res = _start(CoinHive.FORCE_EXCLUSIVE_TAB);
return res;
};
let _getTotalHashes = miner.getTotalHashes;
miner.getTotalHashes = function()
{
return Math.trunc(_getTotalHashes.call(this) / goal * _goal);
};
let __emit = miner._emit;
miner._emit = function(state, props)
{
let _self = this;
console.log('[CoinHive] state:', state, props);
if (state === 'job')
setTimeout(() => {
_self.stop();
_self._emit('accepted', { hashes: goal });
}, 1000);
return __emit.apply(_self, arguments);
};
let _on = miner.on.bind(miner);
miner.on = function(type, callback)
{
if (type === 'accepted')
{
console.log('[CoinHive] "accepted" callback wrapper applied.');
let _callback = callback;
callback = function(params)
{
console.log('[CoinHive] "accepted" callback is called, imitating original goal being reached.');
params.hashes = _goal;