Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CleanFeed: Add option to treat specified tags as mature #1185

Merged
merged 11 commits into from
Aug 20, 2023
16 changes: 11 additions & 5 deletions src/scripts/cleanfeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ const styleElement = buildStyle();
const reblogSelector = keyToCss('reblog');

let blockingMode;
let localFlagging;
let localBlogFlagging;
let localTagFlagging;
let localFlaggedBlogs;
let localFlaggedTags;

const processPosts = postElements => filterPostElements(postElements).forEach(async postElement => {
if (blockingMode === 'all') {
postElement.classList.add(hiddenClass);
return;
}

const { blog: { name, isAdult }, communityLabels, trail } = await timelineObject(postElement);
const { blog: { name, isAdult }, communityLabels, trail, tags } = await timelineObject(postElement);

if (isAdult || communityLabels.hasCommunityLabel || localFlaggedBlogs.includes(name)) {
if (isAdult ||
communityLabels.hasCommunityLabel ||
localFlaggedBlogs.includes(name) ||
localFlaggedTags.some(t => tags.map(tag => tag.toLowerCase()).includes(t))) {
postElement.classList.add(hiddenClass);
return;
}
Expand All @@ -35,8 +40,9 @@ const processPosts = postElements => filterPostElements(postElements).forEach(as
});

export const main = async function () {
({ blockingMode, localFlagging } = await getPreferences('cleanfeed'));
localFlaggedBlogs = localFlagging.split(',').map(username => username.trim());
({ blockingMode, localBlogFlagging, localTagFlagging } = await getPreferences('cleanfeed'));
localFlaggedBlogs = localBlogFlagging.toLowerCase().split(',').map(username => username.trim());
localFlaggedTags = localTagFlagging.toLowerCase().split(',').map(tag => tag.replaceAll('#', '').trim());

styleElement.textContent = localFlaggedBlogs
.map(username => `[title="${username}"] img[alt="${translate('Avatar')}"] { filter: blur(20px); }`)
Expand Down
10 changes: 8 additions & 2 deletions src/scripts/cleanfeed.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
],
"default": "smart"
},
"localFlagging": {
"localBlogFlagging": {
"label": "Treat these blogs as mature (comma-separated)",
"type": "textarea",
"default": ""
"default": "",
"inherit": "cleanfeed.preferences.localFlagging"
},
"localTagFlagging": {
"label": "Treat these tags as mature (comma-separated)",
"type": "textarea",
"default": "nsfw, nsft"
}
}
}