-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHaloPSA Prevent Leaving When Entering Ticket Notes.user.js
More file actions
66 lines (57 loc) · 2.38 KB
/
HaloPSA Prevent Leaving When Entering Ticket Notes.user.js
File metadata and controls
66 lines (57 loc) · 2.38 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
// ==UserScript==
// @name HaloPSA Prevent Leaving When Entering Ticket Notes
// @namespace http://tampermonkey.net/
// @version 2024-10-21
// @description HaloPSA Prevent Leaving When Entering Ticket Notes
// @author Andrea Mastellone
// @match https://service.intellicomp.net/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=intellicomp.net
// @grant none
// @downloadURL https://github.com/intellicomp/UserScripts/raw/refs/heads/main/HaloPSA%20Prevent%20Leaving%20When%20Entering%20Ticket%20Notes.user.js
// @updateURL https://github.com/intellicomp/UserScripts/raw/refs/heads/main/HaloPSA%20Prevent%20Leaving%20When%20Entering%20Ticket%20Notes.user.js
// ==/UserScript==
(function () {
'use strict';
function onBeforeUnload(e) {
// Cancel the event
e.preventDefault();
// Chrome requires returnValue to be set
e.returnValue = '';
}
function activateReloader() {
window.addEventListener('beforeunload', onBeforeUnload);
}
function deactivateReloader() {
window.removeEventListener('beforeunload', onBeforeUnload);
}
function onElementAvailable(selector, callback) {
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
callback();
}
});
observer.observe(document.body, { childList: true, subtree: true });
}
onElementAvailable("#ticketdetails-details", () => {
// Element-specific code here
const targetNode = document.getElementById('ticketdetails-details');
function callback(mutationsList, observer) {
mutationsList.forEach((mutation) => {
console.log(mutation.type);
if (mutation.type === 'childList') {
if (document.querySelector(".action-history-item.wcontainer.isadding")) {
activateReloader();
console.log('notes exists');
} else {
deactivateReloader();
console.log('notes removed');
}
}
});
};
const observer = new MutationObserver(callback);
const config = { childList: true, subtree: true };
observer.observe(targetNode, config);
});
})();