Last active
August 29, 2015 14:05
-
-
Save mythmon/1a0c7a00e722e3aac530 to your computer and use it in GitHub Desktop.
Scratchpad user script for http://particle-clicker.web.cern.ch/particle-clicker/#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var output = document.querySelector('#-debug-output'); | |
if (!output) { | |
output = document.createElement('div'); | |
output.style.position = 'absolute'; | |
output.style.left = '30vw'; | |
output.style.bottom = 0; | |
document.body.appendChild(output); | |
output.setAttribute('id', '-debug-output'); | |
} | |
var dataPS = 1; | |
var fundPS = 1; | |
function findNum(s, name) { | |
var match = s.match(new RegExp('(\\d+(.\\d+)?)([kM]?) ?' + name)); | |
if (!match) { | |
throw new Error('"' + s + '" did not have number tagged ' + name + ' in it'); | |
} | |
var num = parseFloat(match[1]); | |
var mult = {k: 1e3, M: 1e6}[match[3]] || 1; | |
return num * mult; | |
} | |
var researchEls = document.querySelectorAll('#Research .media:not(.ng-hide)'); | |
var hrEls = document.querySelectorAll('#HR .media:not(.ng-hide)'); | |
function update() { | |
var dataPSEl = document.querySelector('#update-data .update-plus'); | |
if (dataPSEl) { | |
dataPS = findNum(dataPSEl.textContent, ''); | |
} | |
var fundPSEl = document.querySelector('#update-funding .update-plus'); | |
if (fundPSEl) { | |
fundPS = findNum(fundPSEl.textContent, ''); | |
} | |
var research = Array.prototype.map.call(researchEls, function(elem) { | |
return { | |
name: elem.querySelector('.media-heading').textContent, | |
cost: findNum(elem.querySelector('button').textContent, 'data'), | |
delta: findNum(elem.querySelector('p').textContent, 'reputation'), | |
}; | |
}).map(function(res) { | |
res.value = (fundPS + res.delta) / res.cost; | |
return res; | |
}); | |
var hr = Array.prototype.map.call(hrEls, function(elem) { | |
return { | |
name: elem.querySelector('.media-heading').textContent, | |
cost: findNum(elem.querySelector('button').textContent, ''), | |
delta: findNum(elem.querySelector('p').textContent, 'data'), | |
}; | |
}).map(function(res) { | |
res.value = (dataPS + res.delta) / res.cost; | |
return res; | |
}); | |
research.sort(function(a, b) { | |
return b.value - a.value; | |
}); | |
hr.sort(function(a, b) { | |
return b.value - a.value; | |
}); | |
output.innerHTML = ''; | |
output.innerHTML += research.map(function(res) { | |
return (res.value * 1e6).toPrecision(3) + ' || ' + res.name; | |
}).join('<br>'); | |
output.innerHTML += '<hr>'; | |
output.innerHTML += hr.map(function(res) { | |
return (res.value * 1e6).toPrecision(3) + ' || ' + res.name; | |
}).join('<br>'); | |
} | |
clearInterval(window.monsterInterval); | |
window.monsterInterval = setInterval(update, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment