编辑聊天机器人脚本:如何在消息中添加换行符?

问题描述 投票:0回答:0

提醒一下,我对 js 编码还很陌生。

我正在编辑我发现的 omegle 半机器人用户脚本,我想添加多行将被发送的文本。目前这个机器人会自动将“options.g1”粘贴为“deez”,就是这样。

有什么方法可以实现更好的功能,可以允许多个换行符而无需逐字打印命令?

代码:

// ==UserScript==
// @name         Omegle semi-bot
// @namespace    https://openuserjs.org/user/burn
// @version      0.2.2
// @description  Write first message and auto-reconnect when disconnected.
// @author       Burn
// @copyright   2019, burn (https://openuserjs.org//users/burn)
// @license     MIT
// @match        https://www.omegle.com/*
// @grant        none
// ==/UserScript==



(function() {
    'use strict';
    var options = {
            g1 : "deez",
            g2 : "Timesaved.reezone.",
            disconnectOnIdle : {
                enabled: true,
                timeout: 300000,
                timeoutId : null
            }
        },
        BreakException = {},
        targetNode = document.querySelector('body'),
        observerConfig = { attributes: false, childList: true, subtree: true },
        tId = null,
        previousListLength = 0,
        getRndIntBetween = function(min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        },
        callback = function(mutationsList, observer) {
        try {
            mutationsList.forEach(function (mutation) {
                var entry = {
                    mutation: mutation,
                    el: mutation.target,
                    value: mutation.target.textContent,
                    oldValue: mutation.oldValue
                };
                if (entry.el.classList.contains("statuslog")) {
                    if (targetNode.classList.contains("inconversation")) {
                        var btnSubmit = document.querySelector(".sendbtn");
                        var textarea = document.querySelector(".chatmsg");
                        textarea.innerText = options.g1;
                        tId === null && (tId = window.setTimeout(function() {
                            btnSubmit != null && btnSubmit.click();
                            textarea.innerText = options.g2;
                            tId == 100;
                            btnSubmit != null && btnSubmit.click();
                            }, getRndIntBetween(0.8*1000, 1.2*1000)) );
                    }
                }
                if (entry.el.firstChild && entry.el.firstChild.classList) {
                    tId = null;
                    if (entry.el.firstChild.classList.contains("logitem")) {
                        var logs = document.querySelectorAll('.logitem');
                        if (logs.length > previousListLength) {
                            console.log(logs[ logs.length - 1 ].innerText);
                            if (options.disconnectOnIdle.enabled) {
                                clearTimeout(options.disconnectOnIdle.timeoutId);
                                options.disconnectOnIdle.timeoutId = null;
                            }
                            if (options.disconnectOnIdle.enabled &&
                               options.disconnectOnIdle.timeoutId === null) {
                                   options.disconnectOnIdle.timeoutId = window.setTimeout(function() {
                                       console.log("*** ESCO ***");
                                       document.querySelector(".disconnectbtn").click();
                                       document.querySelector(".disconnectbtn").click();
                                   }, options.disconnectOnIdle.timeout);
                            }
                        }
                        if (document.querySelector(".newbtn .disconnectbtn")) {
                            previousListLength = 0;
                            window.setTimeout(function() {
                                document.querySelector(".newbtn .disconnectbtn")
                                && document.querySelector(".newbtn .disconnectbtn").click();
                            }, getRndIntBetween(1.2 * 1000, 1.8 * 1000));
                        }
                    }
                }
            });
        } catch(e) {
            if (e !== BreakException) throw e;
        }
    };

    var observer = new MutationObserver(callback);
    observer.observe(targetNode, observerConfig);
}
)();

我尝试添加“ ” 并且它实际上是粘贴“deez “在消息框中。我也尝试过 br 和 br/,但考虑到它不是 innerHtml,在这种情况下它似乎不起作用。

预期结果: 我想粘贴的示例文本 - “deez(换行符)nuts lmao” 应打印为 - Line1: deez Line2:坚果lmao

实际结果: Line1: deez 坚果 lmao

javascript html tampermonkey userscripts
© www.soinside.com 2019 - 2024. All rights reserved.