* Initial work for streaming app shell way of using serviceworkers * Close in on serviceworker adjustment finalization * Add docs and loading indicator * Remove useless code * Don't run on API * Update app/javascript/contentDisplayPolicy/hideBlockedContent.js * Fix small details * Don't run serviceworker.js code in test env * Fix JS in serviceworker * Move private keyword to proper place in async controller * Change shell_version to HEROKU_SLUG_COMMIT * Update caching config * Add test for async_info/shell_version
27 lines
948 B
JavaScript
27 lines
948 B
JavaScript
export default function hideBlockedContent() {
|
|
const contentUserElements = Array.from(
|
|
document.querySelectorAll('div[data-content-user-id]'),
|
|
);
|
|
const user = userData(); //global var
|
|
const blockedUserIds = user ? user.blocked_user_ids : [];
|
|
|
|
const divsToHide = contentUserElements.filter(div => {
|
|
const { contentUserId } = div.dataset;
|
|
return blockedUserIds.includes(parseInt(contentUserId, 10));
|
|
});
|
|
|
|
divsToHide.forEach(div => {
|
|
if (div.className.includes('single-article')) {
|
|
div.style.display = 'none';
|
|
} else if (div.className.includes('single-comment-node')) {
|
|
const divInnerComment = div.querySelector('div.inner-comment');
|
|
divInnerComment.innerHTML = `
|
|
<div class="body " style="padding-bottom:32px;opacity:0.3;user-select:none;cursor:default">
|
|
[blocked content]
|
|
</div>
|
|
`;
|
|
}
|
|
});
|
|
}
|
|
|
|
window.addEventListener('checkBlockedContent', hideBlockedContent);
|