Skip to content

Instantly share code, notes, and snippets.

@mcxiaoke
Last active September 5, 2022 13:46
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 mcxiaoke/f0def81f600c93d2d5ee6ab713214df0 to your computer and use it in GitHub Desktop.
Save mcxiaoke/f0def81f600c93d2d5ee6ab713214df0 to your computer and use it in GitHub Desktop.
Pixiv Follow All Users on Page
// https://levelup.gitconnected.com/how-to-load-external-javascript-files-from-the-browser-console-8eb97f7db778
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
const randint = (max) => Math.floor(Math.random() * max)
async function getDiscoveryData() {
const resp = await fetch(
'https://www.pixiv.net/ajax/discovery/artworks?mode=all&limit=100&lang=zh',
{
headers: {
accept: 'application/json',
'accept-language': 'zh-CN,zh;q=0.9',
'sec-ch-ua':
'".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'x-user-id': '22273488',
},
referrer: 'https://www.pixiv.net/discovery?mode=all',
referrerPolicy: 'strict-origin-when-cross-origin',
body: null,
method: 'GET',
mode: 'cors',
credentials: 'include',
}
)
}
async function getUserInfo(uid) {
const resp = await fetch(
`https://www.pixiv.net/ajax/user/${uid}?full=1&lang=zh`,
{
headers: {
accept: 'application/json',
'accept-language': 'zh-CN,zh;q=0.9',
'sec-ch-ua':
'".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'x-user-id': '22273488',
},
referrer: 'https://www.pixiv.net/discovery',
referrerPolicy: 'strict-origin-when-cross-origin',
body: null,
method: 'GET',
mode: 'cors',
credentials: 'include',
}
)
if (resp && resp.ok) {
return await resp.json()
}
}
async function followUser(uid) {
const resp = await fetch('https://www.pixiv.net/bookmark_add.php', {
headers: {
accept: 'application/json',
'accept-language': 'zh-CN,zh;q=0.9',
'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
'sec-ch-ua':
'".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'x-csrf-token': '4df277440653e923275dc9d0c5609b44',
},
referrer: 'https://www.pixiv.net/discovery',
referrerPolicy: 'strict-origin-when-cross-origin',
body: `mode=add&type=user&user_id=${uid}&tag=&restrict=0&format=json`,
method: 'POST',
mode: 'cors',
credentials: 'include',
})
// resp &&
// resp.ok &&
// console.log(`success follow user ${uid} ${await resp.text()}`)
}
async function followAll() {
let links = [...document.querySelectorAll('a')].filter((x) =>
x.href.includes('/users/')
)
let users = links.map((x) => x.href.split('/').pop())
users = [...new Set(users)]
let c = 0
console.log(`[info] follow all start [${users.length}]`)
for (let index = 0; index < users.length; index++) {
const uid = users[index]
const d = await getUserInfo(uid)
if (d && d.body) {
const need = !d.body.isFollowed
if (need) {
console.log(
`[info] follow ${d.body.name} ${d.body.userId} ${++c} ${index}/${
users.length
}`
)
await followUser(uid)
} else {
console.log(
`--- ${d.body.name} ${d.body.userId} ${index}/${users.length}`
)
}
}
await sleep(100 + randint(200))
}
console.log(`[info] follow all done [${c}/${users.length}]`)
}
/***
let resp = await fetch("https://gist.githubusercontent.com/mcxiaoke/f0def81f600c93d2d5ee6ab713214df0/raw/90ccf3bc600380d76787dac6a510f3fa577b902c/pixiv-follow-all.js")
let text = await resp.text()
//eval(text)
Function(text)
await followAll()
***/
@mcxiaoke
Copy link
Author

mcxiaoke commented Sep 2, 2022

clear()
let resp = await fetch("https://gist.github.com/mcxiaoke/f0def81f600c93d2d5ee6ab713214df0/raw/baa35c665940f6aa8a14e6e9c7700debc6cba267/pixiv-follow-all.js", {mode: 'no-cors', cache: 'no-cache'})
eval(await resp.text())
await followAll()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment