-
-
Save Dzinlife/a0887f4c4a7fd9b979c6d2364e83635e to your computer and use it in GitHub Desktop.
Surge Script - Jellow Display User Followed Status
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
//URL regexp | |
\/\/api\.jellow\.club\/1\.0\/users\/profile | |
if (!follewedList) { | |
var follewedList = new Set() | |
} | |
(($request, $response, $done) => { | |
const JELLOW_ID = 'YOUR_JELLOW_ID' | |
const requestUrl = $request.url | |
const userId = requestUrl.match(/username=([^?#&]*)/)[1] | |
if (userId === JELLOW_ID) { | |
$done({}) | |
return | |
} | |
const body = JSON.parse($response.body) | |
let retryCount = 0 | |
function next(data) { | |
if (retryCount > 5) { | |
$notification.post('retry count exceeded', '', '') | |
abandon() | |
return | |
} | |
const option = { | |
url: 'https://api.jellow.club/1.0/userRelation/getFollowingList', | |
body: { | |
limit: 100, | |
username: userId, | |
loadMoreKey: data && data.loadMoreKey | |
}, | |
headers: requestHeaders // $request.headers not available in response script, set it in a request script and turn on context share | |
} | |
$httpClient.post(option, (err, res, data) => { | |
if (err) { | |
retryCount++ | |
next(data) | |
return | |
} | |
data = JSON.parse(data) | |
if (data.data.find(user => user.id === JELLOW_ID)) { | |
done(true) | |
} else if (data.loadMoreKey) { | |
next(data) | |
} else { | |
done(false) | |
} | |
}) | |
} | |
function done(hasMe) { | |
if (hasMe) { | |
follewedList.add(body.user.id) | |
body.user.screenName += '👀' | |
} | |
$done({ | |
body: JSON.stringify(body) | |
}) | |
} | |
function abandon() { | |
body.user.screenName += '🤷♂️' | |
$done({ | |
body: JSON.stringify(body) | |
}) | |
} | |
if (follewedList.has(body.user.id)) { | |
done(true) | |
} else { | |
next() | |
} | |
})($request, $response, $done) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment