Skip to content

Instantly share code, notes, and snippets.

@rinsuki
Created April 16, 2020 09:33
Show Gist options
  • Save rinsuki/426a59e5427ad7d92169acf2b1403181 to your computer and use it in GitHub Desktop.
Save rinsuki/426a59e5427ad7d92169acf2b1403181 to your computer and use it in GitHub Desktop.
// Please paste to browser console
(async () => {
const listIdRe = /\/web\/timelines\/list\/([0-9]+)/g.exec(location.pathname)
if (listIdRe == null) throw "Please open timeline of target list"
const listId = listIdRe[1]
const initialState = JSON.parse(document.getElementById("initial-state").innerText)
const token = initialState.meta.access_token
const myUserID = initialState.meta.me
const headers = { Authorization: "Bearer " + token }
var next = ""
do {
const res = await fetch("/api/v1/accounts/" + myUserID + "/following" + next, {
headers,
})
if (res.status >= 400) throw await addRes.text()
const accounts = await res.json()
const addRes = await fetch("/api/v1/lists/" + listId + "/accounts", {
method: "POST",
body: JSON.stringify({
account_ids: accounts.map(a => a.id),
}),
headers: {
...headers,
"Content-Type": "application/json"
},
})
if (addRes.status >= 400) throw await addRes.text()
const next_ = /(\?max_id=.+?)>/.exec(res.headers.get("Link"))
next = next_ == null ? "" : next_[1]
} while(next !== "")
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment