diff --git a/images/calculator.svg b/images/calculator.svg new file mode 100644 index 0000000..6ff4a26 --- /dev/null +++ b/images/calculator.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/kaplus.js b/src/kaplus.js index fc64d06..a8aa6d5 100644 --- a/src/kaplus.js +++ b/src/kaplus.js @@ -31,6 +31,14 @@ function createRow(key, value) { return row; } +function createInput(type, name, value) { + let elt = document.createElement("input"); + elt.setAttribute("type", type); + elt.setAttribute("name", name); + elt.setAttribute("value", value); + return elt; +} + function shortcutElementReplace(elt, img, text) { // If more than one hyperlink element found, // then keep the last one but with href of the first one. @@ -208,6 +216,9 @@ function main() { let table = contentPane.getElementsByClassName("borderlist")[0]; let rows = table.getElementsByTagName("tr"); + let headCell = document.createElement("th"); + rows[0].appendChild(headCell); + for (let i = 1; i < rows.length; i ++) { let cells = rows[i].getElementsByTagName("td"); let arrivalDateCell = cells[3] @@ -218,6 +229,26 @@ function main() { let arrival = new Date(Date.now() + seconds * 1000); let hour = arrival.toLocaleTimeString("fr-FR"); arrivalDateCell.textContent = arrivalDateCell.textContent.replace(/(.*)\d\d:\d\d(.*)/, "$1" + hour + "$2"); + + let startPoint = cells[2].getElementsByTagName("a")[3].textContent.split("|"); + let targetPoint = cells[1].getElementsByTagName("a")[2].textContent.split("|"); + let calculatorCell = document.createElement("td"); + let calculatorForm = document.createElement("form"); + calculatorForm.setAttribute("method", "post"); + calculatorForm.setAttribute("action", "/?s=tools&m=runtime_calculator&inta=calculate"); + calculatorForm.appendChild(createInput("hidden", "start_x", startPoint[0])); + calculatorForm.appendChild(createInput("hidden", "start_y", startPoint[1])); + calculatorForm.appendChild(createInput("hidden", "target_x", targetPoint[0])); + calculatorForm.appendChild(createInput("hidden", "target_y", targetPoint[1])); + let calculatorImg = document.createElement("input"); + calculatorImg.setAttribute("type", "image"); + calculatorImg.setAttribute("src", chrome.runtime.getURL("images/calculator.svg")); + calculatorImg.style.width = "20px"; + calculatorImg.style.height = "20px"; + calculatorImg.style.border = "none"; + calculatorForm.appendChild(calculatorImg); + calculatorCell.appendChild(calculatorForm); + rows[i].appendChild(calculatorCell); } } }