From c3d0c71d6bd68f02c2c1c92268c524a53d994d5a Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Fri, 28 Aug 2020 11:49:20 -0400 Subject: [PATCH] show shadowban stats in blockparty control --- .../bblock/BubbleBlockRuleDriver_stats.js.hbs | 32 ++++++++++++++++++- .../block/JsUserBlockerRuleDriver.js.hbs | 18 ++++++++--- .../bubble/rule/social/block/site/FB.js.hbs | 15 +++++---- .../rule/social/block/site/HackerNews.js.hbs | 4 ++- .../bubble/rule/social/block/site/MR.js.hbs | 1 + .../rule/social/block/site/Reason.js.hbs | 1 + .../rule/social/block/site/Twitter.js.hbs | 6 ++-- .../apps/user_block/bubbleApp_userBlock.json | 3 ++ 8 files changed, 65 insertions(+), 15 deletions(-) diff --git a/bubble-server/src/main/resources/bubble/rule/bblock/BubbleBlockRuleDriver_stats.js.hbs b/bubble-server/src/main/resources/bubble/rule/bblock/BubbleBlockRuleDriver_stats.js.hbs index 63f263dd..2444668f 100644 --- a/bubble-server/src/main/resources/bubble/rule/bblock/BubbleBlockRuleDriver_stats.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/bblock/BubbleBlockRuleDriver_stats.js.hbs @@ -4,6 +4,15 @@ let {{JS_PREFIX}}_app_details = false; let {{JS_PREFIX}}_last_stats = null; let {{JS_PREFIX}}_app_stats_last_change = 0; const {{JS_PREFIX}}_app_stats_timeout = 35000; +const {{PAGE_PREFIX}}_extra_blocks = {}; + +const {{PAGE_PREFIX}}_add_extra_block = function(name) { + if (!(name in {{PAGE_PREFIX}}_extra_blocks)) { + {{PAGE_PREFIX}}_extra_blocks[name] = 1; + } else { + {{PAGE_PREFIX}}_extra_blocks[name] = {{PAGE_PREFIX}}_extra_blocks[name] + 1; + } +} function {{JS_PREFIX}}_toggle_app_details(ev) { const detailsDivId = '{{JS_PREFIX}}_detailsDiv'; @@ -17,7 +26,11 @@ function {{JS_PREFIX}}_toggle_app_details(ev) { } } } else { - if ({{JS_PREFIX}}_last_stats === null || {{JS_PREFIX}}_last_stats.blocks.length === 0) return; + const extraKeys = Object.keys({{PAGE_PREFIX}}_extra_blocks); + if (extraKeys.length === 0 + && ({{JS_PREFIX}}_last_stats === null || {{JS_PREFIX}}_last_stats.blocks.length === 0)) { + return; + } {{JS_PREFIX}}_app_details = true; {{JS_PREFIX}}_app_refresh(function () { if ({{JS_PREFIX}}_last_stats != null) { @@ -33,6 +46,23 @@ function {{JS_PREFIX}}_toggle_app_details(ev) { } detailsDiv.style.display = 'block'; // add rows for blocked stuff... + extraKeys.sort(function (a, b) { + return a.localeCompare(b, '{{ACCOUNT_LANG}}', {'sensitivity': 'base'}); + }); + extraKeys.forEach(k => { + const useEm = k.startsWith('*'); + const token = useEm ? k.substring(1) : k; + const entryDiv = document.createElement('div'); + if (useEm) { + const em = document.createElement('em'); + em.appendChild(document.createTextNode(token + ': ' + {{PAGE_PREFIX}}_extra_blocks[k])); + entryDiv.appendChild(em); + } else { + const entryText = document.createTextNode(token + ': ' + {{PAGE_PREFIX}}_extra_blocks[k]); + entryDiv.appendChild(entryText); + } + detailsDiv.appendChild(entryDiv); + }); for (let i = 0; i < {{JS_PREFIX}}_last_stats.blocks.length; i++) { const entry = {{JS_PREFIX}}_last_stats.blocks[i]; const entryDiv = document.createElement('div'); diff --git a/bubble-server/src/main/resources/bubble/rule/social/block/JsUserBlockerRuleDriver.js.hbs b/bubble-server/src/main/resources/bubble/rule/social/block/JsUserBlockerRuleDriver.js.hbs index 599c5d6d..168a90e9 100644 --- a/bubble-server/src/main/resources/bubble/rule/social/block/JsUserBlockerRuleDriver.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/social/block/JsUserBlockerRuleDriver.js.hbs @@ -43,7 +43,7 @@ const {{JS_PREFIX}}_stop_refreshing_blocks = function(e) { } const {{JS_PREFIX}}_refresh_blocks = function(e) { - {{PAGE_PREFIX}}_log('_refresh_blocks!'); + // {{PAGE_PREFIX}}_log('refresh_blocks starting'); {{JS_PREFIX}}_last_applied = Date.now(); {{JS_PREFIX}}_stop_refreshing_blocks(); {{JS_PREFIX}}_apply_blocks({{JS_PREFIX}}_blocked_users); @@ -155,6 +155,12 @@ function {{JS_PREFIX}}_block_list (list) { } } +function {{JS_PREFIX}}_tally_block(name) { + if (typeof {{PAGE_PREFIX}}_add_extra_block === 'function') { + {{PAGE_PREFIX}}_add_extra_block(name); + } +} + function {{JS_PREFIX}}_includes_block_keyword (element) { const keywords = Object.keys(Object.assign({}, {{JS_PREFIX}}_blocked_keywords, {{JS_PREFIX}}_blocked_list_keywords)); if (keywords.length > 0) { @@ -164,12 +170,14 @@ function {{JS_PREFIX}}_includes_block_keyword (element) { if (kw.startsWith('_')) { let cskw = kw.substring(1); if (html.indexOf(cskw) !== -1) { - {{PAGE_PREFIX}}_log('>>> includes_block_keyword: blocking based on case-sensitive keyword: ' + cskw); + // {{PAGE_PREFIX}}_log('>>> includes_block_keyword: blocking based on case-sensitive keyword: ' + cskw); + {{JS_PREFIX}}_tally_block('*'+cskw); return true; } } else { if (html.toLowerCase().indexOf(kw.toLowerCase()) !== -1) { - {{PAGE_PREFIX}}_log('>>> includes_block_keyword: blocking based on case-insensitive keyword: ' + kw); + // {{PAGE_PREFIX}}_log('>>> includes_block_keyword: blocking based on case-insensitive keyword: ' + kw); + {{JS_PREFIX}}_tally_block('*'+kw); return true; } } @@ -240,7 +248,7 @@ function {{JS_PREFIX}}_create_unblock_control(name, unblock_func) { } function {{JS_PREFIX}}_hide_app_details() { - {{PAGE_PREFIX}}_log('hide_app_details called'); + // {{PAGE_PREFIX}}_log('hide_app_details called'); const detailsDivId = '{{JS_PREFIX}}_detailsDiv'; let detailsDiv = document.getElementById(detailsDivId); {{JS_PREFIX}}_app_details = false; @@ -253,7 +261,7 @@ function {{JS_PREFIX}}_hide_app_details() { } function {{JS_PREFIX}}_show_app_details() { - {{PAGE_PREFIX}}_log('show_app_details called'); + // {{PAGE_PREFIX}}_log('show_app_details called'); {{JS_PREFIX}}_refresh_blocks(); const detailsDivId = '{{JS_PREFIX}}_detailsDiv'; let detailsDiv = document.getElementById(detailsDivId); diff --git a/bubble-server/src/main/resources/bubble/rule/social/block/site/FB.js.hbs b/bubble-server/src/main/resources/bubble/rule/social/block/site/FB.js.hbs index 522406df..7ac0d049 100644 --- a/bubble-server/src/main/resources/bubble/rule/social/block/site/FB.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/social/block/site/FB.js.hbs @@ -20,7 +20,7 @@ Element.prototype.appendChild = function() { || ({{JS_PREFIX}}_mobile && arguments[0].tagName.toUpperCase() === 'DIV' && arguments[0].role && arguments[0].role === 'article') ) { const block = {{JS_PREFIX}}_should_block({{JS_PREFIX}}_blocked_users, arguments[0]) if (block) { - log('>>> BLOCKING via appendChild: '+block); + // log('>>> BLOCKING via appendChild: '+block); return; } } @@ -65,7 +65,7 @@ function {{JS_PREFIX}}_remove_article_from_dom(article, authorName) { function {{JS_PREFIX}}_remove_article(article, authorName) { if (article.className.indexOf('{{JS_PREFIX}}_bub_blocked') === -1) { - log('removing post by author: ' + authorName); + // log('removing post by author: ' + authorName); article.className = article.className += ' {{JS_PREFIX}}_bub_blocked'; {{JS_PREFIX}}_remove_article_from_dom(article, authorName); } else { @@ -117,7 +117,7 @@ function {{JS_PREFIX}}_should_block(blocked_users, article) { const log = {{PAGE_PREFIX}}_log; if ({{JS_PREFIX}}_includes_block_keyword(article)) { - log('should_block returning true for keyword block'); + // log('should_block returning true for keyword block'); return true; } @@ -137,7 +137,8 @@ function {{JS_PREFIX}}_should_block(blocked_users, article) { } if (authorName.endsWith('/')) authorName = authorName.substring(0, authorName.length-1); if (authorName === 'profile.php') { - log('should_block returning true for '+authorName); + // log('should_block returning true for '+authorName); + {{JS_PREFIX}}_tally_block({{PAGE_PREFIX}}_msg_or_default({{JS_PREFIX}}_messages, 'web_advertOrOtherBlock', 'ad/other')); return true; } const authorDisplay = mobile @@ -145,11 +146,13 @@ function {{JS_PREFIX}}_should_block(blocked_users, article) { : authorLink.getElementsByTagName('span')[0]; const authorDisplayName = authorDisplay.innerHTML; if ({{JS_PREFIX}}_is_ad(article)) { - log('removing ad ('+authorDisplayName+')'); + // log('removing ad ('+authorDisplayName+')'); + {{JS_PREFIX}}_tally_block(authorName == null ? {{PAGE_PREFIX}}_msg_or_default({{JS_PREFIX}}_messages, 'web_advertOrOtherBlock', 'ad/other') : authorName); return authorName == null ? true : authorName; } else if (authorName in blocked_users) { - log('should_block returning '+authorName); + // log('should_block returning '+authorName); + {{JS_PREFIX}}_tally_block(authorName == null ? {{PAGE_PREFIX}}_msg_or_default({{JS_PREFIX}}_messages, 'web_advertOrOtherBlock', 'ad/other') : authorName); return authorName == null ? true : authorName; } else { diff --git a/bubble-server/src/main/resources/bubble/rule/social/block/site/HackerNews.js.hbs b/bubble-server/src/main/resources/bubble/rule/social/block/site/HackerNews.js.hbs index 2194c287..1572336f 100644 --- a/bubble-server/src/main/resources/bubble/rule/social/block/site/HackerNews.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/social/block/site/HackerNews.js.hbs @@ -36,7 +36,9 @@ function {{JS_PREFIX}}_apply_blocks(blocked_users) { blocking_indent = null; } } else { - if (author in blocked_users || {{JS_PREFIX}}_includes_block_keyword(comment)) { + const authorBlocked = author in blocked_users; + if (authorBlocked || {{JS_PREFIX}}_includes_block_keyword(comment)) { + if (authorBlocked) {{JS_PREFIX}}_tally_block(author); blocking = true; blocking_indent = indent; comment.parentNode.removeChild(comment); diff --git a/bubble-server/src/main/resources/bubble/rule/social/block/site/MR.js.hbs b/bubble-server/src/main/resources/bubble/rule/social/block/site/MR.js.hbs index 65f69cf6..3e121846 100644 --- a/bubble-server/src/main/resources/bubble/rule/social/block/site/MR.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/social/block/site/MR.js.hbs @@ -21,6 +21,7 @@ function {{JS_PREFIX}}_consider_block(comments, blocked_users) { if (userElement !== null) { const author = userElement.innerText; if (author in blocked_users) { + {{JS_PREFIX}}_tally_block(author); comment.parentNode.removeChild(comment); continue; } diff --git a/bubble-server/src/main/resources/bubble/rule/social/block/site/Reason.js.hbs b/bubble-server/src/main/resources/bubble/rule/social/block/site/Reason.js.hbs index b84bb6e4..70f7b4d7 100644 --- a/bubble-server/src/main/resources/bubble/rule/social/block/site/Reason.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/social/block/site/Reason.js.hbs @@ -21,6 +21,7 @@ function {{JS_PREFIX}}_consider_block(comments, blocked_users) { if (userElement !== null) { const author = userElement.innerText; if (author in blocked_users) { + {{JS_PREFIX}}_tally_block(author); comment.parentNode.removeChild(comment); continue; } diff --git a/bubble-server/src/main/resources/bubble/rule/social/block/site/Twitter.js.hbs b/bubble-server/src/main/resources/bubble/rule/social/block/site/Twitter.js.hbs index d9fa110e..dfff76da 100644 --- a/bubble-server/src/main/resources/bubble/rule/social/block/site/Twitter.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/social/block/site/Twitter.js.hbs @@ -33,8 +33,10 @@ function {{JS_PREFIX}}_apply_blocks(blocked_users) { node = node.parentNode; if (node === null) break; } - if (node === null || node.parentNode === null) continue'' - if (author in blocked_users || {{JS_PREFIX}}_includes_block_keyword(node)) { + if (node === null || node.parentNode === null) continue; + let authorBlocked = author in blocked_users; + if (authorBlocked || {{JS_PREFIX}}_includes_block_keyword(node)) { + if (authorBlocked) {{JS_PREFIX}}_tally_block(author); console.log('removing post by author: ' + authorName); try { author.className = author.className + ' _bubble_blocked'; diff --git a/bubble-server/src/main/resources/models/apps/user_block/bubbleApp_userBlock.json b/bubble-server/src/main/resources/models/apps/user_block/bubbleApp_userBlock.json index 390dccb1..106d2b1d 100644 --- a/bubble-server/src/main/resources/models/apps/user_block/bubbleApp_userBlock.json +++ b/bubble-server/src/main/resources/models/apps/user_block/bubbleApp_userBlock.json @@ -44,12 +44,15 @@ {"name": "web_blockedKeywords", "value": "Keywords"}, {"name": "web_noKeywordsBlocked", "value": "(empty)"}, {"name": "web_addKeyword", "value": "Add"}, + {"name": "web_advertOrOtherBlock", "value": "advert/other"}, {"name": "web_close", "value": "Close"}, {"name": "web_blockedKeywordLists", "value": "Keyword Lists"}, {"name": "web_kwlist_us_news", "value": "US News Media"}, {"name": "web_kwlist_us_news_url", "value": "https://raw.githubusercontent.com/getbubblenow/bubble-filter-lists/master/sites_us_news.txt"}, {"name": "web_kwlist_us_politics", "value": "US Politics"}, {"name": "web_kwlist_us_politics_url", "value": "https://raw.githubusercontent.com/getbubblenow/bubble-filter-lists/master/us_politics.txt"}, + {"name": "web_kwlist_vulgar", "value": "Bad Words"}, + {"name": "web_kwlist_vulgar_url", "value": "https://raw.githubusercontent.com/getbubblenow/bubble-filter-lists/master/bad_words.txt"}, {"name": "web_refreshPage", "value": "refresh"} ] }]