WorkOrder Info Change

Trigger script based on URL hash change

  1. // ==UserScript==
  2. // @name WorkOrder Info Change
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description Trigger script based on URL hash change
  6. // @author YourName3
  7. // @match https://app.shopvox.com/*
  8. // @grant GM_xmlhttpRequest
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function processUrlHash() {
  15. var hash = window.location.hash;
  16. var guidPattern = /pos\/(work_orders|quotes)\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i;
  17. var match = guidPattern.exec(hash);
  18.  
  19. if (match) {
  20. var type = match[1]; // "work_orders" or "quotes"
  21. var guid = match[2];
  22. console.log("Type: " + type + ", GUID: " + guid);
  23. sendDataToAzure(type, guid);
  24. }
  25. }
  26.  
  27. function sendDataToAzure(type, guid) {
  28. var azureUrl = "https://prod-25.australiasoutheast.logic.azure.com:443/workflows/272d34bf3ffa4e2a8dfb79c872771823/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=4XHesCUHZdmpOiXVb9Zcv16-8tdGqMSz3oBV8bzVHpc";
  29. GM_xmlhttpRequest({
  30. method: "POST",
  31. url: azureUrl,
  32. data: JSON.stringify({ type: type, guid: guid }),
  33. headers: {
  34. "Content-Type": "application/json"
  35. },
  36. onload: function(response) {
  37. console.log("Response from Azure: " + response.responseText);
  38. displayAzureResponse(response.responseText);
  39. },
  40. onerror: function(error) {
  41. console.error("Error sending data to Azure: ", error.responseText);
  42. }
  43. });
  44. }
  45. function displayAzureResponse(jsonData) {
  46. try {
  47. var data = JSON.parse(jsonData);
  48. var customerData = data.customerData; // Extracting customerData from the response
  49.  
  50. var responseDiv = document.createElement('div');
  51. responseDiv.className = 'row';
  52. responseDiv.innerHTML = '<div class="col-sm-12 detail">' +
  53. '<div class="title ng-binding">Additional Customer Data</div>' +
  54. '<div class="ng-scope simple-format">' + customerData + '</div>' +
  55. '</div>';
  56.  
  57. var insertLocation = document.querySelector('.details.ng-scope');
  58. if (insertLocation) {
  59. var wrapperDiv = document.createElement('div');
  60. wrapperDiv.className = 'wrapper';
  61. wrapperDiv.appendChild(responseDiv);
  62.  
  63. insertLocation.appendChild(wrapperDiv);
  64. } else {
  65. console.error('Could not find the insertion point for the customer data.');
  66. }
  67. } catch (e) {
  68. console.error('Error parsing JSON response: ', e);
  69. }
  70. }
  71.  
  72. window.addEventListener('hashchange', processUrlHash, false);
  73. processUrlHash();
  74. })();