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 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();
})();