forked from arnoudkooi/SN-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject_parent.js
More file actions
72 lines (54 loc) · 2.8 KB
/
inject_parent.js
File metadata and controls
72 lines (54 loc) · 2.8 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
setTimeout(function () { //be sure dompurify is loaded
//Initialize Alert
var parent = document.querySelector('body');
var alertContainer = document.createElement('div');
alertContainer.innerHTML = DOMPurify.sanitize('<input id="sn_gck" type="hidden" value="' + (g_ck || '') + '" /><div style="display:none" class="notification-container service-now-util-alert" role="alert" ><div class="notification outputmsg outputmsg_has_text" style="top: 20px;"><span class="outputmsg_text role="alert"></span></div></div>');
parent.insertBefore(alertContainer, parent.firstChild);
},1500);
function addDblClickToPin(){
setTimeout(function () {
var snuHeader = document.querySelector("macroponent-f51912f4c700201072b211d4d8c26010")?.
shadowRoot?.querySelector("sn-polaris-layout")?.
shadowRoot?.querySelector("sn-polaris-header");
snuHeader?.shadowRoot?.querySelectorAll(".sn-polaris-tab:not(.tab-overflow)").forEach(div => {
div.title = '[SN Utils] Doubleclick to pin';
div.addEventListener('dblclick', evt => {
evt.preventDefault();
snuHeader.dispatch('MAIN_MENU#PINNED', { "isPrimary": false,
"primaryMenuId": "all",
"secondaryMenuId": div.id,
"doPinning": true})
})
})
},6500);
}
function addStudioLink() {
if (typeof jQuery == 'undefined') return;
waitForEl('#concourse_application_tree li', function () {
var addStudio = jQuery('a[href*="$studio.do"]').length;
var isUI16 = jQuery('.navpage-header-content').length > 0;
var widgetHtml;
if (!isUI16) return;
if (addStudio) {
widgetHtml = '<div class="navpage-header-content">' +
'<button data-placement="auto" class="btn btn-icon icon-cards"' +
' title="Quick Application Switch (By SN Utils)\nSlashcommand: /sa" data-original-title="Studio" onclick="snuShowSlashCommand(\'/sa\',1);">' +
'<span class="sr-only">Studio</span>' +
'</button>' +
'<button data-placement="auto" class="btn btn-icon icon-script"' +
' title="Open Studio IDE (Link by SN Utils)\nSlashcommand: /st" data-original-title="Studio" onclick="window.open(\'/$studio.do\', \'_blank\');">' +
'<span class="sr-only">Studio</span>' +
'</button></div>';
jQuery('#sysparm_search').parents('div.navpage-header-content').first().after(widgetHtml);
}
});
}
function waitForEl(selector, callback) {
if (document.querySelectorAll(selector).length) {
callback();
} else {
setTimeout(function () {
waitForEl(selector, callback);
}, 300);
}
};