From 7e6f047728da0063e433c4b1def462bb7522a891 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Mon, 31 Aug 2020 10:11:19 -0400 Subject: [PATCH] clean up links --- .../bubble/rule/social/block/site/FB.js.hbs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 f203486c..e1c691da 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 @@ -206,6 +206,19 @@ function {{JS_PREFIX}}_should_block(blocked_users, article) { return false; } +function {{JS_PREFIX}}_remove_param(href, param) { + const cid = href.indexOf(param+'='); + if (cid !== -1) { + const regex = new RegExp('&?'+param+'=[^?&]+', 'g'); + href = href.replace(regex, ''); + const qPos = href.indexOf('?'); + if (href[qPos+1] === '&') { + href = href.substring(0, qPos) + href.substring(qPos+2); + } + } + return href; +} + function {{JS_PREFIX}}_apply_blocks(blocked_users) { const mobile = {{JS_PREFIX}}_mobile; @@ -223,5 +236,23 @@ function {{JS_PREFIX}}_apply_blocks(blocked_users) { if (authorName) { {{JS_PREFIX}}_remove_article(article, authorName === true ? null : authorName); } + Array.from(article.getElementsByTagName('a')).forEach(a => { + let href = a.href; + if (href.indexOf('facebook.com') !== -1 && href.indexOf('u=http') !== -1) { + const uPos = href.indexOf('u=http'); + const andPos = href.indexOf('&'); + if (andPos !== -1) { + href = href.substring(uPos + 2, andPos); + } else { + href = href.substring(uPos + 2); + } + href = decodeURIComponent(href); + } + href = {{JS_PREFIX}}_remove_param(href, 'fbclid'); + href = {{JS_PREFIX}}_remove_param(href, '_ft_'); + href = {{JS_PREFIX}}_remove_param(href, '__tn__'); + href = {{JS_PREFIX}}_remove_param(href, 'refid'); + a.href = href; + }); } }