Repository navigation
Expand file tree
/
Copy pathTech Notes Button.user.js
More file actions
85 lines (75 loc) · 2.13 KB
/
Copy pathTech Notes Button.user.js
File metadata and controls
85 lines (75 loc) · 2.13 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
81
82
83
84
85
// ==UserScript==
// @name Tech Notes Button
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Adds a button to add a new entry in the tech notes
// @author Luke Miletta
// @match https://oregonstate.teamdynamix.com/TDNext/Apps/*/Tickets/Edit?TicketID=*
// @match https://oregonstate.teamdynamix.com/TDNext/Apps/*/Tickets/New?formId=*
// @grant none
// ==/UserScript==
// Date Object
var d = new Date();
//AM or PM function
var am_or_pm = "";
var hours = d.getHours();
if(hours > 11){
hours = hours - 12;
am_or_pm = "pm";
}
else if(hours == 0){
am_or_pm = "am";
hours = 12;
}
else {
am_or_pm = "am";
}
var min = d.getMinutes();
if(min < 10){
min = "0" + min;
}
var time_string = "" + hours + ":" + min + am_or_pm + ":\n";
var date = d.getDate();
if(date < 10){
date = "0" + date;
}
var date_string = "" + (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear() + " " + time_string + "\n-Luke Miletta\n";
// Form Where Internal Notes Exist
var form = document.getElementById("attribute53162-grp");
var text_field = form.childNodes;
text_field.forEach(function(element){
if(element.className == "js-ca"){
text_field = element;
}
});
text_field = text_field.childNodes;
if(text_field[1]){
text_field.forEach(function(element){
if(element.id == "attribute53162"){
text_field = element;
}
});
}
else{
text_field = text_field[0];
}
// 1. Create the button
var button1 = document.createElement("form-button");
button1.setAttribute("type", "button");
button1.innerHTML = "Add a New Entry";
button1.setAttribute("class", "btn btn-primary btn-sm js-progress-button");
button1.setAttribute("id", "form-button");
// 2. Append somewhere
form.appendChild(button1);
// 3. Add event handler
button1.addEventListener ("click", click_form_button);
// Function that handles click of form button
function click_form_button(){
// Insert Date and Time Below Data Field
if(text_field.value == ""){
text_field.value = date_string;
}
else{
text_field.value = date_string + "\n" + text_field.value;
}
}