13 ms·
This is begging for a console.table console.table([...document.querySelectorAll('.fatitem table .athing')].map(el => [el.textContent.trim(), el.nextSiblin
by toqy 5y ago
This is begging for a console.table
console.table([...document.querySelectorAll('.fatitem table .athing')].map(el => [el.textContent.trim(), el.nextSibling.textContent.trim()]).sort(([,a], [,b]) => parseInt(b) - parseInt(a)))
- gabrielsroka 5y agoMore efficient, uses integers, and sortable in the table: console.table([...document.querySelectorAll('.fatitem table .athing')].map(el => ({place: el.textContent.trim(), score: parseInt(el.nextSibling.textContent)})).sort((a, b) => b.score - a.score))
- gabrielsroka 5y agowith tie breakers console.table([...document.querySelectorAll('.fatitem table .athing')].map(el => ({place: el.textContent.trim(), score: parseInt(el.nextSibling.textContent)})).sort((a, b) => b.score - a.score || a.place.localeCompare(b.place)))
- lhorie 5y agoGood call!
- runjake 5y agoNeat! Noob question: is there a similar way to dump it to JSON, instead of a table?
- chair6 5y agoJust replace console.table with JSON.stringify for the quick-and-easy dump of exactly the same data as is in the table... JSON.stringify([...document.querySelectorAll('.fatitem table .athing')].map(el => [el.textContent.trim(), el.nextSibling.textContent.trim()]).sort(([,a], [,b]) => parseInt(b) - parseInt(a)))
- AntonyGarand 5y agoReplace `console.table` with `JSON.stringify`: JSON.stringify([...document.querySelectorAll('.fatitem table .athing')].map(el => [el.textContent.trim(), el.nextSibling.textContent.trim()]).sort(([,a], [,b]) => parseInt(b) - parseInt(a)))
- deleted 5y ago[deleted]
- gkfasdfasdf 5y agoCurrent top 10: 'US: California' '79 points' 'Canada' '48 points' 'US: Washington' '39 points' 'US: New York' '36 points' 'Germany' '35 points' 'United Kingdom' '34 points' 'US: Massachusetts' '19 points' 'Netherlands' '18 points' 'US: Colorado' '17 points' 'Sweden' '16 points' Colorado #9? Really?
- deleted 5y ago[deleted]
- TulliusCicero 5y agoDenver and Boulder have a good amount of tech. A bit surprised it comes out ahead of Texas though. Also the UK and Germany being about the same is interesting. Germany does have a slightly larger population, but of course the UK is natively English speaking.
- hwc 5y agoTexas is without power at the moment.
- capableweb 5y agoThought you were joking at first, how can an entire state be without power? But seems you're right, how the hell does that happen in a first-world country? Tried to access some dashboards that are supposed to show some data, but not sure if I can't access it because I'm not in the US/Texas or if it's down as well (because they don't have power?) - https://www.ercot.com/gridmktinfo/dashboards https://www.ercot.com/gridmktinfo/dashboards - https://www.ercot.com/gridmktinfo/dashboards/gridconditions https://www.ercot.com/gridmktinfo/dashboards/gridconditions - https://www.ercot.com/gridinfo https://www.ercot.com/gridinfo Says "This request was blocked by the security rules" so I'm assuming it's the former.
- dhosek 5y ago
- mmcnl 5y agoTIL. Cool!
- newaccount74 5y agoI wanted a total for the US: console.table([...document.querySelectorAll('.fatitem table .athing')].map(el => [el.textContent.replace(/:.*/,'').trim(), parseInt(el.nextSibling.textContent.trim())]).reduce((d, [k,v]) => {d[k]=v + (d[k] || 0); return d}, {})) I can't figure out how to sort that, though...
- gabrielsroka 5y agoObject.entries https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- newaccount74 5y agoOh, I need to type Object.entries(x) instead of x.entries() Makes sense, otherwise entries would contain itself. Thank you!
- eyelidlessness 5y agoEntries only iterates enumerable items (unless you make something evil). None of the native types with entries in their prototype iterate over that method
- binarynate 5y agoI created a page with the current results that includes a total for the US: https://nate.org/hacker-news-location-poll https://nate.org/hacker-news-location-poll
- Larrikin 5y agoPercentage next to totals would make this perfect
- binarynate 5y agoGood idea—I just added a percentage column, as well as a row at the bottom for the total count
- gabrielsroka 5y agoIf you're on a mobile browser, paste this into the address bar: javascript:document.write('<table>' + [...document.querySelectorAll('.fatitem table .athing')].map(el => ({place: el.textContent.trim(), score: parseInt(el.nextSibling.textContent)})).sort((a, b) => b.score - a.score || a.place.localeCompare(b.place)).map(e => `<tr><td>${e.place}<td align=right>${e.score}`).join('') + '</table>')
- cardamomo 5y agoThat doesn't seem to work on Firefox for Android, sadly
- gabrielsroka 5y agoSometimes the browser will remove the leading 'javascript'. In that case, type it back in.
- gabrielsroka 5y agoIt doesn't seem to be supported. Ironic that the bookmarklet was invented by them. It works on Chrome for Android.
- zander312 5y agothis is fricking awesome!! thanks!!
- gabrielsroka 5y agoTo see the sorted results: https://gabrielsroka.github.io/hnpoll.html?id=30210378 https://gabrielsroka.github.io/hnpoll.html?id=30210378 Source: https://github.com/gabrielsroka/gabrielsroka.github.io/blob/master/hnpoll.html https://github.com/gabrielsroka/gabrielsroka.github.io/blob/...