Last active
May 17, 2021 10:36
-
-
Save gkucmierz/55c82784ece4744d2908e465f0815aec to your computer and use it in GitHub Desktop.
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 silent = false; | |
| var mute = () => silent = true; | |
| var unmute = () => silent = false; | |
| var loop = () => { | |
| const play = (frequency = 300, duration = 1e3) => { | |
| const context = new AudioContext(); | |
| const gainNode = context.createGain(); | |
| const oscillator = context.createOscillator(); | |
| oscillator.frequency.value = frequency; | |
| oscillator.connect(gainNode); | |
| gainNode.connect(context.destination); | |
| oscillator.start(0); | |
| setTimeout(() => oscillator.stop(), duration); | |
| }; | |
| const expand = () => { | |
| [...document.querySelectorAll('button')].filter(b => b.innerText === 'Manage').map(btn => { | |
| const isOpen = btn.parentNode.parentNode.parentNode.querySelectorAll('button').length > 1; | |
| if (!isOpen) btn.click(); | |
| }); | |
| }; | |
| try { | |
| const SEPARATOR = '/'; | |
| const USDC = 'USDC'; | |
| const USDT = 'USDT'; | |
| const DAI = 'DAI'; | |
| const pairs = [ | |
| [USDC, USDT].join(SEPARATOR), | |
| [USDC, DAI].join(SEPARATOR), | |
| [DAI, USDT].join(SEPARATOR) | |
| ]; | |
| const getPooled = (parent = document, coin = 'USDC') => { | |
| const label = [...parent.querySelectorAll('div')].filter(d => d.innerHTML === `Pooled ${coin}:`)[0]; | |
| return +label.parentNode.parentNode.querySelectorAll('div')[3].innerText; | |
| } | |
| const r = (n, prec = 2) => n.toFixed(prec); | |
| expand(); | |
| let sound = false; | |
| console.log('-'.repeat(80)); | |
| const data = pairs.map(pair => { | |
| try { | |
| const div = [...document.querySelectorAll('div')].filter(d => d.innerHTML === pair)[0]; | |
| const parent = div.parentNode.parentNode.parentNode; | |
| const [a, b] = pair.split(SEPARATOR) | |
| const da = getPooled(parent, a); | |
| const db = getPooled(parent, b); | |
| const sum = da + db; | |
| const geoSum = Math.sqrt(da * db) * 2; | |
| const ratio = da / db; | |
| const inef = Math.abs(1 - ratio) * 100; | |
| console.log(`${pair}: ${r(ratio, 4)} | sum: ${r(sum)} | geoSum: ${r(geoSum)} | inef: ${r(inef)}`); | |
| if (inef > 0.8) sound = true; | |
| } catch (e) { } | |
| // return [pair, sum, geoSum, ratio, inef]; | |
| }); | |
| // console.table(data);//, ['pair', 'sum', 'geoSum', 'ratio', 'inef']); | |
| sound && !silent && play(); | |
| } catch (e) { | |
| console.error('cant read data'); | |
| } | |
| } | |
| setInterval(loop, 1e4); | |
| loop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment