Last active
May 27, 2021 03:43
-
-
Save kbni/cc7f55ed353654cc5d35a235b0ea4c5f to your computer and use it in GitHub Desktop.
HaloPSA Tweaks (User Script)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name HaloPSA Tweaks | |
// @namespace https://kbni.net.au/ | |
// @version 20210528.1342 | |
// @description just some HaloPSA tweaks | |
// @author Alex Wilson | |
// @match https://psa.anspired.com.au/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var $ = window.$; | |
window._awoxHaloTweaks = { | |
debugMessages: true, | |
collapseActionsOnChange: true, | |
collapseActionsCurrentCount: 0, | |
collapseActionsMatchActions: /(ROC:Technician|Progress|Sched|Completed|Close)/, | |
ticketTitleTemplate: "HaloPSA #{ticket_id} {ticket_summary}", | |
ticketLinkTemplate: "https://{hostname}/ticket?id={ticket_id}&showmenu=false", | |
setup: function() { | |
this.log("Awox's HaloPSA tweaks engaged!") | |
this.run_repeat(this.annoying_scheduling_pops, 500) | |
this.run_repeat(this.collapse_ticket_actions, 500) | |
this.run_repeat(this.give_ticket_tabs_titles, 500) | |
}, | |
run_repeat: function(method_ref, timeout) { | |
method_ref.apply(this, Array()) | |
setTimeout(function() { window._awoxHaloTweaks.run_repeat(method_ref, timeout) }, timeout) | |
}, | |
log: function (message) { | |
if(this.debugMessages) console.log.apply(this, arguments) | |
}, | |
annoying_scheduling_pops: function () { | |
var modal = $('.ReactModal__Content--after-open'); | |
if(modal.length && modal.text().match(/(in the past|falls outside the Agents working hours)/)) { | |
modal.find('button').click() | |
} | |
}, | |
give_ticket_tabs_titles: function () { | |
if(String(document.location.pathname).startsWith("/ticket")) { | |
var ticket_summary = $('#ticketdetails-details div.summary-header .read-value').text() | |
var ticket_num = $('#ticketdetails-details .profile-full-name').text() | |
var ticket_id = ticket_num.replace(/^ID:0?/,"") | |
if(ticket_id && ticket_summary) { | |
document.title = this.ticketTitleTemplate.replace("{ticket_id}", ticket_id).replace("{ticket_summary}", ticket_summary) | |
var direct_link = this.ticketLinkTemplate.replace("{ticket_id}", ticket_id).replace("{hostname}", document.location.hostname) | |
// $('#ticketdetails-details .profile-full-name').html($('<a href="' + direct_link + '">' + ticket_num + '</a>')) | |
} else { | |
document.title = 'HaloPSA'; | |
} | |
} | |
}, | |
clear_sidebar_schedule_times: function () { | |
if(document.location.pathname.startsWith("/ticket")) { | |
$('.sidebar-tab #input-field-for-timetaken_\\!hrs').val(0).change().blur() | |
$('.sidebar-tab #input-field-for-timetaken_\\!mins').val(0).change().blur() | |
} | |
}, | |
collapse_ticket_actions: function () { | |
var tweaks = this; | |
var action_items = $('.action-history-item') | |
if(this.collapseActionsOnChange === false || action_items.length != this.collapseActionsCurrentCount) { | |
action_items.each(function(idx){ | |
var expanded = $(this).find('.note').length == 0 | |
var outcome = $(this).find('.outcome').text() | |
if(expanded) { | |
if(outcome.match(tweaks.collapseActionsMatchActions)) { | |
tweaks.log("collapse_actions", "Outcome matched, so collapsing: " + outcome) | |
$(this).find('.detailsholder').click(); | |
} else { | |
tweaks.log("collapse_actions", "Outcome unmatched, so not collapsing: " + outcome) | |
} | |
} | |
}); | |
this.collapseActionsCurrentCount = action_items.length; | |
} | |
}, | |
} | |
window._awoxHaloTweaks.setup() | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment