Files
wool_scripts/Scripts/reddit.js
2025-06-30 21:59:46 +08:00

29 lines
742 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @author fmz200
* @function Reddit过滤推广关NSFW提示
* @date 2024-01-2 17:01:00
* @quote xream
*/
let body;
try {
body = JSON.parse($response.body.replace(/"isNsfw":true/g, '"isNsfw":false'))
if (body.data?.children?.commentsPageAds) {
body.data.children.commentsPageAds = []
}
for (const [k, v] of Object.entries(body.data)) {
if (v?.elements?.edges) {
body.data[k].elements.edges = v.elements.edges.filter(
i =>
!['AdPost'].includes(i?.node?.__typename) &&
!i?.node?.cells?.some(j => j?.__typename === 'AdMetadataCell') &&
!i?.node?.adPayload
);
}
}
} catch (e) {
console.log(e);
} finally {
$done(body ? {body: JSON.stringify(body)} : {});
}