Last active
September 28, 2020 21:36
-
-
Save simonwjackson/bb463390dce6aa507d29c29e77355e94 to your computer and use it in GitHub Desktop.
Get the average price of a search on ebay
This file contains 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
/************************************************ | |
* Utils | |
************************************************/ | |
const injectScript = url => | |
document.body.appendChild(document.createElement('script')).src = url | |
const querySelectorAllArray = selector => | |
[...document.querySelectorAll(selector)] | |
const execWhenReady = fn => | |
["complete", "interactive"].includes(document.readyState) | |
? fn() | |
: addEventListener("load", fn) | |
/************************************************ | |
* Main | |
************************************************/ | |
const scripts = [ | |
'//cdn.jsdelivr.net/npm/ramda@0.25/dist/ramda.min.js', | |
'//cdnjs.cloudflare.com/ajax/libs/ramda-adjunct/2.28.0/RA.web.min.js' | |
] | |
const main = () => { | |
const nodesToFloats = R.pipe( | |
R.map(x => x.innerText), | |
R.map(R.slice(1, Infinity)), | |
R.map(parseFloat), | |
R.filter(RA.isFloat) | |
) | |
R.pipe( | |
querySelectorAllArray, | |
nodesToFloats, | |
R.mean, | |
RA.round, | |
alert | |
)('.s-item__price .POSITIVE') | |
} | |
scripts.map(injectScript) | |
execWhenReady(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment