Luke Childs
6 years ago
7 changed files with 21 additions and 18 deletions
@ -1,15 +1,17 @@ |
|||
import camelcase from 'camelcase'; |
|||
import getData from './get-data'; |
|||
|
|||
const preloadData = () => { |
|||
// Get all usernames we can find with data-screen-name
|
|||
const usernames = [...document.querySelectorAll('[data-screen-name]')] |
|||
.map(element => element.dataset.screenName); |
|||
|
|||
// Also scrape usernames from mentions and other user id links
|
|||
const linkUsernames = [...document.querySelectorAll('a[data-user-id], a[data-mentioned-user-id]')] |
|||
.map(a => a.href.split('/').pop()); |
|||
const scrapeDataAttribute = dataAttribute => { |
|||
return [...document.querySelectorAll(`[data-${dataAttribute}]`)].map(el => { |
|||
return el.dataset[camelcase(dataAttribute)]; |
|||
}); |
|||
}; |
|||
|
|||
new Set([...usernames, ...linkUsernames]).forEach(getData); |
|||
const preloadData = () => { |
|||
new Set([ |
|||
...scrapeDataAttribute('user-id'), |
|||
...scrapeDataAttribute('mention-user-id'), |
|||
]).forEach(getData); |
|||
}; |
|||
|
|||
export default preloadData; |
|||
|
Loading…
Reference in new issue