Created
August 31, 2022 03:38
-
-
Save floogulinc/b784a3b152693709ea420878c81228f4 to your computer and use it in GitHub Desktop.
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
const pixivFollows = (async function (userId, private) { | |
const initialCheck = await fetch(`https://www.pixiv.net/ajax/user/${userId}/following?offset=0&limit=1&rest=${private ? 'hide' : 'show'}&lang=en`); | |
const initialJson = await initialCheck.json(); | |
const total = initialJson.body.total; | |
let users = []; | |
const numPerGet = 100; | |
console.log(`total private following ${total}`) | |
for(let i = 0; i < total; i += numPerGet) { | |
console.log(`getting follows ${i} to ${Math.min(i + numPerGet, total)}`); | |
const newCheck = await fetch(`https://www.pixiv.net/ajax/user/${userId}/following?offset=${i}&limit=${numPerGet}&rest=${private ? 'hide' : 'show'}&lang=en`); | |
const newJson = await newCheck.json(); | |
const newUsers = newJson.body.users.map(({userId, userName}) => ({userId, userName})); | |
console.log(`found ${newUsers.length} users`); | |
users = users.concat(newUsers); | |
} | |
console.log(`got ${users.length} users total`); | |
console.log(users); | |
let dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(users, null, 2)); | |
let downloadAnchorNode = document.createElement('a'); | |
downloadAnchorNode.setAttribute('href', dataStr); | |
downloadAnchorNode.setAttribute('download', `pixiv-follows-${private ? 'private' : 'public'}-${userId}.json`); | |
downloadAnchorNode.click(); | |
downloadAnchorNode.remove(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment