ShopVox URL Hash Trigger for Azure with Dynamic Response Display

Trigger script based on URL hash change, send GUID to Azure, and dynamically display response in ShopVox

目前為 2023-12-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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();
})();