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

Show usernames #44

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
13 changes: 9 additions & 4 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,27 @@ import showUsername from "./libs/transformations/showUsername";
import assignMe from "./libs/transformations/assignMe";
import bindLabelsKeyboardShortcuts
from "./libs/transformations/bindLabelsKeyboardShortcuts";
import discussionOverComment from "./libs/transformations/discussionOverComment";
import discussionOverComment
from "./libs/transformations/discussionOverComment";

const s = document.createElement("script");
s.src = chrome.runtime.getURL("agent.js"); // eslint-disable-line no-undef
(document.head || document.documentElement).appendChild(s);

storage.load().then(() => {
const route = pathnameToRoute(location.pathname);

// Common
// ---
showUsername(route);

// Route specific
// ---
switch (route) { // eslint-disable-line default-case
case ROUTES.MR:
case ROUTES.ISSUE:
// Enable when it will work properly
// assignMe();
// showUsername(route);
expandAll();
rotateDiscussion("notes-list");
expandSidePanel();
Expand All @@ -42,8 +49,6 @@ storage.load().then(() => {
case ROUTES.ISSUES:
filterItems("filtered-search-box");
alignLabels(route);
// Enable when it will work properly
// showUsername(route);
break;
}

Expand Down
6 changes: 3 additions & 3 deletions src/libs/transformations/discussionOverComment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default () => {
const el = document.getElementById('discussion');
el.click();
}
const el = document.getElementById("discussion");
el.click();
};
108 changes: 53 additions & 55 deletions src/libs/transformations/showUsername.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,82 +6,80 @@ import getUsername from "../helpers/getUsername";
export default route => {
switch (route) {
case ROUTES.MR:
case ROUTES.ISSUE:
case ROUTES.ISSUE: {
const commitsTab = document.getElementsByClassName("commits-tab")[0];
commitsTab.children[0].click();
const notesTab = document.getElementsByClassName("notes-tab")[0];
notesTab.children[0].click();
// eslint-disable-next-line no-plusplus
for (let j = 0; j < 7; j++) {
const className = [
"author has-tooltip",
"author_link bold",
"author_link has-tooltip",
"note-header-info",
"note-header-author-name",
"author_link",
"discussion-header",
"inline discussion-headline-light",
"commit-author-link has-tooltip",
"avatar has-tooltip s36 hidden-xs",
];
const a = document.getElementsByClassName(className[j]);
if (a !== undefined) {
// eslint-disable-next-line no-plusplus
for (let i = 0; i < a.length; i++) {
let username;
if (j === 2 || j === 4 || j === 6) username = getUsername(a[i]);
switch (j) {
case 0:
// Author
a[i].innerText = a[i].getAttribute("title").slice(1);
continue;
case 1:
// Assignees
a[i].children[1].innerText = a[i].children[2].innerText.slice(
1
);
continue;
case 2:
// Participants
a[i].setAttribute("title", username);
continue;
case 3:
// Discussion
if (a[i].children[0].childElementCount === 2) {
a[i].children[0].children[0].innerText = a[
i
].children[0].children[1].innerText.slice(1);
a[i].children[0].removeChild(a[i].children[0].children[1]);
}
continue;
case 4:
a[i].childNodes[0].innerText = username;
continue;
case 5:
a[i].children[2].innerText = a[i].children[2].innerText.replace(
`@${getUsername(a[i].children[1])}`,
""
);
continue;
case 6:
// Commits
// eslint-disable-next-line no-shadow
setTimeout((a, i) => {
// eslint-disable-next-line no-param-reassign
a[i].innerText = username;
}, 1000);
let a = document.getElementsByClassName(className[j]);
if (j === 6 || j === 7) a = [].slice.call(a);
// eslint-disable-next-line no-plusplus
for (let i = 0; i < a.length; i++) {
let username;
if (j === 2 || j === 4 || j === 6) username = getUsername(a[i]);
switch (j) {
case 0:
// Author
a[i].innerText = a[i].getAttribute("title").slice(1);
continue;
case 1:
// Assignees
a[i].children[1].innerText = a[i].children[2].innerText.slice(1);
continue;
case 2:
// Participants
a[i].setAttribute("title", username);
continue;
case 3:
// Discussion
a[i].innerText = getUsername(a[i].parentElement);
a[i].parentElement.children[1].remove();
continue;
case 4:
a[i].children[0].innerText = username;
continue;
case 5:
a[i].innerText = a[i].innerText.replace(
`@${getUsername(a[i].parentElement.children[1])}`,
""
);
continue;
case 6:
a[i].innerText = username;
continue;
case 7: {
const userName = getUsername(a[i].parentElement);
a[i].setAttribute("alt", `${userName}'s avatar`);
a[i].setAttribute("title", `${userName}`);
}
}
}
}
break;
}
case ROUTES.MRS:
case ROUTES.ISSUES: {
let a = document.getElementsByClassName("author_link");
a = [].slice.call(a);
// eslint-disable-next-line array-callback-return
a.map(element => {
const username = getUsername(element);
if (element.classList.contains("has-tooltip")) {
element.setAttribute("title", `Assigned to ${username}`);
} else {
// eslint-disable-next-line no-param-reassign
element.children[0].innerText = username;
}
// eslint-disable-next-line no-unused-expressions
element.classList.contains("has-tooltip")
? element.setAttribute("title", `Assigned to ${username}`)
: (element.children[0].innerText = username); // eslint-disable-line no-param-reassign
});
break;
}
Expand Down