Skip to content

Commit

Permalink
NPM 1.12.1; Fix runtime-sort for github actions runtime not working w…
Browse files Browse the repository at this point in the history
…ith textContent.
  • Loading branch information
LeeWannacott committed May 9, 2023
1 parent de573af commit ef454a4
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 99 deletions.
17 changes: 5 additions & 12 deletions browser-extension/addTableSortClass.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
document.body.style.border = "1px solid red";

function getTables() {
return document.querySelectorAll("table");
}
let tables = getTables();
console.log("tables", tables);
function addTableSortClass() {
let tablesWithTableSortClass = Array.from(tables).map((table) => {
return table.classList.add("table-sort");
});
return tablesWithTableSortClass;
}
addTableSortClass();
let tables = document.querySelectorAll("table");

Array.from(tables).map((table) => {
return table.classList.add("table-sort");
});
7 changes: 0 additions & 7 deletions browser-extension/getTableHeaders.js

This file was deleted.

5 changes: 2 additions & 3 deletions browser-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"icons": { "48": "icons/t.png" },
"browser_action": {
"default_icon": "./icons/t.png",
"default_title": "table-sort",
"default_popup": "popup/table-options.html"
"default_title": "table-sort-js"
},
"content_scripts": [
{
Expand All @@ -17,7 +16,7 @@
"*://*.mozilla.org/*",
"https://github.com/*/*/actions/runs/*/usage"
],
"js": ["addTableSortClass.js", "getTableHeaders.js", "table-sort.js"]
"js": ["addTableSortClass.js", "table-sort.js"]
}
]
}
17 changes: 0 additions & 17 deletions browser-extension/popup/table-options.html

This file was deleted.

16 changes: 0 additions & 16 deletions browser-extension/setButtons.js

This file was deleted.

52 changes: 31 additions & 21 deletions browser-extension/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,30 +177,40 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}

function sortByRuntime(tableRows, columnData) {
for (let [i, tr] of tableRows.entries()) {
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
let columnOfTd = tr
.querySelectorAll("td")
.item(columnIndex).textContent;
let match = columnOfTd.match(regexMinutesAndSeconds);
let [minutesInSeconds, hours, seconds, timeinSeconds] = [0, 0, 0, 0];
if (match) {
const regexHours = match[1];
if (regexHours) {
hours = Number(regexHours.replace("h", "")) * 60 * 60;
}
const regexMinutes = match[2];
if (regexMinutes) {
minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60;
try {
for (let [i, tr] of tableRows.entries()) {
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
let columnOfTd = "";
// TODO: github actions runtime didn't like textContent, tests didn't like innerText?
if (testingTableSortJS) {
columnOfTd = tr
.querySelectorAll("td")
.item(columnIndex).textContent;
} else {
columnOfTd = tr.querySelectorAll("td").item(columnIndex).innerText;
}
const regexSeconds = match[3];
if (regexSeconds) {
seconds = Number(regexSeconds.replace("s", ""));
let match = columnOfTd.match(regexMinutesAndSeconds);
let [minutesInSeconds, hours, seconds, timeinSeconds] = [0, 0, 0, 0];
if (match) {
const regexHours = match[1];
if (regexHours) {
hours = Number(regexHours.replace("h", "")) * 60 * 60;
}
const regexMinutes = match[2];
if (regexMinutes) {
minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60;
}
const regexSeconds = match[3];
if (regexSeconds) {
seconds = Number(regexSeconds.replace("s", ""));
}
timeinSeconds = hours + minutesInSeconds + seconds;
}
timeinSeconds = hours + minutesInSeconds + seconds;
columnData.push(`${timeinSeconds}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.innerHTML;
}
columnData.push(`${timeinSeconds}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.innerHTML;
} catch (e) {
console.log(e);
}
}

Expand Down
52 changes: 31 additions & 21 deletions npm/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,30 +177,40 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}

function sortByRuntime(tableRows, columnData) {
for (let [i, tr] of tableRows.entries()) {
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
let columnOfTd = tr
.querySelectorAll("td")
.item(columnIndex).textContent;
let match = columnOfTd.match(regexMinutesAndSeconds);
let [minutesInSeconds, hours, seconds, timeinSeconds] = [0, 0, 0, 0];
if (match) {
const regexHours = match[1];
if (regexHours) {
hours = Number(regexHours.replace("h", "")) * 60 * 60;
}
const regexMinutes = match[2];
if (regexMinutes) {
minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60;
try {
for (let [i, tr] of tableRows.entries()) {
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
let columnOfTd = "";
// TODO: github actions runtime didn't like textContent, tests didn't like innerText?
if (testingTableSortJS) {
columnOfTd = tr
.querySelectorAll("td")
.item(columnIndex).textContent;
} else {
columnOfTd = tr.querySelectorAll("td").item(columnIndex).innerText;
}
const regexSeconds = match[3];
if (regexSeconds) {
seconds = Number(regexSeconds.replace("s", ""));
let match = columnOfTd.match(regexMinutesAndSeconds);
let [minutesInSeconds, hours, seconds, timeinSeconds] = [0, 0, 0, 0];
if (match) {
const regexHours = match[1];
if (regexHours) {
hours = Number(regexHours.replace("h", "")) * 60 * 60;
}
const regexMinutes = match[2];
if (regexMinutes) {
minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60;
}
const regexSeconds = match[3];
if (regexSeconds) {
seconds = Number(regexSeconds.replace("s", ""));
}
timeinSeconds = hours + minutesInSeconds + seconds;
}
timeinSeconds = hours + minutesInSeconds + seconds;
columnData.push(`${timeinSeconds}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.innerHTML;
}
columnData.push(`${timeinSeconds}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.innerHTML;
} catch (e) {
console.log(e);
}
}

Expand Down
6 changes: 4 additions & 2 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
for (let [i, tr] of tableRows.entries()) {
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
let columnOfTd = "";
// TODO: github actions runtime didn't like textContent, tests didn't like innerText?
// TODO: github actions runtime didn't like textContent, tests didn't like innerText?
if (testingTableSortJS) {
columnOfTd = tr.querySelectorAll("td").item(columnIndex).textContent;
columnOfTd = tr
.querySelectorAll("td")
.item(columnIndex).textContent;
} else {
columnOfTd = tr.querySelectorAll("td").item(columnIndex).innerText;
}
Expand Down

0 comments on commit ef454a4

Please sign in to comment.