Last active
April 15, 2021 10:05
-
-
Save edwinclement08/e247116da4233f71aaf2f3a3a0a52a2e to your computer and use it in GitHub Desktop.
Helpers for summary_logs page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Add some delta info to summary_logs page | |
// @namespace Violentmonkey Scripts | |
// @match https://www.browserstack.com/admin/summary_logs | |
// @grant none | |
// @version 1.0 | |
// @author - | |
// @description 14/04/2021, 14:16:19 | |
// ==/UserScript== | |
if (document.querySelectorAll(".data_table").length === 1 && document.querySelectorAll('.th-time_run').length === 0) { | |
session_ids = document.querySelectorAll('.data_table tbody tr td:nth-child(9)') | |
created_at = document.querySelectorAll('.data_table tbody tr td:nth-child(10)') | |
updated_at = document.querySelectorAll('.data_table tbody tr td:nth-child(11)') | |
tunnel_enabled = document.querySelectorAll('.data_table tbody tr td:nth-child(15)') | |
function msToTime(ms) { | |
let seconds = (ms / 1000).toFixed(1); | |
let minutes = (ms / (1000 * 60)).toFixed(1); | |
let hours = (ms / (1000 * 60 * 60)).toFixed(1); | |
let days = (ms / (1000 * 60 * 60 * 24)).toFixed(1); | |
if (seconds < 60) return seconds + " Sec"; | |
else if (minutes < 60) return minutes + " Min"; | |
else if (hours < 24) return hours + " Hrs"; | |
else return days + " Days" | |
} | |
console.log('not yet added'); | |
header = document.querySelector('.data_table tbody tr th:nth-child(11)') | |
console.log(header.innerText) | |
var node = document.createElement("th"); | |
var textnode = document.createTextNode("delta"); | |
node.append(textnode) | |
node.className = 'th-time_run' | |
header.insertAdjacentElement("afterend", node) | |
date = (dd) => { | |
sp = dd.innerText.split(' '); | |
return new Date(`${sp[0]}T${sp[1]}Z`) | |
} | |
i = 0 | |
while (i < created_at.length) { | |
start = date(created_at[i]) | |
end = date(updated_at[i]) | |
delta = msToTime(end - start) | |
var n = document.createElement("td"); | |
var t = document.createTextNode(delta); | |
n.append(t) | |
updated_at[i].insertAdjacentElement("afterend", n) | |
i += 1 | |
} | |
// make dates easier to read | |
dateString = (dd) => { | |
sp = dd.innerText.split(' '); | |
return `${sp[0]} ${sp[1]}` | |
} | |
i = 0 | |
while (i < created_at.length) { | |
c_date = created_at[i].innerText.substring(0, 10); | |
u_date = updated_at[i].innerText.substring(0, 10); | |
c_string = dateString(created_at[i]) | |
u_string_pre = dateString(updated_at[i]) | |
console.log(u_date) | |
u_string = (c_date === u_date) ? u_string_pre.substr(11).padStart(19,' ') : u_string_pre; | |
created_at[i].innerHTML = '<pre>' + c_string + '\n' + u_string + '</pre>'; | |
created_at[i].style.fontSize = "medium" | |
updated_at[i].remove(); | |
i += 1; | |
} | |
createdHeader = document.querySelector('.data_table tbody tr th:nth-child(10)') | |
createdHeader.remove() | |
timeHeader = document.querySelector('.data_table tbody tr th:nth-child(10)') | |
timeHeader.innerText = "Session Time" | |
// add hyperdrive link | |
i = 0 | |
while (i < session_ids.length) { | |
var n = document.createElement("a"); | |
n.href = `https://hyperdrive.bsstag.com/local/search?session_id=${session_ids[i].innerText}` | |
n.target = "_blank" | |
var t = document.createTextNode("Hyperdrive"); | |
n.append(document.createElement("br")) | |
n.append(document.createElement("br")) | |
n.append(t) | |
if (tunnel_enabled[i].innerText === '1') { | |
session_ids[i].insertAdjacentElement("beforeend", n) | |
} | |
i += 1 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment