Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(betteReddit): add unEscapeLinks option #5404

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/modules/betteReddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ module.options = {
title: 'betteRedditRestrictScrollEventsTitle',
advanced: true,
},
unEscapeLinks: {
type: 'boolean',
value: true,
description: 'betteRedditunEscapeLinksDesc',
title: 'betteRedditunEscapeLinksTitle',
},
};

module.exclude = [
Expand Down Expand Up @@ -272,6 +278,10 @@ module.beforeLoad = () => {
}`;
document.documentElement.append(scr);
}

if (module.options.unEscapeLinks.value) {
watchForElements(['selfText', 'page'], 'a[href*="%5C"]', unEscapeLinks);
}
};

module.contentStart = () => {
Expand Down Expand Up @@ -577,3 +587,8 @@ function applyNoCtrlF(element) {
element.dataset.text = element.textContent;
element.textContent = '';
}

function unEscapeLinks(a) {
a.href = a.href.replace(/%5C([_"])/g, '$1');
if (a.innerText) a.innerText = a.innerText.replace(/\\([_"])/g, '$1');
}
6 changes: 6 additions & 0 deletions locales/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,12 @@
"betteRedditRestrictScrollEventsDesc": {
"message": "Reddit performs much work every time you scroll, which may cause lag on pages with many comments. Reducing the number of scroll events it processes improves performance."
},
"betteRedditunEscapeLinksDesc": {
"message": "Fix Escaped Links"
},
"betteRedditunEscapeLinksTitle": {
"message": "New Reddit adds backslashes before underscores and quotes in links, which often causes links to be broken."
},
"betteRedditHideLinkLabel": {
"message": "hide"
},
Expand Down