|
|
@@ -13,90 +13,93 @@ function {{JS_PREFIX}}_getElementsByXPath(xpath, parent) { |
|
|
|
const {{JS_PREFIX}}_site_host = location.protocol + '//' + window.location.hostname + '/'; |
|
|
|
|
|
|
|
function {{JS_PREFIX}}_apply_blocks(blocked_users) { |
|
|
|
let authors = {{JS_PREFIX}}_getElementsByXPath('//article//a'); |
|
|
|
let sitePrefix = {{JS_PREFIX}}_site_host; |
|
|
|
for (let i=0; i<authors.length; i++) { |
|
|
|
let author = authors[i]; |
|
|
|
const authors = {{JS_PREFIX}}_getElementsByXPath('//article//a'); |
|
|
|
const sitePrefix = {{JS_PREFIX}}_site_host; |
|
|
|
for (let i=0; i<authors.length; i++) { |
|
|
|
const author = authors[i]; |
|
|
|
|
|
|
|
if (author.href && author.href.startsWith(sitePrefix) |
|
|
|
&& author.href.indexOf('?', sitePrefix.length) === -1 |
|
|
|
&& author.href.indexOf('/', sitePrefix.length) === -1 |
|
|
|
&& author.className.indexOf('_bubble_blocked') === -1) { |
|
|
|
if (author.href && author.href.startsWith(sitePrefix) |
|
|
|
&& author.href.indexOf('?', sitePrefix.length) === -1 |
|
|
|
&& author.href.indexOf('/', sitePrefix.length) === -1 |
|
|
|
&& author.className.indexOf('_bubble_blocked') === -1) { |
|
|
|
|
|
|
|
const firstEval = {{JS_PREFIX}}_mark_evaluated(author); |
|
|
|
const firstEval = {{JS_PREFIX}}_mark_evaluated(author); |
|
|
|
|
|
|
|
let authorName = author.href.substring(sitePrefix.length); |
|
|
|
let node = author; |
|
|
|
// walk parents until we find the article, then go up 3 more divs |
|
|
|
while (node.tagName.toUpperCase() !== 'ARTICLE') { |
|
|
|
node = node.parentNode; |
|
|
|
if (node === null) break; |
|
|
|
} |
|
|
|
if (node === null) continue; |
|
|
|
for (let p = 0; p < 3; p++) { |
|
|
|
node = node.parentNode; |
|
|
|
if (node === null) break; |
|
|
|
} |
|
|
|
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); |
|
|
|
if (!firstEval) {{JS_PREFIX}}_untally_allow(); |
|
|
|
} |
|
|
|
console.log('removing post by author: ' + authorName); |
|
|
|
try { |
|
|
|
author.className = author.className + ' _bubble_blocked'; |
|
|
|
node.style = 'display: none'; |
|
|
|
} catch (e) { |
|
|
|
console.log('error removing post by author: ' + authorName+': '+e); |
|
|
|
} |
|
|
|
const authorName = author.href.substring(sitePrefix.length); |
|
|
|
let node = author; |
|
|
|
// walk parents until we find the article, then go up 3 more divs |
|
|
|
while (node.tagName.toUpperCase() !== 'ARTICLE') { |
|
|
|
node = node.parentNode; |
|
|
|
if (node === null) break; |
|
|
|
} |
|
|
|
if (node === null) continue; |
|
|
|
for (let p = 0; p < 3; p++) { |
|
|
|
node = node.parentNode; |
|
|
|
if (node === null) break; |
|
|
|
} |
|
|
|
if (node === null || node.parentNode === null) continue; |
|
|
|
const authorBlocked = authorName in blocked_users; |
|
|
|
if (authorBlocked || {{JS_PREFIX}}_includes_block_keyword(node)) { |
|
|
|
if (authorBlocked) { |
|
|
|
{{JS_PREFIX}}_tally_block(authorName); |
|
|
|
if (!firstEval) {{JS_PREFIX}}_untally_allow(); |
|
|
|
} |
|
|
|
console.log('removing post by author: ' + authorName); |
|
|
|
try { |
|
|
|
author.className = author.className + ' _bubble_blocked'; |
|
|
|
node.style = 'display: none'; |
|
|
|
} catch (e) { |
|
|
|
console.log('error removing post by author: ' + authorName+': '+e); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
// walk up until we find the tweet |
|
|
|
let tweet = author; |
|
|
|
while (tweet.getAttribute('data-testid') === 'undefined' || tweet.getAttribute('data-testid') === null || tweet.getAttribute('data-testid') !== 'tweet') { |
|
|
|
if (tweet.parentNode === document) { |
|
|
|
tweet = null; |
|
|
|
break; |
|
|
|
} else { |
|
|
|
tweet = tweet.parentNode; |
|
|
|
} |
|
|
|
} |
|
|
|
if (tweet === null) { |
|
|
|
console.log('tweet node not found for author: '+authorName); |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
// console.log('FOUND tweet node for author: '+authorName); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// walk up until we find the tweet |
|
|
|
let tweet = author; |
|
|
|
while (tweet.getAttribute('data-testid') === 'undefined' || tweet.getAttribute('data-testid') === null || tweet.getAttribute('data-testid') !== 'tweet') { |
|
|
|
if (tweet.parentNode === document) { |
|
|
|
tweet = null; |
|
|
|
break; |
|
|
|
} else { |
|
|
|
tweet = tweet.parentNode; |
|
|
|
} |
|
|
|
} |
|
|
|
if (tweet === null) { |
|
|
|
console.log('tweet node not found for author: '+authorName); |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
// console.log('FOUND tweet node for author: '+authorName); |
|
|
|
} |
|
|
|
|
|
|
|
// have we visited this tweet before? |
|
|
|
if (tweet.className.indexOf('{{JS_PREFIX}}_bubble_block') === -1) { |
|
|
|
// console.log('VISITING tweet node for author: '+authorName); |
|
|
|
const authorWrapper = author.parentNode.parentNode; |
|
|
|
const authorDiv = authorWrapper.firstChild; |
|
|
|
if (typeof authorDiv.tagName !== 'undefined' && authorDiv.tagName.toUpperCase() === 'DIV') { |
|
|
|
const blockControl = document.createElement('div'); |
|
|
|
blockControl.style.textAlign = 'center'; |
|
|
|
tweet.className = tweet.className += ' {{JS_PREFIX}}_bubble_block'; |
|
|
|
// have we visited this tweet before? |
|
|
|
if (tweet.className.indexOf('{{JS_PREFIX}}_bubble_block') === -1) { |
|
|
|
// console.log('VISITING tweet node for author: '+authorName); |
|
|
|
const authorWrapper = author.parentNode.parentNode; |
|
|
|
const authorDiv = authorWrapper.firstChild; |
|
|
|
if (typeof authorDiv.tagName !== 'undefined' && authorDiv.tagName.toUpperCase() === 'DIV') { |
|
|
|
const blockControl = document.createElement('div'); |
|
|
|
blockControl.style.textAlign = 'center'; |
|
|
|
tweet.className = tweet.className += ' {{JS_PREFIX}}_bubble_block'; |
|
|
|
|
|
|
|
const line = document.createElement('hr'); |
|
|
|
const imgHolder = document.createElement('img'); |
|
|
|
imgHolder.src = {{JS_PREFIX}}_asset_img_url('icon'); |
|
|
|
imgHolder.width = 32; |
|
|
|
const line = document.createElement('hr'); |
|
|
|
const imgHolder = document.createElement('img'); |
|
|
|
imgHolder.src = {{JS_PREFIX}}_asset_img_url('icon'); |
|
|
|
imgHolder.width = 32; |
|
|
|
|
|
|
|
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); |
|
|
|
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); |
|
|
|
|
|
|
|
authorDiv.setAttribute('white-space', 'no-wrap'); |
|
|
|
authorDiv.parentNode.appendChild(blockControl); |
|
|
|
{{JS_PREFIX}}_tally_allow(author); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
authorDiv.setAttribute('white-space', 'no-wrap'); |
|
|
|
authorDiv.parentNode.appendChild(blockControl); |
|
|
|
{{JS_PREFIX}}_tally_allow(authorName); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |