Skip to content

Commit

Permalink
fix(navigation): fix ajax navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-brito committed Feb 11, 2020
1 parent 250ee84 commit e52523c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 59 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# refactoring-diff
# refactoring-diff

Chrome Extension for RefDiff Integration in Github Review.

## Example of usage

- Download a [realese](https://github.com/rodrigo-brito/refactoring-diff/releases)
- See a refactoring example [here](https://github.com/rodrigo-brito/refactoring-diff-example/pull/3/files)

## Preview

![image](https://user-images.githubusercontent.com/7620947/74206000-61ced780-4c58-11ea-8478-46e02bd059e9.png)
47 changes: 25 additions & 22 deletions js/build/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,35 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
switch (request.message) {
case "data":
if (urlEqual(request.url, currentPage)) {
console.log("same page, skipping...");
return;
}

currentPage = request.url.split("#diff")[0];
var files = document.querySelectorAll(".file");
files.forEach(function (file) {
var header = file.querySelector(".file-info > a");
var fileName = header.textContent;
var link = header.getAttribute("href");
fileMap[fileName] = {
ref: file,
link: link
};
});
console.log("DATA = ", request.data);
request.data.refactorings.forEach(function (refactoring) {
var beforeFile = fileMap[refactoring.before_file_name];
var afterFile = fileMap[refactoring.after_file_name];
addRefactorings(beforeFile.ref, "".concat(afterFile.link, "R").concat(refactoring.after_line_number), refactoring, "L");
addRefactorings(afterFile.ref, "".concat(beforeFile.link, "L").concat(refactoring.before_line_number), refactoring, "R");

if (beforeFile && afterFile) {
addRefactorings(beforeFile.ref, "".concat(afterFile.link, "R").concat(refactoring.after_line_number), refactoring, "L");
addRefactorings(afterFile.ref, "".concat(beforeFile.link, "L").concat(refactoring.before_line_number), refactoring, "R");
}
});
}
});
window.addEventListener("load", function () {
popup.setAttribute("class", "diff-refector-popup");
popup.innerHTML = "\n <button class=\"diff-refector-popup-close btn btn-sm btn-default\">x</button>\n <p><b class=\"refactor-type\"></b></p>\n <div class=\"refactor-content\"></div>\n <a class=\"btn btn-sm btn-primary refactor-link\" href=\"#\">Go to block</a>\n ";
popup.innerHTML = "\n <button class=\"diff-refector-popup-close btn btn-sm btn-default\">x</button>\n <p><b class=\"refactor-type\"></b></p>\n <div class=\"refactor-content\"></div>\n <a class=\"btn btn-sm btn-primary refactor-link\" href=\"#\">Go to source</a>\n ";

popup.showDiff = function (element, type, diffHTML, interval) {
popup.style.setProperty("display", "block");
Expand All @@ -167,17 +179,6 @@ window.addEventListener("load", function () {
document.querySelector(".diff-refector-popup-close").addEventListener("click", function () {
popup.style.setProperty("display", "none");
});
var files = document.querySelectorAll(".file");
files.forEach(function (file) {
var header = file.querySelector(".file-info > a");
var fileName = header.textContent;
var link = header.getAttribute("href");
console.log("File=" + fileName + " Link=" + link);
fileMap[fileName] = {
ref: file,
link: link
};
});
chrome.runtime.sendMessage({
message: "fetch",
url: document.location.href.split("#diff")[0]
Expand All @@ -196,8 +197,6 @@ function addRefactorings(file, link, refactoring, side) {
}

file.querySelectorAll(selector).forEach(function (line) {
console.log("seraching for ", lineNumber, "side = ", side);

if (!line.querySelector("[data-line=\"".concat(lineNumber, "\"]"))) {
return;
}
Expand All @@ -206,17 +205,21 @@ function addRefactorings(file, link, refactoring, side) {

switch (refactoring.type) {
case "RENAME":
contentHTML = "<p>".concat(refactoring.before_local_name, " to ").concat(refactoring.after_local_name, "</p>");
contentHTML = "<p><code>".concat(refactoring.before_local_name, "</code> to <code>").concat(refactoring.after_local_name, "</code></p>");
break;

case "MOVE":
contentHTML = "<p>".concat(refactoring.object_type, " ").concat(refactoring.before_local_name, " moved.</p>");
contentHTML += "<p>Origin: ".concat(refactoring.before_file_name, ":").concat(refactoring.before_line_number, "</p>");
contentHTML += "<p>Destiny: ".concat(refactoring.after_file_name, ":").concat(refactoring.after_line_number, "</p>");
contentHTML = "<p><code>".concat(refactoring.before_local_name, "</code> moved.</p>");
contentHTML += "<p>Origin: <code>".concat(refactoring.before_file_name, ":").concat(refactoring.before_line_number, "</code></p>");
contentHTML += "<p>Destiny: <code>".concat(refactoring.after_file_name, ":").concat(refactoring.after_line_number, "</code></p>");
break;

default:
contentHTML = "<p>".concat(refactoring.type, ": ").concat(refactoring.object_type, " <code>").concat(refactoring.before_local_name, "</code></p>");
contentHTML += "<p>Origin: <code>".concat(refactoring.before_file_name, ":").concat(refactoring.before_line_number, "</code></p>");
contentHTML += "<p>Destiny: <code>".concat(refactoring.after_file_name, ":").concat(refactoring.after_line_number, "</code></p>");
}

console.log("found line!!!!");
var button = document.createElement("button");
button.setAttribute("class", "btn-refector");
button.addEventListener("click", function () {
Expand Down
73 changes: 37 additions & 36 deletions js/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,42 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
switch (request.message) {
case "data":
if (urlEqual(request.url, currentPage)) {
console.log("same page, skipping...");
return;
}
currentPage = request.url.split("#diff")[0];

var files = document.querySelectorAll(".file");
files.forEach(file => {
var header = file.querySelector(".file-info > a");
var fileName = header.textContent;
var link = header.getAttribute("href");

fileMap[fileName] = {
ref: file,
link: link
};
});

console.log("DATA = ", request.data);
request.data.refactorings.forEach(refactoring => {
var beforeFile = fileMap[refactoring.before_file_name];
var afterFile = fileMap[refactoring.after_file_name];
addRefactorings(
beforeFile.ref,
`${afterFile.link}R${refactoring.after_line_number}`,
refactoring,
"L"
);

addRefactorings(
afterFile.ref,
`${beforeFile.link}L${refactoring.before_line_number}`,
refactoring,
"R"
);

if (beforeFile && afterFile) {
addRefactorings(
beforeFile.ref,
`${afterFile.link}R${refactoring.after_line_number}`,
refactoring,
"L"
);

addRefactorings(
afterFile.ref,
`${beforeFile.link}L${refactoring.before_line_number}`,
refactoring,
"R"
);
}
});
}
});
Expand All @@ -42,7 +56,7 @@ window.addEventListener("load", function() {
<button class="diff-refector-popup-close btn btn-sm btn-default">x</button>
<p><b class="refactor-type"></b></p>
<div class="refactor-content"></div>
<a class="btn btn-sm btn-primary refactor-link" href="#">Go to block</a>
<a class="btn btn-sm btn-primary refactor-link" href="#">Go to source</a>
`;

popup.showDiff = function(element, type, diffHTML, interval) {
Expand Down Expand Up @@ -70,20 +84,6 @@ window.addEventListener("load", function() {
popup.style.setProperty("display", "none");
});

var files = document.querySelectorAll(".file");
files.forEach(file => {
var header = file.querySelector(".file-info > a");
var fileName = header.textContent;
var link = header.getAttribute("href");

console.log("File=" + fileName + " Link=" + link);

fileMap[fileName] = {
ref: file,
link: link
};
});

chrome.runtime.sendMessage({
message: "fetch",
url: document.location.href.split("#diff")[0]
Expand All @@ -104,25 +104,26 @@ function addRefactorings(file, link, refactoring, side) {
}

file.querySelectorAll(selector).forEach(line => {
console.log("seraching for ", lineNumber, "side = ", side);
if (!line.querySelector(`[data-line="${lineNumber}"]`)) {
return;
}

var contentHTML;
switch (refactoring.type) {
case "RENAME":
contentHTML = `<p>${refactoring.before_local_name} to ${refactoring.after_local_name}</p>`;
contentHTML = `<p><code>${refactoring.before_local_name}</code> to <code>${refactoring.after_local_name}</code></p>`;
break;
case "MOVE":
contentHTML = `<p>${refactoring.object_type} ${refactoring.before_local_name} moved.</p>`;
contentHTML += `<p>Origin: ${refactoring.before_file_name}:${refactoring.before_line_number}</p>`;
contentHTML += `<p>Destiny: ${refactoring.after_file_name}:${refactoring.after_line_number}</p>`;
contentHTML = `<p><code>${refactoring.before_local_name}</code> moved.</p>`;
contentHTML += `<p>Origin: <code>${refactoring.before_file_name}:${refactoring.before_line_number}</code></p>`;
contentHTML += `<p>Destiny: <code>${refactoring.after_file_name}:${refactoring.after_line_number}</code></p>`;
break;
default:
contentHTML = `<p>${refactoring.type}: ${refactoring.object_type} <code>${refactoring.before_local_name}</code></p>`;
contentHTML += `<p>Origin: <code>${refactoring.before_file_name}:${refactoring.before_line_number}</code></p>`;
contentHTML += `<p>Destiny: <code>${refactoring.after_file_name}:${refactoring.after_line_number}</code></p>`;
}

console.log("found line!!!!");

var button = document.createElement("button");
button.setAttribute("class", "btn-refector");
button.addEventListener("click", () => {
Expand Down

0 comments on commit e52523c

Please sign in to comment.