From 24c056c9626f4ed06a0388d238cfcf884f9e13ba Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Mon, 31 Aug 2020 02:44:47 -0400 Subject: [PATCH] shadowban for reddit --- .../rule/social/block/site/Reddit.js.hbs | 110 ++++++++++++++++++ .../reddit/bubbleApp_userBlock_reddit.json | 19 +++ .../bubbleApp_userBlock_reddit_matchers.json | 15 +++ .../models/manifest-app-user-block.json | 4 +- 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 bubble-server/src/main/resources/bubble/rule/social/block/site/Reddit.js.hbs create mode 100644 bubble-server/src/main/resources/models/apps/user_block/reddit/bubbleApp_userBlock_reddit.json create mode 100644 bubble-server/src/main/resources/models/apps/user_block/reddit/bubbleApp_userBlock_reddit_matchers.json diff --git a/bubble-server/src/main/resources/bubble/rule/social/block/site/Reddit.js.hbs b/bubble-server/src/main/resources/bubble/rule/social/block/site/Reddit.js.hbs new file mode 100644 index 00000000..473d5256 --- /dev/null +++ b/bubble-server/src/main/resources/bubble/rule/social/block/site/Reddit.js.hbs @@ -0,0 +1,110 @@ +{{JS_PREFIX}}_supports_keywords = true; + {{JS_PREFIX}}_idle_interval = 10000; + +const {{JS_PREFIX}}_site_host = location.protocol + '//' + window.location.hostname + '/'; + +let {{JS_PREFIX}}_first = true; + +function {{JS_PREFIX}}_create_block_control(comment, authorName) { + const imgHolder = {{JS_PREFIX}}_create_block_img(); + const blockSpan = document.createElement('span'); + const blockLink = document.createElement('a'); + blockLink.style.zIndex = '{{APP_CONTROLS_Z_INDEX}}' + blockLink.style.cursor = 'pointer'; + blockLink.addEventListener("click", function (e) { + {{JS_PREFIX}}_remove_comment(comment); + {{JS_PREFIX}}_block_user(authorName); + e.stopPropagation(); + e.preventDefault(); + return false; + }); + blockLink.appendChild(imgHolder); + blockSpan.appendChild(document.createTextNode('\u00A0\u00A0')); + blockSpan.appendChild(blockLink); + blockSpan.id = 'blockSpan_'+{{JS_PREFIX}}_uuidv4(); + // console.log('adding block control on '+authorName); + return blockSpan; +} + +function {{JS_PREFIX}}_remove_comment(comment) { + let paddingLeft = comment.parentNode && comment.parentNode.style ? comment.parentNode.style.paddingLeft : null; + if (paddingLeft && paddingLeft.endsWith('px')) { + paddingLeft = paddingLeft.substring(0, paddingLeft.length-2); + } else { + return; + } + let commentWrapper = comment.parentNode.parentNode.parentNode; + let wrappersToRemove = [commentWrapper]; + let nextCommentWrapper = commentWrapper.nextElementSibling ? commentWrapper.nextElementSibling : null; + while (nextCommentWrapper !== null) { + const nextPadding = Array.from(nextCommentWrapper.getElementsByTagName('div')) + .find(w => w.style && w.style.paddingLeft && w.style.paddingLeft.length && w.style.paddingLeft.length > 0 && w.style.paddingLeft.endsWith('px')); + if (nextPadding) { + console.log('nextPadding.style.paddingLeft='+nextPadding.style.paddingLeft+', nextPadding.style.paddingLeft.substring(nextPadding.style.paddingLeft.length-2) ='+nextPadding.style.paddingLeft.substring(0, nextPadding.style.paddingLeft.length-2)); + const nextPadAmount = parseInt(nextPadding.style.paddingLeft.substring(0, nextPadding.style.paddingLeft.length-2)); + if (nextPadAmount > paddingLeft) { + console.log('startPad='+paddingLeft+', nextPadAmount='+nextPadAmount+', adding wrapper to remove'); + wrappersToRemove.push(nextCommentWrapper); + nextCommentWrapper = nextCommentWrapper.nextElementSibling ? nextCommentWrapper.nextElementSibling : null; + } else { + console.log('startPad='+paddingLeft+', nextPadAmount='+nextPadAmount+', stopping removals'); + break; + } + } else { + break; + } + } + wrappersToRemove.forEach(w => w.parentNode.removeChild(w)); +} + +function {{JS_PREFIX}}_apply_blocks(blocked_users) { + const first = {{JS_PREFIX}}_first; + let currentUser = null; + try { + currentUser = Array.from(document.getElementsByClassName('header-user-dropdown')[0].getElementsByTagName('span'))[3].innerText; + } catch (e) { + // console.log('no current user'); + } + + const userPrefix = {{JS_PREFIX}}_site_host + 'user/'; + const authors = Array.from(document.getElementsByTagName('a')).filter(a => a.href.indexOf('/user/') !== -1); + authors.forEach(author => { + let authorName = author.href; + if (!authorName.startsWith(userPrefix)) return; + authorName = authorName.substring(userPrefix.length); + if (authorName.endsWith('/')) authorName = authorName.substring(0, authorName.length-1); + + let node = author.parentNode; + let comment = null; + for (let i=0; i<4; i++) { + if (node.parentNode === null) break; + node = node.parentNode; + if (node.className.indexOf(' Comment ') !== -1) { + comment = node; + break; + } + } + if (comment === null || comment.parentNode === null) return; + const firstEval = comment.className.indexOf('{{JS_PREFIX}}_bubble_evaluated') === -1; + if (firstEval) { + comment.className = comment.className + ' {{JS_PREFIX}}_bubble_evaluated'; + } + const authorBlocked = authorName in blocked_users; + if (authorBlocked || {{JS_PREFIX}}_includes_block_keyword(comment, firstEval)) { + if (authorBlocked) { + {{JS_PREFIX}}_tally_author_block(authorName); + if (!firstEval) {{JS_PREFIX}}_untally_allow(); + } + {{JS_PREFIX}}_remove_comment(comment); + return; + } + + if (author.className.indexOf('{{JS_PREFIX}}_bubble_has_icon') === -1) { + let b = {{JS_PREFIX}}_create_block_control(comment, authorName); + author.className = author.className + ' {{JS_PREFIX}}_bubble_has_icon'; + author.parentNode.insertBefore(b, author); + {{JS_PREFIX}}_tally_allow(); + } + }); + if (authors.length > 0) {{JS_PREFIX}}_first = false; +} diff --git a/bubble-server/src/main/resources/models/apps/user_block/reddit/bubbleApp_userBlock_reddit.json b/bubble-server/src/main/resources/models/apps/user_block/reddit/bubbleApp_userBlock_reddit.json new file mode 100644 index 00000000..64c21717 --- /dev/null +++ b/bubble-server/src/main/resources/models/apps/user_block/reddit/bubbleApp_userBlock_reddit.json @@ -0,0 +1,19 @@ +[{ + "name": "UserBlocker", + "children": { + "AppSite": [{ + "name": "Reddit", + "url": "https://reddit.com", + "description": "Reddit is home to thousands of communities, endless conversation, and authentic human connection", + "template": true + }], + "AppRule": [{ + "name": "reddit_user_blocker", + "template": true, + "driver": "JsUserBlockerRuleDriver", + "config": { + "siteJsTemplate": "bubble/rule/social/block/site/Reddit.js.hbs" + } + }] + } +}] \ No newline at end of file diff --git a/bubble-server/src/main/resources/models/apps/user_block/reddit/bubbleApp_userBlock_reddit_matchers.json b/bubble-server/src/main/resources/models/apps/user_block/reddit/bubbleApp_userBlock_reddit_matchers.json new file mode 100644 index 00000000..e47d3cad --- /dev/null +++ b/bubble-server/src/main/resources/models/apps/user_block/reddit/bubbleApp_userBlock_reddit_matchers.json @@ -0,0 +1,15 @@ +[{ + "name": "UserBlocker", + "children": { + "AppMatcher": [{ + "name": "RedditMatcher", + "site": "Reddit", + "template": true, + "requestCheck": true, + "requestModifier": true, + "fqdn": "www.reddit.com", + "urlRegex": "/r/.+", + "rule": "reddit_user_blocker" + }] + } +}] diff --git a/bubble-server/src/main/resources/models/manifest-app-user-block.json b/bubble-server/src/main/resources/models/manifest-app-user-block.json index fd7e07f6..49e14659 100644 --- a/bubble-server/src/main/resources/models/manifest-app-user-block.json +++ b/bubble-server/src/main/resources/models/manifest-app-user-block.json @@ -14,5 +14,7 @@ "apps/user_block/fb/bubbleApp_userBlock_fb_data", "apps/user_block/insta/bubbleApp_userBlock_insta", "apps/user_block/insta/bubbleApp_userBlock_insta_matchers", - "apps/user_block/insta/bubbleApp_userBlock_insta_data" + "apps/user_block/insta/bubbleApp_userBlock_insta_data", + "apps/user_block/reddit/bubbleApp_userBlock_reddit", + "apps/user_block/reddit/bubbleApp_userBlock_reddit_matchers" ] \ No newline at end of file