-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtc-userscript.js
More file actions
80 lines (61 loc) · 2.46 KB
/
tc-userscript.js
File metadata and controls
80 lines (61 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// ==UserScript==
// @name ThreatConnect Utilities userscript
// @author wesinator
// @version 1.1
// @grant none
// @match https://*.threatconnect.com/*
// @run-at document-idle
// ==/UserScript==
if (window.location.pathname == "/auth/settings/user.xhtml") {
setTimeout(function() {
// Follow Settings link #form:tabView:j_idt213 no id :(
var groupFollows = document.getElementById("form:tabView:notificationIncidentTable_data");
if (groupFollows) {
var getFollows = confirm("Do you want to download the follow settings to backup file ?");
if (getFollows) {
var groups = getTableText(groupFollows);
var indicatorFollows = document.getElementById("form:tabView:notificationIndicatorTable_data");
var indicators = getTableText(indicatorFollows);
var follows = groups.concat(indicators);
return arrayToFile(follows, "TC_follows_backup.txt");
}
}
}, 5000);
}
// save current list to file
if (window.location.href.toString().includes("enhanced/browse/groups")) {
setTimeout(function() {
groupCsv = "Type,Name/Summary,link,TagCount,DateAdded,LastModified\r\n"
tcTable = document.getElementsByClassName('ui-table-tbody')[1];
for (var item of tcTable.children) {
cols = item.children;
type = cols[0].innerText;
name = cols[1].innerText;
link = cols[1].getElementsByTagName('a')[0].href;
tagcount = cols[2].innerText;
dateadded = cols[3].innerText;
lastmodified = cols[4].innerText;
groupCsv = groupCsv + `${type},"${name}",${link},${tagcount},${dateadded},${lastmodified}\r\n`;
}
fileDataDownload(groupCsv, "tc_group_table.csv", "text/plain");
}, 8000);
}
function getTableText(table) {
list = [];
for (var entry of table.children) {
console.log(entry.innerText);
list.push(entry.innerText);
}
return list;
}
function arrayToFile(list, filename) {
return fileDataDownload(list.join('\n'), filename, "text/plain");
}
function fileDataDownload(contents, name, mimeType) {
// https://stackoverflow.com/questions/34101871/save-data-using-greasemonkey-tampermonkey-for-later-retrieval
var a = document.createElement("a");
a.href = `data:${mimeType};charset=utf-8,` + encodeURIComponent(contents);
a.download = name;
a.click();
}
// document.getElementById("j_idt112:modificationHostName").value = document.getElementById("j_idt112:modificationHostName").value.trim();