Skip to content

Instantly share code, notes, and snippets.

@floogulinc
Created August 31, 2022 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floogulinc/b784a3b152693709ea420878c81228f4 to your computer and use it in GitHub Desktop.
Save floogulinc/b784a3b152693709ea420878c81228f4 to your computer and use it in GitHub Desktop.
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