@@ -5,6 +5,20 @@ let {{JS_PREFIX}}_interval = null; | |||||
let {{JS_PREFIX}}_last_applied = null; | let {{JS_PREFIX}}_last_applied = null; | ||||
const {{JS_PREFIX}}_idle_interval = 2500; | const {{JS_PREFIX}}_idle_interval = 2500; | ||||
const {{JS_PREFIX}}_stop_refreshing_blocks = function(e) { | |||||
if ({{JS_PREFIX}}_interval !== null) { | |||||
window.clearInterval({{JS_PREFIX}}_interval); | |||||
} | |||||
} | |||||
const {{JS_PREFIX}}_refresh_blocks = function(e) { | |||||
{{JS_PREFIX}}_stop_refreshing_blocks(); | |||||
{{JS_PREFIX}}_apply_blocks({{JS_PREFIX}}_blocked_users); | |||||
{{JS_PREFIX}}_interval = window.setInterval(function () { | |||||
{{JS_PREFIX}}_apply_blocks({{JS_PREFIX}}_blocked_users); | |||||
{{JS_PREFIX}}_last_applied = Date.now(); | |||||
}, {{JS_PREFIX}}_idle_interval); | |||||
} | |||||
function {{JS_PREFIX}}_fetch_blocks (do_apply) { | function {{JS_PREFIX}}_fetch_blocks (do_apply) { | ||||
const requestOptions = { method: 'GET' }; | const requestOptions = { method: 'GET' }; | ||||
const blocked_users_url = '/__bubble/api/filter/data/{{BUBBLE_DATA_ID}}/read'; | const blocked_users_url = '/__bubble/api/filter/data/{{BUBBLE_DATA_ID}}/read'; | ||||
@@ -26,16 +40,17 @@ function {{JS_PREFIX}}_fetch_blocks (do_apply) { | |||||
}); | }); | ||||
} | } | ||||
window.addEventListener('popstate', function(e) { | |||||
if ({{JS_PREFIX}}_interval !== null) { | |||||
window.clearInterval({{JS_PREFIX}}_interval); | |||||
window.addEventListener('popstate', {{JS_PREFIX}}_refresh_blocks); | |||||
function {{JS_PREFIX}}_handleVisibilityChange() { | |||||
if (document.hidden) { | |||||
{{JS_PREFIX}}_stop_refreshing_blocks(); | |||||
} else { | |||||
{{JS_PREFIX}}_refresh_blocks(); | |||||
} | } | ||||
{{JS_PREFIX}}_apply_blocks({{JS_PREFIX}}_blocked_users); | |||||
{{JS_PREFIX}}_interval = window.setInterval(function () { | |||||
{{JS_PREFIX}}_apply_blocks({{JS_PREFIX}}_blocked_users); | |||||
{{JS_PREFIX}}_last_applied = Date.now(); | |||||
}, {{JS_PREFIX}}_idle_interval); | |||||
}); | |||||
} | |||||
document.addEventListener("visibilitychange", {{JS_PREFIX}}_handleVisibilityChange, false); | |||||
function {{JS_PREFIX}}_block_user (author) { | function {{JS_PREFIX}}_block_user (author) { | ||||
{{JS_PREFIX}}_blocked_users.push(author); | {{JS_PREFIX}}_blocked_users.push(author); | ||||
@@ -23,14 +23,18 @@ function {{JS_PREFIX}}_author_display_name(link) { | |||||
return spans[spans.length-1]; | return spans[spans.length-1]; | ||||
} | } | ||||
function {{JS_PREFIX}}_find_feed_item(article) { | |||||
return {{JS_PREFIX}}_mobile | |||||
? article | |||||
: article.parentElement.parentElement.parentElement.parentElement.parentElement; // todo: safer to walk upwards until we find FeedItem | |||||
} | |||||
function {{JS_PREFIX}}_remove_article(article, authorName) { | function {{JS_PREFIX}}_remove_article(article, authorName) { | ||||
if (article.className.indexOf('{{JS_PREFIX}}_bub_blocked') === -1) { | 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'; | article.className = article.className += ' {{JS_PREFIX}}_bub_blocked'; | ||||
try { | try { | ||||
const feedItem = {{JS_PREFIX}}_mobile | |||||
? article | |||||
: article.parentElement.parentElement.parentElement.parentElement.parentElement; // todo: safer to walk upwards until we find FeedItem | |||||
const feedItem = {{JS_PREFIX}}_find_feed_item(article); | |||||
feedItem.parentElement.removeChild(feedItem); | feedItem.parentElement.removeChild(feedItem); | ||||
} catch (e) { | } catch (e) { | ||||
log('error removing post by author: ' + authorName + ': ' + e); | log('error removing post by author: ' + authorName + ': ' + e); | ||||
@@ -56,13 +60,13 @@ function {{JS_PREFIX}}_create_block_control(article, authorName) { | |||||
const blockLink = document.createElement('a'); | const blockLink = document.createElement('a'); | ||||
blockLink.style.zIndex = '{{APP_CONTROLS_Z_INDEX}}' | blockLink.style.zIndex = '{{APP_CONTROLS_Z_INDEX}}' | ||||
blockLink.addEventListener("click", function (e) { | blockLink.addEventListener("click", function (e) { | ||||
{{JS_PREFIX}}_block_user(authorName); | |||||
try { | try { | ||||
const feedItem = article.parentElement.parentElement.parentElement.parentElement.parentElement; | |||||
const feedItem = {{JS_PREFIX}}_find_feed_item(article); | |||||
feedItem.parentElement.removeChild(feedItem); | feedItem.parentElement.removeChild(feedItem); | ||||
} catch (e) { | } catch (e) { | ||||
log('click error removing post by author: ' + authorName + ': ' + e); | log('click error removing post by author: ' + authorName + ': ' + e); | ||||
} | } | ||||
{{JS_PREFIX}}_block_user(authorName); | |||||
e.stopPropagation(); | e.stopPropagation(); | ||||
e.preventDefault(); | e.preventDefault(); | ||||
return false; | return false; | ||||
@@ -1 +1 @@ | |||||
Subproject commit 73fdb7cb6320f43d267b16330f7c08bfd3eab93c | |||||
Subproject commit 3de70e3b1e5109a0d1bf41e8d6e73358236d5e8f |