Greasy Fork is available in English.

Assign Interaction: autofill due date

Infer the due date of the interaction you're assigning.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Assign Interaction: autofill due date
// @namespace    http://tampermonkey.net/
// @version      2025.12.21
// @description  Infer the due date of the interaction you're assigning.
// @author       Nate Kean
// @match        https://jamesriver.fellowshiponego.com/members/view/*
// @match        https://jamesriver.fellowshiponego.com/members/family/*
// @match        https://jamesriver.fellowshiponego.com/members/timeline/*
// @match        https://jamesriver.fellowshiponego.com/members/giving/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fellowshiponego.com
// @require      https://update.greasyfork.org/scripts/559387/1716607/getRelativeWeekday.js
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    const actionSpan = document.querySelector("#aid").parentElement.querySelector(".chosen-container > a > span");
    const completeByDateInput = document.querySelector("#completeByDate");
    const today = new Date();


    function decideDate(actionName) {
        switch (actionName) {
            case "New Visitor Connections Follow-Up":
            case "New Visitor Follow-Up: Cookie Visit":
                return today;
            case "New Visitor Follow- Up: Phone Call":
            case "Altar Follow-up": {
                // This Friday on Sun, Mon, Tue, Wed, Sat; next Friday on Thu, Fri
                const friday = getRelativeWeekday(today, DateDir.THIS, Day.FRIDAY, false);
                if ([Day.THURSDAY, Day.FRIDAY].includes(today.getDay())) {
                    // If it's already Thursday or Friday, make it next Friday
                    friday.setDate(friday.getDate() + 7);
                }
                return friday;
            }
            case "Discipleship":
                return getRelativeWeekday(today, DateDir.THIS, Day.TUESDAY, false);
        }
        return null;
    }


    function formatDate(date) {
        const month = String(date.getMonth() + 1).padStart(2, "0");
        const day = String(date.getDate()).padStart(2, "0");
        const year = date.getFullYear();
        return `${month}/${day}/${year}`;
    }


    function onMutation(records) {
        const date = decideDate(actionSpan.textContent);
        if (date === null) return;
        completeByDateInput.value = formatDate(date);
    }


    const observer = new MutationObserver(onMutation);
    const options = {
        subtree: false,
        childList: true,
        attributes: false,
        characterData: true,
        characterDataOldValue: false,
    };
    observer.observe(actionSpan, options);
})();