-
Notifications
You must be signed in to change notification settings - Fork 2
/
reddit.js
28 lines (28 loc) · 955 Bytes
/
reddit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
let modified;
let body;
try {
body = JSON.parse($response.body.replace(/\"isNsfw\"/gi, '"_isNsfw"'));
if (body?.data?.subredditInfoByName?.elements?.edges) {
body.data.subredditInfoByName.elements.edges =
body.data.subredditInfoByName.elements.edges.filter(
i => i?.node?.__typename !== 'AdPost'
);
modified = true;
} else if (body?.data?.home?.elements?.edges) {
body.data.home.elements.edges = body.data.home.elements.edges.filter(
i => i?.node?.__typename !== 'AdPost'
);
modified = true;
} else if (body?.data?.homeV3?.elements?.edges) {
body.data.homeV3.elements.edges = body.data.homeV3.elements.edges.filter(
i => !i?.node?.cells?.some(j => j?.__typename === 'AdMetadataCell')
);
modified = true;
} else if ($response.body.includes('"isNsfw"')) {
modified = true;
}
} catch (e) {
console.log(e)
} finally {
$done(modified ? { body: JSON.stringify(body) } : {});
}