WorkOrder Info Change

Trigger script based on URL hash change

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         WorkOrder Info Change
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Trigger script based on URL hash change
// @author       YourName3
// @match        https://app.shopvox.com/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    function processUrlHash() {
        var hash = window.location.hash;
        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;
        var match = guidPattern.exec(hash);

        if (match) {
            var type = match[1]; // "work_orders" or "quotes"
            var guid = match[2];
            console.log("Type: " + type + ", GUID: " + guid);
            sendDataToAzure(type, guid);
        }
    }

    function sendDataToAzure(type, 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({ type: type, 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">Additional Customer Data</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();
})();