浏览代码

basic shadowban support working on fb

pull/44/head
Jonathan Cobb 4 年前
父节点
当前提交
4a8903e48a
共有 5 个文件被更改,包括 85 次插入50 次删除
  1. +5
    -5
      bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java
  2. +1
    -1
      bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java
  3. +9
    -3
      bubble-server/src/main/resources/bubble/rule/RequestModifierRule_icon.js.hbs
  4. +14
    -5
      bubble-server/src/main/resources/bubble/rule/bblock/BubbleBlockRuleDriver_stats.js.hbs
  5. +56
    -36
      bubble-server/src/main/resources/bubble/rule/social/block/site/FB.js.hbs

+ 5
- 5
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;


+ 1
- 1
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);
}



+ 9
- 3
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);
}
}
}



+ 14
- 5
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);
}
});
}



+ 56
- 36
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<articles.length; i++) {
let article = articles[i];
let authorLink = article.getElementsByTagName('a')[0];
if (typeof authorLink.href === 'undefined') {
continue;
}
let authorHref = authorLink.href;
if (!authorHref.href.startsWith(sitePrefix)) continue;
if (!authorHref.startsWith(sitePrefix)) continue;
let authorName = authorHref.substring(sitePrefix.length);
let qPos = authorName.indexOf('?');
if (qPos !== -1) {
authorName = authorName.substring(0, qPos);
authorLink.href = sitePrefix + authorName; // todo: clean up all links, not just this one
authorLink.href = sitePrefix + authorName;
}
if (blocked_users !== null && blocked_users.includes(authorName)) {
console.log('removing post by author: ' + authorName);
try {
article.className = article.className + ' _bubble_blocked';
node.style = 'display: none';
} catch (e) {
console.log('error removing post by author: ' + authorName+': '+e);
if (article.className.indexOf('{{JS_PREFIX}}_bub_blocked') === -1) {
log('removing post by author: ' + authorName);
article.className = article.className += ' {{JS_PREFIX}}_bub_blocked';
try {
const feedItem = article.parentElement.parentElement.parentElement.parentElement.parentElement;
log('nuking: '+feedItem.outerHTML.substring(0, 40))
feedItem.parentElement.removeChild(feedItem);
} catch (e) {
log('error removing post by author: ' + authorName + ': ' + e);
}
} else {
log('found post marked removed but still present (??) by author: ' + authorName);
}

} else {
// have we visited this article before?
if (article.className.indexOf('{{JS_PREFIX}}_bubble_block') === -1) {
console.log('VISITING article node for author: '+authorName);
const spans = authorLink.parentNode.nextSibling.getElementsByTagName('span');
let sepSpan = null;
for (let i=0; i<spans.length; i++) {
let s = spans[i];
if (s.innerHTML === ' · ') {
sepSpan = s;
break;
if (article.innerHTML.indexOf('_bubble') === -1) {
log('VISITING article node for author: '+authorName);
try {
article.className = article.className += ' {{JS_PREFIX}}_bubble_block';
if (typeof authorLink.parentNode.parentNode.nextSibling === 'undefined' || authorLink.parentNode.parentNode.nextSibling === null) {
console.log('authorLink.parentNode.parentNode.nextSibling was undefined or null, skipping; outerHTML='+authorLink.parentNode.parentNode.outerHTML);
continue;
}
}
if (sepSpan === null) {
console.log('no insertion point found');
continue;
}
const blockControl = document.createElement('div');
blockControl.style.textAlign = 'center';
article.className = article.className += ' {{JS_PREFIX}}_bubble_block';
const spans = authorLink.parentNode.parentNode.nextSibling.getElementsByTagName('span');
const sepSpans = Array.from(spans).filter(s => 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);
}
}
}
}


正在加载...
取消
保存