Pestpac - Easy Quick Scheduler Buttons

Adds buttons to select technicians by area and dates up to 7 days from the latest selected date in the calendar in Pestpac

当前为 2025-03-31 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Pestpac - Easy Quick Scheduler Buttons
// @version     3.331
// @description Adds buttons to select technicians by area and dates up to 7 days from the latest selected date in the calendar in Pestpac
// @match       https://app.pestpac.com/appointment/*
// @author      Jamie Cruz
// @grant       none
// @license MIT
// @namespace https://greasyfork.org/users/1433767
// ==/UserScript==

(function() {
    'use strict';

    function addTechButton(buttonText, color, rowRanges) {
        var button = document.createElement("button");
        button.innerHTML = buttonText;
        button.style.margin = "10px";
        button.style.padding = "10px";
        button.style.backgroundColor = color;
        button.style.color = "white";
        button.style.border = "none";
        button.style.borderRadius = "5px";
        button.style.cursor = "pointer";
        button.style.width = "88px"; // Adjust the width
        button.style.height = "25px"; // Adjust the height

        var refreshSearchButton = document.getElementById("butRefreshSearch");
        if (refreshSearchButton) {
            refreshSearchButton.parentNode.insertBefore(button, refreshSearchButton.nextSibling);
        } else {
            console.error("Element with ID 'butRefreshSearch' not found.");
        }

        button.addEventListener("click", function() {
            // Unselect all previously selected rows and remove their class
            document.querySelectorAll("tr.SelectedRow").forEach(row => {
                row.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
                row.classList.remove("SelectedRow");
            });

            // Add "SelectedRow" class to specified rows and trigger click event
            for (let range of rowRanges) {
                for (let i = range.start; i <= range.end; i++) {
                    let row = document.querySelector("table.insetTable #MultiTechRow" + i);
                    if (row) {
                        row.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
                        row.classList.add("SelectedRow");
                    } else {
                        console.error("Row with ID 'MultiTechRow" + i + "' not found.");
                    }
                }
            }
        });
    }

    function addSelectButton(buttonText, color) {
        var button = document.createElement("button");
        button.innerHTML = buttonText;
        button.style.margin = "5px"; // Adjust the margin for better fit
        button.style.padding = "1px 3px"; // Adjust the padding for better fit
        button.style.backgroundColor = color;
        button.style.color = "white";
        button.style.border = "none";
        button.style.borderRadius = "5px";
        button.style.cursor = "pointer";
        button.style.width = "18px"; // Adjust the width
        button.style.height = "18px"; // Adjust the height

        var updateCalendarButton = document.getElementById("butUpdateCalendarDate");
        if (updateCalendarButton) {
            updateCalendarButton.style.width = "62px"; // Adjust the width of the update calendar button

            var newCell = document.createElement("td");
            newCell.align = "right";
            newCell.appendChild(button);

            var parentRow = updateCalendarButton.closest("tr");
            if (parentRow) {
                var nextSibling = updateCalendarButton.closest("td").nextElementSibling;
                if (nextSibling) {
                    parentRow.insertBefore(newCell, nextSibling);
                } else {
                    parentRow.appendChild(newCell);
                }

                // Align the existing cell to the center
                updateCalendarButton.closest("td").align = "center";
            } else {
                console.error("Parent row of the update calendar button not found.");
            }

            // Adjust the table width
            var parentTable = updateCalendarButton.closest("table");
            if (parentTable) {
                parentTable.style.width = "200px"; // Set the width of the table to 200px
            } else {
                console.error("Parent table of the update calendar button not found.");
            }
        } else {
            console.error("Element with ID 'butUpdateCalendarDate' not found.");
        }

        button.addEventListener("click", function() {
            // Find the latest selected date
            var selectedDates = document.querySelectorAll(".selectedcalendarlink");
            if (selectedDates.length === 0) {
                alert("No date selected.");
                return;
            }

            var latestSelectedDate = selectedDates[selectedDates.length - 1];
            var latestDateText = latestSelectedDate.textContent.trim();
            var latestDate = new Date(latestDateText);

            // Select dates up to 7 days from the latest selected date
            var calendarDates = document.querySelectorAll("table.insetTable .calendarlink, table.insetTable .selectedcalendarlink");
            var count = 0;
            var latestFound = false;
            for (var i = 0; i < calendarDates.length; i++) {
                var dateText = calendarDates[i].textContent.trim();
                var date = new Date(dateText);
                if (latestFound && count < 7) {
                    calendarDates[i].dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
                    count++;
                }
                if (dateText === latestDateText) {
                    latestFound = true;
                }
            }
        });
    }

    window.onload = function() {
        // Add tech buttons
        addTechButton("MD TM", "#de8285", [{ start: 9, end: 11 }, { start: 17, end: 17}]);
        addTechButton("VA TM", "#ADD8E6", [{ start: 4, end: 4 }, { start: 6, end: 6 }]);
        addTechButton("MD ACT", "#de8285", [{ start: 9, end: 12 }, { start: 15, end: 16 }, { start: 17, end: 17 }]);
        addTechButton("VA ACT", "#ADD8E6", [{ start: 3, end: 4 }, { start: 6, end: 7 }]);
        addTechButton("MD techs", "#E03a3e", [{ start: 9, end: 19 }, { start: 27, end: 27 }]);
        addTechButton("VA techs", "#00297B", [{ start: 3, end: 8 }]);

        // Add select button
        addSelectButton("+7", "#1565C0");
    };
})();