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

Add usernameHider support to mod.reddit.com #5401

Open
wants to merge 1 commit 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
1 change: 0 additions & 1 deletion firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
],
"all_frames": true,
"exclude_matches": [
"https://mod.reddit.com/*",
"https://ads.reddit.com/*",
"https://i.reddit.com/*",
"https://m.reddit.com/*",
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/accountSwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ const accounts = once(() =>
);

module.contentStart = () => {
if (location.host === 'mod.reddit.com') {
return;
}
const downArrow = module.options.dropDownStyle.value === 'alien' ?
string.html`<span id="RESAccountSwitcherIcon" role="button"></span>` :
string.html`<span id="RESAccountSwitcherIcon" role="button"><span class="downArrow"></span></span>`;
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/announcements.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const now = Date.now();
let biff;

module.go = async () => {
if (location.host === 'mod.reddit.com') {
return;
}
if (isCurrentSubreddit(subreddit)) {
setMarkedRead();
} else {
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/messageMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ module.options = {
};

module.contentStart = () => {
if (location.host === 'mod.reddit.com') {
return;
}
Hover.dropdownList(module.moduleID)
.options({
openDelay: parseFloat(module.options.hoverDelay.value),
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/orangered.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ module.options = {
module.contentStart = () => {
if (module.options.faviconUseLegacy.value) setupFavicon();

if (location.host === 'mod.reddit.com') {
return;
}

if (!loggedInUser()) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/pageNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.beforeLoad = () => {
};

module.contentStart = () => {
if (location.host === 'mod.reddit.com') {
return;
}
if (module.options.toComment.value && isPageType('comments')) {
backToNewCommentArea();
}
Expand Down
26 changes: 25 additions & 1 deletion lib/modules/usernameHider.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,28 @@ function hideUsername(user, displayText) {

const userHref = `[href*="/user/${user}"]`;

if (location.host === 'mod.reddit.com') {
addCSS(`
a.author${userHref} .Author__text {
line-height: 0;
font-size: 0;
}
`);
} else {
addCSS(`
a.author${userHref} {
line-height: 0;
font-size: 0;
}
`);
}

// Hide username
addCSS(`
p.tagline > a${userHref},
#header .user > a${userHref},
.titlebox .tagline a.author${userHref},
.commentingAsUser a${userHref},
a.author${userHref},
.bottom a${userHref} {
line-height: 0;
font-size: 0;
Expand All @@ -106,6 +121,15 @@ function hideUsername(user, displayText) {
padding: inherit;
}

.Header__user {
font-size: 0;
}

.Header__user::after {
content: "${displayText}";
font-size: 20px;
}

a.author${userHref}::after {
margin-right: 0.5em;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/utils/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export const isLoggedIn = once(() => {
export const loggedInUser = once((): string | void => documentLoggedInUser(document));

export const documentLoggedInUser = (document: Document | Element): string | void => {
if (location.host === 'mod.reddit.com') {
// eslint-disable-next-line no-useless-assign/no-useless-assign
const username = document.querySelector('.Header__user').textContent;
return username;
}
if (isAppType('d2x')) {
// The first text node in the user button contains the username
const findFirstTextNode = e => [...e.childNodes].filter(v => v.nodeType === 3).concat(...[...e.children].map(findFirstTextNode));
Expand Down