-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetterlayout.user.js
More file actions
71 lines (64 loc) · 2.89 KB
/
Copy pathbetterlayout.user.js
File metadata and controls
71 lines (64 loc) · 2.89 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
// ==UserScript==
// @name Jira Better Layout Script
// @namespace https://github.com/HuongNV13
// @version 1.0
// @description Jira Better Layout Script for Moodlers
// @author Huong Nguyen
// @homepage https://github.com/HuongNV13/moodle-userscripts
// @downloadURL https://github.com/HuongNV13/moodle-userscripts/raw/main/betterlayout.user.js
// @updateURL https://github.com/HuongNV13/moodle-userscripts/raw/main/betterlayout.user.js
// @match https://moodle.atlassian.net/browse/*
// @match https://moodle.atlassian.net/issues/*
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
const selectors = {
target: 'div[data-testid="issue.views.issue-base.context.status-and-approvals-wrapper.status-and-approval"]',
transitionButton: 'div[data-testid="issue.views.issue-base.foundation.status.status-field-wrapper"]',
automationButton: 'div[data-testid="issue.views.issue-base.foundation.status.actions-wrapper"] button',
freshDeskField: 'div[data-testid="issue.views.issue-base.context.ecosystem.connect.field-wrapper"]',
};
const updateView = () => {
// Get the transition button element.
const transitionElement = $(selectors.transitionButton);
// Get the parent of the parent (grandparent).
const grandparent = transitionElement.parent().parent().parent().parent();
// Move the automation button to the grandparent.
const automationButton = $(selectors.automationButton);
automationButton.appendTo(grandparent);
// Move the grandparent to the target.
grandparent.appendTo($(selectors.target));
console.log("Moved transition button to target area.");
// Remove the FreshDesk fields if it exists.
const freshDeskFields = $(selectors.freshDeskField);
if (freshDeskFields.length > 0) {
freshDeskFields.each(function() {
$(this).parent().parent().remove();
});
}
}
// Wait for custom field to be available.
const waitForCustomField = () => {
console.log("Checking for custom field...");
if ($(selectors.freshDeskField).length > 0 && $(selectors.target).length > 0) {
console.log("Custom field found, calling updateView");
updateView();
} else {
setTimeout(waitForCustomField, 1000);
}
};
// Use a longer delay to ensure Jira has fully loaded.
const startScript = () => {
if (typeof AJS === 'undefined') {
console.log("AJS not loaded yet, retrying...");
setTimeout(startScript, 1000);
return;
}
console.log("AJS loaded, starting to wait for custom field");
waitForCustomField();
};
setTimeout(startScript, 2000);
})();