Open PeterDaveHello opened 3 years ago
Maybe we should remove the condition of external link, it'll be great the links of Facebook itself can be more "direct"? https://github.com/Mte90/facebook-direct-links/blob/39809822009ef71e65f0bce4f5ad9fab74d8e593/direct.js#L89
It's interesting that I just found the method to remove external link condition could be too aggressive, that some of the hashtags in the posts could be broken (the link will be missing).
Yes there are some parameters that are needed for "internal links" so that the reason of that check, this require a bit of testing but usually it is better to not remove it. I don't know with the new UI if things are changed.
@Mte90 I got a working patch here, not a very beautify solution, and not sure if that's something acceptable here, would like to have some comments from you:
diff --git a/direct.js b/direct.js
index 5735362..f1993ce 100644
--- a/direct.js
+++ b/direct.js
@@ -47,7 +47,7 @@
win.ready = ready;
ready('a', function (element) {
- let cleanup = function() {
+ let externalCleanup = function() {
let uri = element.href;
if (/^https?:\/\/lm?.facebook.com/i.test(uri)) {
@@ -77,8 +77,31 @@
element.href = uri;
}
- let eventBlocker = function(evt) {
- cleanup();
+ let internalCleanup = function() {
+ let uri = element.href;
+
+ uri = decodeURIComponent(uri);
+ uri = uri.replace(/([&|?])__cft__\[0\]=[^&#$/]*/gi, '$1');
+ uri = uri.replace(/([&|?])__tn__=[^&#$/]*/gi, '$1');
+ uri = uri.replace(/([&|?])__eep__=[^&#$/]*/gi, '$1');
+
+ // Additional `&` clean up
+ uri = uri.replace(/([&|?])(&+)/gi, '$1');
+
+ if (uri[uri.length -1] === '?') {
+ uri = uri.substr(0, uri.length-1);
+ }
+
+ element.href = uri;
+ }
+
+ let eventBlockerForExtLinks = function(evt) {
+ externalCleanup();
+ evt.stopImmediatePropagation();
+ }
+
+ let eventBlockerForIntLinks = function(evt) {
+ externalCleanup();
evt.stopImmediatePropagation();
}
@@ -91,12 +114,19 @@
var trackerLinkRegex = /^https?:\/\/lm?.(facebook\.com|facebookwww\.onion|facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd\.onion)\/l.php\?u=([^&#$]+)/i;
if( !domainfilter.includes(domain) || trackerLinkRegex.test(url) ) { //external links
- element.addEventListener('click', eventBlocker);
- element.addEventListener('contextmenu', eventBlocker);
- element.addEventListener('touchstart', eventBlocker);
- element.addEventListener('mousedown', eventBlocker);
- element.addEventListener('mouseup', eventBlocker);
- cleanup();
+ element.addEventListener('click', eventBlockerForExtLinks);
+ element.addEventListener('contextmenu', eventBlockerForExtLinks);
+ element.addEventListener('touchstart', eventBlockerForExtLinks);
+ element.addEventListener('mousedown', eventBlockerForExtLinks);
+ element.addEventListener('mouseup', eventBlockerForExtLinks);
+ externalCleanup();
+ } else {
+ element.addEventListener('click', eventBlockerForIntLinks);
+ element.addEventListener('contextmenu', eventBlockerForIntLinks);
+ element.addEventListener('touchstart', eventBlockerForIntLinks);
+ element.addEventListener('mousedown', eventBlockerForIntLinks);
+ element.addEventListener('mouseup', eventBlockerForIntLinks);
+ internalCleanup();
}
});
It is missing the externalCleanup
function but seems a simple way to achieve what we need.
To me is fine ;-)
@Mte90 externalCleanup()
is not touched, that's why it's not in the diff result ;)
ok seems perfect!
@Mte90 I thought #30 was reverted by #32, so this issue is not resolved?
I didn't remember, I saw no updates in the ticket and I thought that was closed.
Currently that feature is not implemented yet, so maybe I just reopen it?
The links of Facebook itself is currently not cleaned up here, it'll be great the links of Facebook itself can be more "direct"?