-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracker-period-updater.user.js
74 lines (62 loc) · 3.1 KB
/
tracker-period-updater.user.js
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
// ==UserScript==
// @name TrackerPeriodUpdater
// @namespace https://github.com/achernyakevich-sc/dl-toolset-pub/
// @version 0.1.2
// @description This script brings possibility to move forward period of the tracker.
// @author Alexander Chernyakevich <tch@scand.com>
// @include /^https:\/\/.+\.ph.+us\.com\/(.+\/)*issues\/\d+(\/copy)*/
// @grant GM_log
// @grant GM_registerMenuCommand
// ==/UserScript==
(function() {
'use strict';
const updateForm = () => {
let subjectInput = document.getElementById("issue_subject");
let descriptionTextarea = document.getElementById("issue_description");
let statusSelect = document.getElementById("issue_status_id");
let assigneeSelect = document.getElementById("issue_assigned_to_id");
let periodInput = document.getElementById(periodInputId);
let linkIssueCheckbox = document.getElementById("link_copy");
let copyAttachmentsCheckbox = document.getElementById("copy_attachments");
let oldPeriod = parseInt(periodInput.value);
let year = Math.floor(oldPeriod / 100);
let month = (oldPeriod % 100) + 1;
if ( month > 12 ) {
year++;
month = month - 12;
}
let newPeriod = "" + year + ( month < 10 ? "0" : "" ) + month;
periodInput.value = newPeriod;
subjectInput.value = subjectInput.value.replace(oldPeriod, newPeriod)
if ( !isReportsHost ) {
document.getElementById("issue_custom_field_values_5").value = ""; // Report field
document.getElementById("issue_custom_field_values_8").value = ""; // Issuing Date field
document.getElementById("issue_custom_field_values_7").value = ""; // Payment Date field
document.getElementById("issue_custom_field_values_17").selectedIndex = 0; // Recorded field
let numberInput = document.getElementById("issue_custom_field_values_6");
numberInput.value = ( numberInput.value.trim() != "" ? parseInt(numberInput.value) + 1 : "" );
}
descriptionTextarea.value = "";
if ( linkIssueCheckbox ) {
linkIssueCheckbox.checked = false;
}
if ( copyAttachmentsCheckbox ) {
copyAttachmentsCheckbox.checked = false;
}
assigneeSelect.selectedIndex = 1;
statusSelect.selectedIndex = 0;
GM_log("Form updated.");
}
let isReportsHost = ( document.location.hostname.indexOf("reports") == 0 );
let periodInputId = ( isReportsHost ? "issue_custom_field_values_18" : "issue_custom_field_values_4" );
document.addEventListener("keydown", (event) => {
// GM_log("Ctrl: " + event.ctrlKey +"; Shift: " + event.shiftKey + "; Key: " + event.key + "; Code: " + event.code);
if (event.altKey && event.shiftKey && event.code == "KeyP") {
updateForm();
event.stopPropagation();
event.preventDefault();
}
}, true);
GM_log("TrackerPeriodUpdater: shortcuts assigned");
GM_registerMenuCommand("Updated period", updateForm, "p");
})();