Created
April 16, 2020 09:33
-
-
Save rinsuki/426a59e5427ad7d92169acf2b1403181 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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