-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
36 lines (32 loc) · 1.48 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var REMOVE_NODE = true; //Paramaeter to determine if the node is to be deleted or only colors are to be hidden
var REGEX_TO_MATCH_WHITE_SPACES = /(\r\n|\n|\r| )/gm;
var STRING_TO_REPLACE_WITH = '';
function handleWhiteSpacesInGitlabMergeRequests() {
var line_holders = document.querySelector('.files').querySelectorAll('.line_holder');
line_holders.forEach(line_holder => {
var lineContent = line_holder.querySelectorAll('.line_content');
var oldLineContent = lineContent[0];
var newLineContent = lineContent[1];
var diffIsShown = oldLineContent.classList.contains('old') || newLineContent.classList.contains('new'); //to make sure change is shown on both left and right
if (diffIsShown) {
var isWrondDiffShown = oldLineContent.textContent.replace(REGEX_TO_MATCH_WHITE_SPACES, STRING_TO_REPLACE_WITH) === newLineContent.textContent.replace(REGEX_TO_MATCH_WHITE_SPACES, STRING_TO_REPLACE_WITH);
//trim all whitespaces
if (isWrondDiffShown) {
if (REMOVE_NODE) {
console.log('Removing this node: ', line_holder);
line_holder.remove()
} else {
console.log('Removing colors from this node: ', line_holder);
line_holder.querySelectorAll('td').forEach(el => el.classList.remove('old', 'new'));
}
}
}
});
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.message === "clicked_browser_action") {
handleWhiteSpacesInGitlabMergeRequests();
}
}
);