From 4a8903e48a41de6df64b18a19200f5d161700b56 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Mon, 24 Aug 2020 17:30:28 -0400 Subject: [PATCH] basic shadowban support working on fb --- .../bubble/rule/AbstractAppRuleDriver.java | 10 +- .../rule/bblock/BubbleBlockRuleDriver.java | 2 +- .../rule/RequestModifierRule_icon.js.hbs | 12 ++- .../bblock/BubbleBlockRuleDriver_stats.js.hbs | 19 +++- .../bubble/rule/social/block/site/FB.js.hbs | 92 +++++++++++-------- 5 files changed, 85 insertions(+), 50 deletions(-) diff --git a/bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java b/bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java index e0dfa74a..49adc135 100644 --- a/bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java +++ b/bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java @@ -40,9 +40,9 @@ import java.util.Map; import static bubble.ApiConstants.HOME_DIR; import static bubble.rule.RequestModifierRule.ICON_JS_TEMPLATE; import static bubble.rule.RequestModifierRule.ICON_JS_TEMPLATE_NAME; -import static org.cobbzilla.util.daemon.ZillaRuntime.die; -import static org.cobbzilla.util.daemon.ZillaRuntime.empty; +import static org.cobbzilla.util.daemon.ZillaRuntime.*; import static org.cobbzilla.util.io.FileUtil.abs; +import static org.cobbzilla.util.io.FileUtil.basename; import static org.cobbzilla.util.io.regex.RegexReplacementFilter.DEFAULT_PREFIX_REPLACEMENT_WITH_MATCH; import static org.cobbzilla.util.json.JsonUtil.json; import static org.cobbzilla.util.security.ShaUtil.sha256_hex; @@ -127,12 +127,12 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver { protected String loadTemplate(String defaultTemplate, String templatePath) { if (configuration.getEnvironment().containsKey("DEBUG_RULE_TEMPLATES")) { - final File templateFile = new File(HOME_DIR + "/debugTemplates/" + templatePath); + final File templateFile = new File(HOME_DIR + "/debugTemplates/" + basename(templatePath)); if (templateFile.exists() && templateFile.lastModified() > getJarTime()) { - log.error("loadTemplate: debug file found and newer than bubble jar, using it: "+abs(templateFile)); + if (log.isDebugEnabled()) log.debug("loadTemplate: debug file found and newer than bubble jar, using it: "+abs(templateFile)); return FileUtil.toStringOrDie(templateFile); } else { - log.error("loadTemplate: debug file not found or older than bubble jar, using default: "+abs(templateFile)); + if (log.isDebugEnabled()) log.debug("loadTemplate: debug file not found or older than bubble jar, using default: "+abs(templateFile)); } } return defaultTemplate; diff --git a/bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java b/bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java index e124fecc..c6dee270 100644 --- a/bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java +++ b/bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java @@ -366,7 +366,7 @@ public class BubbleBlockRuleDriver extends TrafficAnalyticsRuleDriver implements if (bubbleBlockConfig.inPageBlocks()) { return filterInsertJs(in, filterRequest, filterCtx, BUBBLE_JS_TEMPLATE, EMPTY, BLOCK_STATS_JS, showStats); } - log.warn(prefix+"inserting JS for stats into: "+request.getUrl()); + log.warn(prefix+"inserting JS for stats into: "+request.getUrl()+" with Content-Type: "+filterRequest.getContentType()); return filterInsertJs(in, filterRequest, filterCtx, getBubbleJsStatsTemplate(), null, null, showStats); } diff --git a/bubble-server/src/main/resources/bubble/rule/RequestModifierRule_icon.js.hbs b/bubble-server/src/main/resources/bubble/rule/RequestModifierRule_icon.js.hbs index 2cc026b2..aef17e16 100644 --- a/bubble-server/src/main/resources/bubble/rule/RequestModifierRule_icon.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/RequestModifierRule_icon.js.hbs @@ -10,18 +10,24 @@ if (typeof {{PAGE_PREFIX}}_icon_status === 'undefined') { method: 'POST', body: logData }; + console.log('Logging to server: '+logData); fetch('/__bubble/api/filter/logs/{{BUBBLE_REQUEST_ID}}', requestOptions) .then(() => { - console.log('Logged to server:', logData); + console.log('Logged to server: '+logData); }) .catch((error) => { - console.error('Error logging "'+logData+'" to server:', error); + console.error('Error logging "'+logData+'" to server: '+error); }); } {{PAGE_PREFIX}}_addBubbleApp = function (app) { if (window.self === window.top) { - {{PAGE_PREFIX}}_icon_status.push(app); + if ({{PAGE_PREFIX}}_icon_status.find(a => a.app === app.app)) { + {{PAGE_PREFIX}}_log('addBubbleApp: NOT adding app (already added): '+app.app); + } else { + {{PAGE_PREFIX}}_log('addBubbleApp: adding app: '+app.app); + {{PAGE_PREFIX}}_icon_status.push(app); + } } } 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 558832ee..5ef7ef14 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 @@ -75,23 +75,32 @@ const {{JS_PREFIX}}_app_refresh = function (displayFunc) { icon = 'icon-yellow'; } else { icon = 'icon-red'; - console.log('cancelling window.interval, red status'); - window.clearInterval({{JS_PREFIX}}_app_refresh_interval); + if ({{JS_PREFIX}}_app_refresh_interval !== null) { + console.log('cancelling window.interval, red status'); + window.clearInterval({{JS_PREFIX}}_app_refresh_interval); + {{JS_PREFIX}}_app_refresh_interval = null; + } } {{JS_PREFIX}}_app.icon = icon; {{PAGE_PREFIX}}_setAppIconImg({{JS_PREFIX}}_app); - } else if (Date.now() - {{JS_PREFIX}}_app_stats_last_change > {{JS_PREFIX}}_app_stats_timeout) { + } else if ({{JS_PREFIX}}_app_refresh_interval !== null && Date.now() - {{JS_PREFIX}}_app_stats_last_change > {{JS_PREFIX}}_app_stats_timeout) { console.log('cancelling window.interval, stats unchanged for a while'); window.clearInterval({{JS_PREFIX}}_app_refresh_interval); + {{JS_PREFIX}}_app_refresh_interval = null; } if (typeof displayFunc === 'function') { displayFunc(); } } }).catch((error) => { - console.log('cancelling window.interval, due to error: '+error); - window.clearInterval({{JS_PREFIX}}_app_refresh_interval); + if ({{JS_PREFIX}}_app_refresh_interval !== null) { + console.log('cancelling window.interval, due to error: ' + error); + window.clearInterval({{JS_PREFIX}}_app_refresh_interval); + {{JS_PREFIX}}_app_refresh_interval = null; + } else { + console.log('error: ' + error); + } }); } 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 225ccf9a..35d03eaa 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 @@ -12,60 +12,80 @@ const {{JS_PREFIX}}_site_host = location.protocol + '//' + window.location.hostn function {{JS_PREFIX}}_apply_blocks(blocked_users) { let articles = {{JS_PREFIX}}_getElementsByXPath('//div[@role="article" and @aria-posinset]'); let sitePrefix = {{JS_PREFIX}}_site_host; + const log = {{PAGE_PREFIX}}_log; for (let i=0; i s.innerHTML === ' · '); + if (sepSpans.length === 0) { + log('no insertion point found for author: ' + authorName); + continue; + } + sepSpans.map(sepSpan => { + const imgHolder = document.createElement('img'); + imgHolder.src = '/__bubble/api/filter/assets/{{BUBBLE_REQUEST_ID}}/UserBlocker/icon?raw=true'; + imgHolder.width = 16; - const line = document.createElement('hr'); - const imgHolder = document.createElement('img'); - imgHolder.src = '/__bubble/api/filter/assets/{{BUBBLE_REQUEST_ID}}/UserBlocker/icon?raw=true'; - imgHolder.width = 16; + const blockLink = document.createElement('a'); + blockLink.addEventListener("click", function (event) { + {{JS_PREFIX}}_block_user(authorName); + try { + const feedItem = article.parentElement.parentElement.parentElement.parentElement.parentElement; + log('click nuking: '+feedItem.outerHTML.substring(0, 40)) + feedItem.parentElement.removeChild(feedItem); + } catch (e) { + log('click error removing post by author: ' + authorName + ': ' + e); + } + return false; + }); + // blockLink.appendChild(line); + blockLink.appendChild(imgHolder); - const blockLink = document.createElement('a'); - blockLink.addEventListener("click", function (event) { {{JS_PREFIX}}_block_user(authorName); return false; }); - blockLink.appendChild(line); - blockLink.appendChild(imgHolder); - blockControl.appendChild(blockLink); + // log('inserting block icon for ' + authorName + '...'); + sepSpan.parentNode.appendChild(blockLink); + sepSpan.parentNode.appendChild(document.createTextNode(' · ')); + }); - sepSpan.appendChild(blockControl); - sepSpan.appendChild(document.createTextNode(' · ')); + } catch (e) { + log('badness: '+e); + } } } }