Assign Interaction: warn for calls/texts if number not present

Warn if you try to assign certain interactions on a profile that doesn't have a phone number.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Assign Interaction: warn for calls/texts if number not present
// @namespace    https://github.com/nate-kean/
// @version      20251117
// @description  Warn if you try to assign certain interactions on a profile that doesn't have a phone number.
// @author       Nate Kean
// @match        https://jamesriver.fellowshiponego.com/*/view/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fellowshiponego.com
// @grant        none
// @license      MIT
// @run-at       document-end
// ==/UserScript==

(async function() {
    const phoneCallAIDs = [
        "253", // New Visitor Connections Follow-up
        "257", // New Visitor Communication: Phone Call
        "247", // Praise Report - ALL ACCESS
        "234", // Prayer Request - CONFIDENTIAL
    ];

    function delay(ms) {
        return new Promise((resolve) => setTimeout(resolve, ms));
    }

    async function waitForElement(selector, pollingRateMs=100, parent=document) {
        let el;
        while (true) {
            el = parent.querySelector(selector);
            if (el) return el;
            await delay(pollingRateMs);
        }
    }

    async function elementGone(selector, pollingRateMs=100, parent=document) {
        let el;
        while (true) {
            el = parent.querySelector(selector);
            if (!el) return;
            await delay(pollingRateMs);
        }
    }

    function checkForPhoneNumber() {
        const addDetailsKeys = document.querySelectorAll(".contact-panel > .panel-body > .info-left-column > .contact-lbl");
        for (const key of addDetailsKeys) {
            if (key.textContent.trim().startsWith("Phone")) {
                return true;
            }
        }
        return false;
    }

    const modal = document.querySelector("#assignInteractionForm");

    while (true) {
        const select = modal.querySelector("#aid");
        while (!phoneCallAIDs.includes(select.value)) {
            await delay(100);
        }

        const hasPhoneNumber = checkForPhoneNumber();
        if (hasPhoneNumber) {
            await delay(100);
            continue;
        }

        const submitBtn = modal.querySelector('input[type="submit"]');
        submitBtn.classList.remove("btn-success");
        submitBtn.classList.add("btn-warning");
        const em = document.createElement("em");
        em.setAttribute("style", "margin-right: 10px; color: #110f24; opacity: .7;");
        const span = document.createElement("span");
        span.textContent = "No phone number on profile";
        em.appendChild(span);
        submitBtn.parentNode.prepend(em);

        while (phoneCallAIDs.includes(select.value)) {
            await delay(100);
        }

        submitBtn.classList.remove("btn-warning");
        submitBtn.classList.add("btn-success");
        em.remove();
    }
})();