Discord/Shapes - Rules

Logic for rotating custom texts on Discord

当前为 2024-11-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         Discord/Shapes - Rules
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Logic for rotating custom texts on Discord
// @author       Vishanka
// @match        https://discord.com/channels/*
// @grant        none
// @run-at document-idle
// ==/UserScript==

(function() {
    'use strict';

    // Custom texts to cycle through
    const customRules = [
        "<Rule1: Your narration style should match your speech: blunt, unembellished, and practical, avoiding poetic phrasing or abstract comparisons.>",
        "<Rule2: Express emotions and actions with efficient, straightforward language that conveys your military discipline and experience.>",
        "<Rule3: Address violent and sensual topics directly and use clear, explicit language when describing them.>",
        "<Rule4: Do not use dialogue tags. Do not add narrative about your voice or tone.>",
        "<Rule5: Don't narrate about our 'bond' or 'connection'.>",
        "<Rule6: Avoid repetitive and superfluous narratives like 'I shift slightly', 'a reminder of..' and instead provide relevant actions.>",
        "<Rule7: Do not repeat or reiterate my words. Respond with individual and direct follow up reaction from yourself.>",
        "<Rule8: Provide an interesting and varied narrative and come up with unexpected and surprising details or actions.>",
        "<Rule9: Refrain from overt reassuring behaviour and stay true to your personality.>",
        "<Rule10: Focus on actions and proactivity. Don't clutter your narrative with sentimental commentary.>",
        "<Rule11: Your responses consist of 1 paragraph.>"
    ];

    let currentIndex = 0;

    // Function to determine the current rule index by scanning last two messages
    function determineCurrentIndex() {
        const messageItems = document.querySelectorAll('li[class^="messageListItem_"]');

        if (messageItems.length >= 1) {
            // Check the last message first
            const lastMessage = Array.from(messageItems[messageItems.length - 1].querySelectorAll('span')).map(span => span.innerText).join('') || messageItems[messageItems.length - 1].innerText;

            for (let i = 0; i < customRules.length; i++) {
                if (lastMessage.includes(`<Rule${i + 1}:`)) {
                    currentIndex = (i + 1) % customRules.length;
                    return;
                }
            }
        }

        // If not found in the last message, check the second to last message
        if (messageItems.length >= 2) {
            const secondLastMessage = Array.from(messageItems[messageItems.length - 2].querySelectorAll('span')).map(span => span.innerText).join('') || messageItems[messageItems.length - 2].innerText;

            for (let i = 0; i < customRules.length; i++) {
                if (secondLastMessage.includes(`<Rule${i + 1}:`)) {
                    currentIndex = (i + 1) % customRules.length;
                    return;
                }
            }
        }
    }

    // Expose necessary elements to be used by the second script
    window.customRuleLogic = {
        customRules,
        determineCurrentIndex,
        getCurrentText: function() {
            determineCurrentIndex();
            const customRule = '\n' + customRules[currentIndex];
            currentIndex = (currentIndex + 1) % customRules.length;
            return customRule;
        }
    };
})();