Skip to content

Commit

Permalink
Fixup disable link filter handler
Browse files Browse the repository at this point in the history
  • Loading branch information
candela97 committed Mar 23, 2024
1 parent 43fd472 commit 272cad7
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/js/Content/Features/Common/FDisableLinkFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ export default class FDisableLinkFilter extends Feature {
}

apply() {
document.addEventListener("click", function(e) {
if (e.target.tagName && e.target.tagName === "A") {
let href = e.target.href;
if (/\/linkfilter\//.test(href)) {
let params = new URLSearchParams(href.search);
// TODO "url" param was used prior to 11/2023, remove after some time
let url = params.get("u") ?? params.get("url");
if (url) {
// TODO check whether it's safe to just directly edit e.target.href
window.location.href = url;
e.preventDefault();
}
}
}

document.addEventListener("click", e => {
if (e.target?.tagName !== "A") { return; }

const href = e.target.href;
if (!/\/linkfilter\//.test(href)) { return; }

const params = new URL(href).searchParams;
// TODO "url" param was used prior to 11/2023, remove after some time
const url = params.get("u") ?? params.get("url");
if (!url) { return; }

// Skip censored links (has '♥')
if (url.includes("%E2%99%A5")) { return; }

e.preventDefault();

// TODO check whether it's safe to just directly edit e.target.href
window.location.href = url;
});
}
}

0 comments on commit 272cad7

Please sign in to comment.