Trigger script based on URL hash change, send GUID to Azure, and dynamically display response in ShopVox
当前为
// ==UserScript==
// @name ShopVox URL Hash Trigger for Azure with Dynamic Response Display
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Trigger script based on URL hash change, send GUID to Azure, and dynamically display response in ShopVox
// @author YourName
// @match https://app.shopvox.com/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
function processUrlHash() {
var hash = window.location.hash;
var guidPattern = /pos\/work_orders\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i;
var match = guidPattern.exec(hash);
if (match) {
var guid = match[1];
console.log("GUID extracted: " + guid);
sendDataToAzure(guid);
}
}
function sendDataToAzure(guid) {
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";
GM_xmlhttpRequest({
method: "POST",
url: azureUrl,
data: JSON.stringify({ guid: guid }),
headers: {
"Content-Type": "application/json"
},
onload: function(response) {
console.log("Response from Azure: " + response.responseText);
displayAzureResponse(response.responseText);
},
onerror: function(error) {
console.error("Error sending data to Azure: ", error.responseText);
}
});
}
function displayAzureResponse(jsonData) {
try {
var data = JSON.parse(jsonData);
var customerData = data.customerData; // Extracting customerData from the response
var responseDiv = document.createElement('div');
responseDiv.className = 'row';
responseDiv.innerHTML = '<div class="col-sm-12 detail">' +
'<div class="title ng-binding">Customer Data' + data.test + '</div>' +
'<div class="ng-scope simple-format">' + customerData + '</div>' +
'</div>';
var insertLocation = document.querySelector('.details.ng-scope');
if (insertLocation) {
var wrapperDiv = document.createElement('div');
wrapperDiv.className = 'wrapper';
wrapperDiv.appendChild(responseDiv);
insertLocation.appendChild(wrapperDiv);
} else {
console.error('Could not find the insertion point for the customer data.');
}
} catch (e) {
console.error('Error parsing JSON response: ', e);
}
}
window.addEventListener('hashchange', processUrlHash, false);
processUrlHash();
})();