github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/html/pages/common.js (about) 1 // Copyright 2018 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 function sortTable(item, colName, conv, desc = false) { 5 table = item.parentNode.parentNode.parentNode.parentNode; 6 rows = table.rows; 7 col = findColumnByName(rows[0].getElementsByTagName("th"), colName); 8 values = []; 9 for (i = 1; i < rows.length; i++) { 10 const td = rows[i].getElementsByTagName("td")[col] 11 let value = td.textContent 12 if (td.getAttribute("sort-value") != null) 13 value = td.getAttribute("sort-value") 14 values.push([conv(value), rows[i]]); 15 } 16 if (desc) 17 desc = !isSorted(values.slice().reverse()) 18 else 19 desc = isSorted(values); 20 values.sort(function(a, b) { 21 if (a[0] == b[0]) return 0; 22 if (desc && a[0] > b[0] || !desc && a[0] < b[0]) return -1; 23 return 1; 24 }); 25 for (i = 0; i < values.length; i++) 26 table.tBodies[0].appendChild(values[i][1]); 27 return false; 28 } 29 30 function findColumnByName(headers, colName) { 31 for (i = 0; i < headers.length; i++) { 32 if (headers[i].textContent == colName) 33 return i; 34 } 35 return 0; 36 } 37 38 function isSorted(values) { 39 for (i = 0; i < values.length - 1; i++) { 40 if (values[i][0] > values[i + 1][0]) 41 return false; 42 } 43 return true; 44 } 45 46 function textSort(v) { return v == "" ? "zzz" : v.toLowerCase(); } 47 function numSort(v) { return -parseInt(v); } 48 function floatSort(v) { return -parseFloat(v); } 49 function reproSort(v) { return v == "C" ? 0 : v == "syz" ? 1 : 2; } 50 function patchedSort(v) { return v == "" ? -1 : parseInt(v); } 51 function lineSort(v) { return -v.split(/\r\n|\r|\n/g).length } 52 53 function timeSort(v) { 54 if (v == "now") 55 return 0; 56 m = v.indexOf('m'); 57 h = v.indexOf('h'); 58 d = v.indexOf('d'); 59 if (m > 0 && h < 0) 60 return parseInt(v); 61 if (h > 0 && m > 0) 62 return parseInt(v) * 60 + parseInt(v.substring(h + 1)); 63 if (d > 0 && h > 0) 64 return parseInt(v) * 60 * 24 + parseInt(v.substring(d + 1)) * 60; 65 if (d > 0) 66 return parseInt(v) * 60 * 24; 67 return 1000000000; 68 } 69 70 71 72 function findAncestorByClass (el, cls) { 73 while ((el = el.parentElement) && !el.classList.contains(cls)); 74 return el; 75 } 76 77 function deleteInputGroup(node) { 78 group = findAncestorByClass(node, "input-group") 79 values = findAncestorByClass(group, "input-values") 80 if (!values) { 81 return false 82 } 83 count = values.querySelectorAll('.input-group').length 84 if (count == 1) { 85 // If it's the only input, just clear it. 86 input = group.querySelector('input') 87 input.value = "" 88 } else { 89 group.remove() 90 } 91 return false 92 } 93 94 function addInputGroup(node) { 95 values = findAncestorByClass(node, "input-values") 96 groups = values.querySelectorAll(".input-group") 97 if (groups.length == 0) { 98 // Something strange has happened. 99 return false 100 } 101 lastGroup = groups[groups.length - 1] 102 newGroup = lastGroup.cloneNode(true) 103 newGroup.querySelector('input').value = "" 104 values.insertBefore(newGroup, lastGroup.nextSibling) 105 return false 106 } 107 108 document.addEventListener("DOMContentLoaded", function() { 109 document.addEventListener('click', function(event) { 110 const collapsible = event.target.closest('.collapsible') 111 if (!collapsible) { 112 return 113 } 114 const toggle = event.target.closest('.collapsible .head'); 115 if (toggle) { 116 collapsible.classList.toggle("collapsible-hide"); 117 collapsible.classList.toggle("collapsible-show"); 118 } 119 }) 120 })