This wiki has been permanently archived. As such, editing and registration have been closed.

User:Lumpy HTF/AutoTurn.js

From CollabVM Wiki, the horrible, autism-inducing, trash filled wiki, featuring people who can't speak English
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// ==UserScript==
// @name         Auto-Turn
// @namespace    http://computernewb.com/
// @version      1.2.0
// @description  A turn spam script with a efficent auto turn method, graphical dropdown, easy-to-use interface, GUI with metro theme support, auto start options, you name it. While your typical turn spam script would just be a plain dev console script or a single button, this userscript version is loaded with features, and the ones I mentioned aren't the only ones. See for yourself by checking the about page in the script today.
// @author       swordlink1/Lumpy HTF
// @match        https://computernewb.com/collab-vm/*
// @match        http://computernewb.com/collab-vm/*
// @match        localhost
// @icon         https://www.google.com/s2/favicons?sz=64&domain=computernewb.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict'; // WELCOME TO THE (long ago) RTM RELEASE! This userscript will be receiving more features in future updates. Stay tuned! The updates are in this script's changelog.
    // This userscript was designed for Chromium-based browsers, at least when swordlink1 is developing it. This userscript, when developed by swordlink1, is developed on Edge.
    // defining some variables
    const bgcolor = $(".navbar").css("background-color"); // detect cvm red and black theme
    var crab = false; // variable for cvm red and black theme detection (crab is cvm red and black theme)
    var bt4 = false; // variable for cvm bootstrap 4 theme detection
    var bt5 = false; // variable for cvm bootstrap 5 theme detection
    var betatheme = false; // variable for cvm beta theme detection
    const devrelease = true; // tells if its a dev release
    const btns = document.getElementById("btns") || document.getElementById("vote-stats").nextSibling;
    const adminbtns = document.getElementById("admin-btns");
    const turnbtn = document.getElementById("turn-btn"); // the setinterval continously defined this variable and i didnt like that so i moved this up here
    const endturnbtn = document.getElementById("end-turn-btn");
    const scriptver = "1.2.0"; // look at the top of the window variables
    const scriptname = "Auto-Turn v" + scriptver; // for the random messages
    var newlabel = "<span class='label label-success'>New!</span>"; // the "New!" label you see on a new option, needed because of bootstrap 4/5 theme compatibility
    var previewheight = "40"; // the height for "chat message previews" in the settings
    var darkbtnclass = "btn-inverse"; // one word: simplicity (you don't get what i mean lol)
    const allowednamechars = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", " ", "-", "_", "."]; // for custom auto-turn chat messages name
    const familyfriendlymessages = {
        "mv_": "Jesus christ, you forkies never stop.",
        "TightVNC Desktop": "HIASM IS THE BEST THING IN THE WORLD!!!11 IEUNFVUIPERHBREIUV",
        "jjjj": "I MADE U!",
        "hna": "forkies will go as FAR AS THAT just to fork the vm",
        "user1272738242": "1. probably violated ToS - assuming the owner had 2 free accounts - H****************r and libreidp-",
        "Bastian": "AA 009 NO FONT IS ILLEGAL!",
        "Samira.exe": "OH YES! GOODLINK1 IS HERE!",
        "Lumpy HTF": "BFDI goodness level went crashing down the hill.",
        "guest82357": "what's the point of this !destroyuservm command if only mods and admins can run it?",
        "guest1352": "stupido..",
        "Hildaboo": "regular tech pro moment"
    };
    const maturemessages = { // read at your own risk if you don't like collabvm/mature language (also i probably should change the name of this variable to prevent confusion because i wouldn't exactly saying either of these is a mature thing to do)
        "guest1337": "MORE PORN",
        "CHOCOLATEMAN": "THIS GAME IS LITERALLY FUCKING PROGRAMMED TO FUCK YOU",
        "MediaArgentinan": "KLASKY CSUPO ROBOT LOGO IN CUM EFFECT YAY!!!11!!",
        "General Darian": "wow! I can't believe \"guest90723\" (user) is THAT retarded! can you?",
        "Technoturnovers": "you know, i think sonic is fine but the community is straight up autistic",
        "jjjj": "jjjj is not a faggot!",
        "Hendicted": "i would rather fuck your mother off",
        "LoveEevee": "I DONT ACTUALLY PLAY POKEMON, I JUST GET HORNY AT THE CHARACTERS",
        "Shitface titty fart": "FUCKING X PROGTAMS",
        "Wulf715": "we didnt do shit",
        "Ctrl": "Techno do you fuck goats?"
    };
    var afkstopwatch = 0; // a stopwatch that goes until the afk time
    var disablewhenafk = true; // options that says if you should disable auto-turn if afk
    var vmscreen = document.getElementById("display"); // for afk countdown
    var afkmsgtype = localStorage.getItem('autoturn-afkmsgtype'); // for afk message
    var afkmsg = localStorage.getItem('autoturn-afkmsg') || ""; // for afk message
    var showmaturelang = (localStorage.getItem('autoturn-maturelang') === 'true'); // says if you should show mature language in the random chat messages
    // pre-dropdown theme support helper (needed for theme detection variables and certain themes)
    try { // using ifs instead of else ifs just in case both crab and some other thing is applied
        if (localStorage.getItem('autoturn-forcetheme') == 'crab' || bgcolor == "rgb(106, 16, 16)") { // cvm red and black theme detection
            crab = true;
            previewheight = "34";
        }
        if (localStorage.getItem('autoturn-forcetheme') == 'bt4' || $.fn.tooltip.Constructor.VERSION == '4.1.3') {
            bt4 = true;
            newlabel = "<span class='badge badge-success'>New!</span>";
            darkbtnclass = "btn-dark"
        }
        if (localStorage.getItem('autoturn-forcetheme') == 'bt5' || $.fn.tooltip.Constructor.VERSION == "5.0.2") {
            bt5 = true;
            newlabel = "<span class='badge bg-success'>New!</span>";
            darkbtnclass = "btn-dark"
        }
    } catch (e) {
        if (localStorage.getItem('autoturn-forcetheme') == 'beta' || turnbtn.classList.contains("ui")) { // detection for future update
            betatheme = true;
        }
    }
    // start of dropdown preparers (DO NOT REMOVE THIS CODE. This is essential for proper theme compatibility.)
    if (bt4) { // bootstrap 4 theme dropdown preparing code
        var autoturnoptions = document.createElement("div"); // the base of the dropdown
        autoturnoptions.id = "auto-turn-options";
        autoturnoptions.classList.add("dropdown");
        autoturnoptions.style.display = "inline-block";
        btns.insertBefore(autoturnoptions, adminbtns);
        var dropdownhelper = document.createElement("button"); // the button that makes the dropdown toggable
        dropdownhelper.classList.add("btn", "btn-default", "dropdown-toggle");
        dropdownhelper.type = "button";
        dropdownhelper.id = "autoturn-dropdownbtn";
        dropdownhelper.setAttribute("data-toggle", "dropdown");
        dropdownhelper.setAttribute("aria-haspopup", "true");
        dropdownhelper.setAttribute("aria-expanded", "false");
        dropdownhelper.innerHTML = "Auto-Turn";
        autoturnoptions.appendChild(dropdownhelper);
        var dropdownlist = document.createElement("div"); // the actual dropdown itself with all the options
        dropdownlist.id = "autoturn-dropdown-list"; // user123 removed the ids, damn, anyways if some mod wants to add stuff into this dropdown then there you go (although i might as well just add the addoption function into "window" which i have done)
        dropdownlist.classList.add("dropdown-menu");
        dropdownlist.setAttribute("aria-labelledby", "autoturn-dropdownbtn");
        autoturnoptions.appendChild(dropdownlist);
    } else if (bt5) {
        autoturnoptions = document.createElement("div"); // the base of the dropdown
        autoturnoptions.id = "auto-turn-options";
        autoturnoptions.classList.add("dropdown");
        autoturnoptions.style.display = "inline-block";
        btns.insertBefore(autoturnoptions, adminbtns);
        dropdownhelper = document.createElement("button"); // the button that makes the dropdown toggable
        dropdownhelper.classList.add("btn", "btn-light", "dropdown-toggle");
        dropdownhelper.type = "button";
        dropdownhelper.id = "autoturn-dropdownbtn";
        dropdownhelper.setAttribute("data-bs-toggle", "dropdown");
        dropdownhelper.setAttribute("aria-expanded", "false");
        dropdownhelper.innerHTML = "Auto-Turn";
        autoturnoptions.appendChild(dropdownhelper);
        dropdownlist = document.createElement("div"); // the actual dropdown itself with all the options
        dropdownlist.id = "autoturn-dropdown-list"; // user123 removed the ids, damn, anyways if some mod wants to add stuff into this dropdown then there you go (although i might as well just add the addoption function into "window" which i have done)
        dropdownlist.classList.add("dropdown-menu");
        dropdownlist.setAttribute("aria-labelledby", "autoturn-dropdownbtn");
        autoturnoptions.appendChild(dropdownlist);
    } else { // original bootstrap 3
        autoturnoptions = document.createElement("div"); // the base of the dropdown
        autoturnoptions.id = "auto-turn-options";
        autoturnoptions.classList.add("btn-group");
        btns.insertBefore(autoturnoptions, adminbtns);
        dropdownhelper = document.createElement("button"); // the button that makes the dropdown toggable
        dropdownhelper.classList.add("btn", "btn-default", "dropdown-toggle");
        dropdownhelper.type = "button";
        dropdownhelper.setAttribute("data-toggle", "dropdown");
        dropdownhelper.setAttribute("aria-haspopup", "true");
        dropdownhelper.setAttribute("aria-expanded", "false");
        dropdownhelper.innerHTML = "Auto-Turn <span class='caret'></span>";
        autoturnoptions.appendChild(dropdownhelper);
        dropdownlist = document.createElement("ul"); // the actual dropdown itself with all the options
        dropdownlist.id = "autoturn-dropdown-list"; // user123 removed the ids, damn, anyways if some mod wants to add stuff into this dropdown then there you go (although i might as well just add the addoption function into "window" which i have done)
        dropdownlist.classList.add("dropdown-menu");
        dropdownlist.style.position = "absolute"; // the only thing thats affected in dark mode is the position of the dropdown so there's not need to make a detection variable and all of that
        autoturnoptions.appendChild(dropdownlist);
    }
    // end of dropdown prepapers (now for some post-dropdown startup code + post-dropdown theme support)
    console.log(`Welcome to ${scriptname}!`);
    $("head").append(`
    <style id="autoturn-cssrules" type="text/css">
    .btn-inverse { /* bootstrap 2 class */
       color: #ffffff!important;
       text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
       background-color: #363636;
       *background-color: #222222;
       background-image: -moz-linear-gradient(top, #444444, #222222);
       background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#444444), to(#222222));
       background-image: -webkit-linear-gradient(top, #444444, #222222);
       background-image: -o-linear-gradient(top, #444444, #222222);
       background-image: linear-gradient(to bottom, #444444, #222222);
       background-repeat: repeat-x;
       border-color: #222222 #222222 #000000;
       border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
       filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff444444', endColorstr='#ff222222', GradientType=0);
       filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
    }
    .crab-dark-input-panel { /* unused */
       background-color: #2a2a2a!important;
       border: none;
    }
    </style>
    `);
    if (localStorage.getItem('autoturn-autostart') == "true") { // for autostart options
        window.autoturnenabled = true; // the reason why this uses window variable is because in the first version, you had to start auto-turn in the dev console and the only way to change the variable was to make it globally accessible using window variables. it is still kept today because why not? ;)
        turnbtn.click();
    } else {
        window.autoturnenabled = false; // same comment as the insanely long comment 2 lines above
    }
    if (crab) { // for cvm red and black theme graphical dropdown compatibility
        dropdownlist.style.backgroundColor = "#111";
    }
    if (localStorage.getItem('autoturn-msgname') != null) {
        var msgname = localStorage.getItem('autoturn-msgname');
    }
    // adding and preparing modals (modals are like that change username popup)
    var helpmodalbody =
        `
        <div style="text-align: center;">
            <h2>Options Help</h2>
            <hr>
            <h3>Auto-Turn Options</h3>
            <h4>Enable Auto-Turn</h4>
            <p>Automatically starts taking turns everytime your turn ends.</p>
            <h4>Disable Auto-Turn</h3>
            <p>Stops the function described above.</p>
            <h3>Auto-Start Options</h3>
            <h4>Start on page load</h4>
            <p>Automatically enable Auto-Turn each time you start/restart a new session on CollabVM.</p>
            <h4>Start on user input only</h3>
            <p>Does not automatically enable Auto-Turn on every new CollabVM session.</p>
            <h3>Misc. Options</h3>
            <h4>About Script and FAQ</h4>
            <p>Shows a about page and a FAQ at the bottom of it.</p>
            <h4>Changelog</h4>
            <p>Shows a changelog of all the versions since 0.1.</p>
            <h4>Options Help</h4>
            <p>Shows this help page.</p>
        </div>
        `;
    var aboutscriptbody = // more info here
        `
        <div style="text-align: center;">
            <h2>${scriptname} by swordlink1/Lumpy HTF and User123</h2>
            <hr>
            <h3>Script Info</h3>
            <p>Did you only use Fylrobot for !turnspam, just to see that all of Fylrobot (including !turnspam) doesn't work for some reason now? Do you want a turn spam script that you can actually manage well? Do you want a turn spam script that isn't hard to use? Do you want a turn spam script that has a lot of features?</p>
            <p>Well, you're at the right place then! This turn spam script (named Auto-Turn) is actively maintained, guaranteeing new features and bug fixes often, comes with a graphical dropdown without-a-hassle, is very easy to use, and is getting new features almost everyday!</p>
            <p>Are you a experienced JS developer that wants to mod this script? No problem! This code has a lot of comments, making sure you know exactly where each function is! It's also easy to manage the graphical dropdown and modals (modals are like the options help and about script page!).</p>
            <s>
                <p>Sadly, time has gone by and over time, I lost interest in this script. Updates used to take less than a day, and later in this script's lifespan, they took days. However, as of May 22th, 2022, I can confirm this script has officially been discontinued and no more feature updates will be given, unless I regain interest.</p>
                <p>However, this isn't to say that if I find a bug in this script, I won't fix it. I only won't be giving this script new features, and bug-fixes and security updates will still continue. While I might not be updating my script with new features, I'm still using it myself. So please continue to report any bugs you find to me.</p>
            </s>
            <p>Yeah... I changed my mind. But I probably won't make up my mind.</p>
            <h3>Script Features</h3>
            <p>Here are all the features of the script! :D</p>
            <ul style="text-align: left;">
                <li>Efficently takes turn when your turn has ended, unlike other turn spam scripts that wait 18 seconds to take a turn again instead, which could be interefered with by cooldowns.</li>
                <li>Provides a graphical controls designed to be very easy-to-use and understandable.</li>
                <li>Uses Bootstrap modals (like the page you're seeing right now!) instead of plain JS alert boxes.</li>
                <li>Provides a about page with all the scripts info, plus a help page for understanding each option's function.</li>
                <li>Provides auto-start options so you don't have to enable auto-turn manually each time if you want it on all the time.</li>
                <li>Code is commented so you can understand the code.</li>
                <li>The graphical dropdown supports the CVM Red and Black theme userstyle.</li>
                <li>Supports all metro themes + the Bootstrap 4 theme.</li>
                <li>Comes with a changelog to know the new features and bug fixes of each update.</li>
                <li>Comes with a FAQ to answer all your questions.</li>
                <li>And there's more to come...</li>
            </ul>
            <h3>Use Cases</h3>
            <ol style="text-align: left;">
                <li>Let's say you're alone on a VM. Since you're alone, why keep clicking the take turn button or the screen everytime? It's not like people are going to come anytime soon, judging by the looks of it. This is one of the situations that this script is useful for.</li>
                <li>Let's say that a forkie is well, forking the VM. You can stop him faster, but how? Since this script automatically takes a turn for you, this will definitely help.</li>
                <li>Or let's just say you're tired of manually clicking take turn or the screen everytime. This script would obviously be the best script for that situation.</li>
                <li>And there's more use cases that will be added here in the future.</li>
            </ol>
            <h3>F.A.Q</h3>
            <p>Okay, these questions were probably never asked, so this is more of a Q&A. You might have some of these questions though, so if you do, then search in this Q&A.</p>
            <h4><b>Q:</b> Where can I meet you on CollabVM?</h4>
            <p><b>A:</b> I'm guest59511. You'll see me most of the on the Install Any OS VMs, whether it be the new OSes or old OSes one (VM7 and VM8).</p>
            <h4><b>Q:</b> Where can I contact you on the Computernewb Wiki?</h4>
            <p><b>A:</b> I'm Swordlink1. Just make a new topic on my talk page and I'll likely notice it the next day.</p>
            <h4><b>Q:</b> Can I contact you to suggest new features or to send bug reports?</h4>
            <p><b>A:</b> Yes! You indeed can. In fact, please do!</p>
            <h4><b>Q:</b> What if I want this userscript to be compatible with a custom userstyle I made?</h4>
            <p><b>A:</b> Contact me on either platform, give me the userstyle, and I'll make it compatible.</p>
            <h4><b>Q:</b> What will happen when CollabVM 3.0 is released?</h4>
            <p><b>A:</b> If 3.0's website classes stays the same, then there will be no problem. Otherwise depending on the changes, the 3.0 website compatibility could take from just half a hour to days.</p>
            <h4><b>Q:</b> Are you going to make any other CVM userscripts soon?</h4>
            <p><b>A:</b> Yes! I'm planning to make a bot creator script, a mute script, and a script that notifies you when somebody pings/mentions you in the chat!</p>
            <p>Enjoy!</p>
        </div>
        `;
    var changelogbody = // can somebody finish this changelog for me please
    /*
    when doing minor version updates, be like:
    v0.6.0
    * adds something
    * adds something else
    * adds another thing (v0.6.9)
    */
        `
        <div style="text-align: center;">
            <h2>Auto-Turn Versions Changelog</h2>
            <hr>
            <h3>Changelog</h3>
            <p>Here is the changelog for all public releases.</p>
            <h4>v1.2.0</h4>
            <ul style="text-align: left;">
                <li><s>Uses JS alerts instead of modals when in Bootstrap 5, due to the Bootstrap 5 theme not working well with modals. (modals are the thing that power the "pages" (like the one you're seeing rn) you see in this script).</s> (browsers are bad and limited how big the text of a alert could get)</li>
                <li>Adds more versions to the changelog all the way down to <s>v0.7</s> v0.9. I don't have the revision history of AutoTurn.js on the wiki due to the wiki explosion.</li>
                <li>Adds a feature to automatically disable Auto-Turn when AFK for 1 minute or the user-specified time.</li>
                <li>Fixes a bug that doesn't enable Auto-Turn until you manually take a turn.</li>
                <li>Adds a settings page.</li>
            </ul>
            <h4>v1.1.0</h4>
            <ul style="text-align: left;">
                <li>Adds Bootstrap 5 theme support.</li>
                <li>Fixes a bug with Bootstrap 4 Theme support.</li>
                <li>Fix a bug with the options help page not showing. (v1.1.1)</li>
                <li>Update the changelog. (v1.1.2)</li>
            </ul>
            <h4>v1.0.0 RTM!</h4>
            <ul style="text-align: left">
                <li>Adds Bootstrap 4 theme support. (and some bootstrap 5 and beta theme variables (that have working detection) for v1.1.0 (BT5 that has been added) and v1.3.0 (Beta))</li>
                <li>Add back removed theme compatibility. I didn't remove it, User123 did. (v1.0.1)</li>
                <li>Adds a global window variable to detect if Auto-Turn is installed.</li>
                <li>Adds a changelog page.</li>
            </ul>
            <h4>v0.9.0</h4>
            <ul style="text-align: left;">
                <li>Adds about menu.</li>
                <li>Adds CVM Red and Black Theme support.</li>
                <li>Adds support for UserVM.</li>
                <li>Improves the code. (v0.9.1)</li>
                <li>Adds Darkest Metro Theme support. (v0.9.3)</li>
                <li>Adds metro theme support. (v0.9.4)</li>
                <li>Adds a modern method to center the text in modals, and moves list in modals to the left. (v0.9.5)</li>
                <li>Adds mutant observers as a more efficent way to check for turn end. If your browser doesn't support mutant observers, it will automatically fall back to the old method. (v0.9.6)</li>
                <li>Adds a global window variable to detect if Auto-Turn is installed.</li>
                <li>Adds a changelog page.</li>
            </ul>
        </div>
        `;
    /*
    speaking of updates, v̶1̶.̶1̶.̶0̶  v1.2.0 will introduce a feature that automatically disables auto-turn when afk (although you can enable/disable it) and bootstrap 5 theme support (v1.1.0).
    */
    var settingsbody = // this page has interactive elements within it's body (like buttons)
        `
        <div style="text-align: center;">
            <h2>Auto-Turn Options</h2>
            <p>Here, you can adjust the settings for this script. The close button will still apply your settings.</p>
            <hr>
            <h3>General Options</h3>
            <h4>Automatically disable Auto-Turn when AFK</h4>
            <p>Leaving Auto-Turn running while AFK could annoy other users, and could lead up to a mod/admin kicking you from the VM, or even toxicly banning you as a whole if they're confused about what's going on <!-- knowing cvm mods/admins, this is a very likely scenario -->. This allows you to automatically disable Auto-Turn when no mouse movement is happening in the screen area of the VM screen for a long time, which is considered being "AFK" here.</p>
            <h5>Do you want to automatically disable Auto-Turn when you're AFK?</h5>
            <div class="btn-group" role="group" aria-label="autoturn-autodisable">
                <button type="button" class="btn btn-success" type="button" id="autoturn-disablewhenafk-btn" onclick="window.autoturnchangesetting(1, 1);">Yes</button>
                <button type="button" class="btn btn-default" type="button" id="autoturn-runwhenafk-btn" onclick="window.autoturnchangesetting(1, 2);">No</button>
            </div>
            <h4>Disable Auto-Turn after...</h4>
            <p>If you choose to automatically disable Auto-Turn when you're AFK, then here is where you can specify how much time AFK is needed to disable Auto-Turn. Default is 1 minute.</p>
            <h5>How much minutes do you need to be AFK for to disable Auto-Turn automatically?</h5>
            <div class="input-group">
                <input type="text" class="form-control" id="autoturn-afklength-input" placeholder="1">
                <span class="input-group-btn input-group-append">
                    <button id="autoturn-applytime-btn" class="btn btn-primary" type="button" onclick="window.autoturnchangesetting(7, 1);">Apply</button>
                </span>
            </div>
            <h4>Mature Language in the Random Chat Message below</h4>
            <p>A random chat message in the <i>Auto-Turn's Name in Chat Messages</i> section is generated from a list of family-friendly strings by default. Here you can change that.</p>
            <h5>Do you want to show more mature languages in these random chat messsages?</h5>
            <div class="btn-group" role="group" aria-label="autoturn-maturelang">
                <button type="button" class="btn btn-default" type="button" id="autoturn-maturelang-btn" onclick="window.autoturnchangesetting(6, 1);">Yes</button>
                <button type="button" class="btn btn-danger" type="button" id="autoturn-familyfriendlylang-btn" onclick="window.autoturnchangesetting(6, 2);">No</button>
            </div>
            <h3>Chat Messages</h3>
            <h4>Auto-Turn's Name in Chat Messages</h4>
            <p>Everytime Auto-Turn sends a chat message in chat, it usually has the name of ${scriptname}. Here you can change that.</p>
            <h5>What username do you want Auto-Turn chat messages to have?</h5>
            <div class="input-group" id="name-input-group">
                <input type="text" class="form-control" id="autoturn-name-input" placeholder="${scriptname}" maxlength="20">
                <span class="input-group-btn input-group-append">
                    <button id="autoturn-applyname-btn" class="btn btn-primary" type="button" onclick="window.autoturnchangesetting(4, 1);">Apply</button>
                    <button id="autoturn-defaultname-btn" class="btn btn-info" type="button" onclick="window.autoturnchangesetting(4, 2);">Restore Default</button>
                </span>
            </div>
            <span style="color: #a94442; display: none;" id="wrongusername">Usernames can contain only numbers, letters, spaces, dashes, underscores, and dots, and it must be between 3 and 20 characters.</span>
            <br>
            <div style="position:relative;min-height:${previewheight * 2.4}px;margin-bottom:10px;text-align:left;">
                <ul id="chat-panel" class="list-group-item message-pane-wrapper" style="overflow:hidden;">
                    <div id="chat-box" class="message-pane">
                        <li><div id="random-message"><span class="username moderator">mv_</span><span class="spacer">▸</span>Jesus christ, you forkies never stop.</div></li>
                        <li><div><span class="username" id="username">${scriptname}</span><span class="spacer">▸</span>Hey! It's me, ${scriptname} sending a message!</div></li>
                    </div>
                </ul>
            </div>
            <h4>AFK Message Customization</h4>
            <p>When you enable the option to automatically disable Auto-Turn when AFK, it shows a chat message in chat. Here, you can customize the chat message.</p>
            <h5>What type of AFK message do you want to show?</h5>
            <div class="btn-group" role="group" aria-label="autoturn-msgtype">
                <button type="button" class="btn btn-default" type="button" id="autoturn-noafkmsg-btn" onclick="window.autoturnchangesetting(2, 1);">None</button>
                <button type="button" class="btn btn-primary" type="button" id="autoturn-defaultafkmsg-btn" onclick="window.autoturnchangesetting(2, 2);">Default</button>
                <button type="button" class="btn btn-default" type="button" id="autoturn-customafkmsg-btn" onclick="window.autoturnchangesetting(2, 3);">Custom</button>
            </div>
            <div id="custom-msg" style="display: none;">
                <h5>If a custom message, what do you want the custom message to be?</h5>
                <div class="input-group" id="msg-input-group">
                    <input type="text" class="form-control" id="autoturn-msg-input" placeholder="${scriptname} has automatically been disabled because the user has been AFK for too long." maxlength="100">
                    <span class="input-group-btn input-group-append">
                        <button id="autoturn-applyafkmsg-btn" class="btn btn-primary" type="button" onclick="window.autoturnchangesetting(5, 1);">Apply</button>
                    </span>
                </div>
                <span style="color: #a94442; display: none;" id="wrongchatmsg">Chat messages must not be empty and contain no more than 100 characters.</span>
                <br>
                <div style="position:relative;min-height:${previewheight * 1.6}px;margin-bottom:10px;text-align:left;">
                    <ul id="chat-panel" class="list-group-item message-pane-wrapper" style="overflow:hidden;">
                        <div id="chat-box" class="message-pane">
                            <li><div id="afkmsg"><span class="username" id="username2">${msgname}</span><span class="spacer">▸</span>${scriptname} has automatically been disabled because the user has been AFK for too long.</div></li>
                        </div>
                    </ul>
                </div>
            </div>
            <h3>Developer Options (not for regular users)</h3>
            <h4>Force Theme Detection</h4>
            <p>This allows you to force Auto-Turn to behave like it was running on a certain CVM theme, even if it isn't. Expect Auto-Turn to misbehave or display graphical elements incorrectly with this option on!</p>
            <p>The metro theme can't be forced here because the code treats it like the regular theme, due to it's internals being similiar to the regular theme.</p>
            <p>This is also useful if you want Auto-Turn before v1.3.0 to display on the beta theme <i>only slightly better</i>, via clicking the "Bootstrap 4" option, due to Bootstrap 4 being a bit more compatible with the beta theme.</p>
            <!-- eh <p>This isn't to say that it will magically look very good, as it's only <b>slightly</b> better looking, but it's still a good fix if you <i>really</i> want to use this on the beta theme on versions before v1.3.0.</p>
            <!-- uncomment and remove this note for v1.3.0 release <p>Not like you'll have to anyways on this version of Auto-Turn (v${scriptver}), due to the beta theme now having official support.</p> -->
            <h5>What theme do you want to use to trick the theme detection code into thinking it's the applied theme?</h5>
            <div class="btn-group" role="group" aria-label="autoturn-forcetheme">
                <button type="button" class="btn btn-success" type="button" id="autoturn-notheme-btn" onclick="window.autoturnchangesetting(3, 1);">None</button>
                <button type="button" class="btn btn-default" type="button" id="autoturn-crabtheme-btn" onclick="window.autoturnchangesetting(3, 2);">CVM Red & Black Theme</button>
                <button type="button" class="btn btn-default" type="button" id="autoturn-bt4theme-btn" onclick="window.autoturnchangesetting(3, 3)">Bootstrap 4</button>
                <button type="button" class="btn btn-default" type="button" id="autoturn-bt5theme-btn" onclick="window.autoturnchangesetting(3, 4);">Bootstrap 5</button>
                <button type="button" class="btn btn-default" type="button" id="autoturn-betatheme-btn" onclick="window.autoturnchangesetting(3, 5);" disabled="disabled">Beta Theme</button>
            </div>
        </div>
        `;
    addmodal("About Script (scroll down if you can't fully see the whole page)", aboutscriptbody, "OK", "autoturn-aboutscript");
    addmodal("Options Help (scroll down if you can't fully see the whole page)", helpmodalbody, "Done", "autoturn-optionhelp");
    addmodal("Changelog (scroll down if you can't fully see the whole page)", changelogbody, "Close", "autoturn-changelog");
    addmodal("Settings (scroll down if you can't fully see the whole page)", settingsbody, "Apply", "autoturn-settings"); // the button text is useless, the settings automatically apply each time they're changed
    // post-modals startup code
    if (crab) { // for cvm red and black theme graphical dropdown compatibility
        document.getElementById("autoturn-name-input").style.backgroundColor = "#111";
        document.getElementById("autoturn-name-input").style.border = "none";
        document.getElementById("autoturn-msg-input").style.backgroundColor = "#111";
        document.getElementById("autoturn-msg-input").style.border = "none";
    }
    if (localStorage.getItem('autoturn-disablewhenafk') == 'false') {
        disablewhenafk = false;
        document.getElementById("autoturn-disablewhenafk-btn").classList.remove("btn-success");
        document.getElementById("autoturn-disablewhenafk-btn").classList.add("btn-default");
        document.getElementById("autoturn-runwhenafk-btn").classList.remove("btn-default");
        document.getElementById("autoturn-runwhenafk-btn").classList.add("btn-danger");
    }
    if (localStorage.getItem('autoturn-afkmsgtype') == 'nomsg') {
        document.getElementById("autoturn-noafkmsg-btn").classList.remove("btn-default");
        document.getElementById("autoturn-noafkmsg-btn").classList.add("btn-danger");
        document.getElementById("autoturn-defaultafkmsg-btn").classList.remove("btn-primary");
        document.getElementById("autoturn-defaultafkmsg-btn").classList.add("btn-default");
        document.getElementById("autoturn-customafkmsg-btn").classList.remove("btn-info");
        document.getElementById("autoturn-customafkmsg-btn").classList.add("btn-default");
    } else if (localStorage.getItem('autoturn-afkmsgtype') == 'custom') {
        document.getElementById("autoturn-noafkmsg-btn").classList.remove("btn-default");
        document.getElementById("autoturn-noafkmsg-btn").classList.remove("btn-danger");
        document.getElementById("autoturn-noafkmsg-btn").classList.add("btn-default");
        document.getElementById("autoturn-defaultafkmsg-btn").classList.remove("btn-primary");
        document.getElementById("autoturn-defaultafkmsg-btn").classList.add("btn-default");
        document.getElementById("autoturn-customafkmsg-btn").classList.remove("btn-default");
        document.getElementById("autoturn-customafkmsg-btn").classList.add("btn-info");
        document.getElementById("custom-msg").style.display = "block";
    }
    if (localStorage.getItem('autoturn-forcetheme') == 'crab') {
        document.getElementById("autoturn-notheme-btn").classList.remove("btn-success");
        document.getElementById("autoturn-notheme-btn").classList.add("btn-default");
        document.getElementById("autoturn-crabtheme-btn").classList.remove("btn-default");
        document.getElementById("autoturn-crabtheme-btn").classList.add(darkbtnclass);
        document.getElementById("autoturn-bt4theme-btn").classList.add("btn-default");
        document.getElementById("autoturn-bt5theme-btn").classList.add("btn-default");
        document.getElementById("autoturn-betatheme-btn").classList.add("btn-default");
    } else if (localStorage.getItem('autoturn-forcetheme') == 'bt4') {
        document.getElementById("autoturn-noafkmsg-btn").classList.remove("btn-default");
        document.getElementById("autoturn-notheme-btn").classList.remove("btn-success");
        document.getElementById("autoturn-notheme-btn").classList.add("btn-default");
        document.getElementById("autoturn-crabtheme-btn").classList.remove(darkbtnclass);
        document.getElementById("autoturn-crabtheme-btn").classList.add("btn-default");
        document.getElementById("autoturn-bt4theme-btn").classList.remove("btn-default");
        document.getElementById("autoturn-bt5theme-btn").classList.add("btn-default");
        document.getElementById("autoturn-betatheme-btn").classList.add("btn-default");
    } else if (localStorage.getItem('autoturn-forcetheme') == 'bt5') {
        document.getElementById("autoturn-notheme-btn").classList.remove("btn-success");
        document.getElementById("autoturn-notheme-btn").classList.add("btn-default");
        document.getElementById("autoturn-crabtheme-btn").classList.remove(darkbtnclass);
        document.getElementById("autoturn-crabtheme-btn").classList.add("btn-default");
        document.getElementById("autoturn-bt4theme-btn").classList.add("btn-default");
        document.getElementById("autoturn-bt5theme-btn").classList.remove("btn-default");
        document.getElementById("autoturn-betatheme-btn").classList.add("btn-default");
    } else if (localStorage.getItem('autoturn-forcetheme') == 'beta') {
        document.getElementById("autoturn-noafkmsg-btn").classList.remove("btn-default");
        document.getElementById("autoturn-notheme-btn").classList.remove("btn-success");
        document.getElementById("autoturn-notheme-btn").classList.add("btn-default");
        document.getElementById("autoturn-crabtheme-btn").classList.remove(darkbtnclass);
        document.getElementById("autoturn-crabtheme-btn").classList.add("btn-default");
        document.getElementById("autoturn-bt4theme-btn").classList.add("btn-default");
        document.getElementById("autoturn-bt5theme-btn").classList.add("btn-default");
        document.getElementById("autoturn-betatheme-btn").classList.remove("btn-default");
    }
    if (localStorage.getItem('autoturn-msgname') != null) {
        if (localStorage.getItem('autoturn-msgname') == scriptname) {
            msgname = scriptname;
        } else {
            document.getElementById("autoturn-name-input").value = msgname;
        }
        document.getElementById("username").textContent = msgname;
        document.getElementById("username2").textContent = msgname;
    }
    if (localStorage.getItem('autoturn-afkmsg') != null) {
        if (localStorage.getItem('autoturn-afkmsg') == afkmsg) {
            document.getElementById("autoturn-msg-input").value = afkmsg;
            document.getElementById("afkmsg").innerHTML = `<span class="username" id="username2">${msgname}</span><span class="spacer">▸</span>${afkmsg}`;
        }
    }
    if (localStorage.getItem('autoturn-maturelang') == 'true') {
        document.getElementById("autoturn-familyfriendlylang-btn").classList.remove("btn-danger");
        document.getElementById("autoturn-familyfriendlylang-btn").classList.add("btn-default");
        document.getElementById("autoturn-maturelang-btn").classList.remove("btn-default");
        document.getElementById("autoturn-maturelang-btn").classList.add("btn-success");
    } else if (localStorage.getItem('autoturn-maturelang') == 'false') {
        localStorage.setItem('autoturn-maturelang', 'false');
        document.getElementById("autoturn-maturelang-btn").classList.remove("btn-success");
        document.getElementById("autoturn-maturelang-btn").classList.add("btn-default");
        document.getElementById("autoturn-familyfriendlylang-btn").classList.remove("btn-default");
        document.getElementById("autoturn-familyfriendlylang-btn").classList.add("btn-danger");
    }
    vmscreen.parentNode.addEventListener('mousemove', e => {
        // console.log("Stopwatch reset.");
        afkstopwatch = 0;
    });
    // auto-turn options
    addoption("Enable Auto-Turn", function() {window.autoturnenabled = true; turnbtn.click();}); // commented here so it's more visible what the autoturn variable is
    addoption("Disable Auto-Turn", function() {window.autoturnenabled = false});
    addseparator();
    // autostart options
    addoption("Start on page load", enableautostart); // automatically starts auto-turn
    addoption("Start on user input only", disableautostart); // starts only when told to
    // misc. options for future updates
    if (bt5) {
        addseparator();
        addoption("These options don't work");
        addoption("under this theme due to");
        addoption("\"modals\" not working.");
        addoption("Click to show anyways.", addmodaloptions);
    } else {
        addmodaloptions();
    }
    // defining "window" (global) variables
    window.autoturninstalled = true; // see if auto turn is installed (for other scripts)
    window.autoturnscriptver = scriptver; // so some other script can access it idk
    window.autoturnaddoption = addoption; // see the comment on line 39
    window.autoturnaddseperator = addseparator;
    window.autoturnaddmodal = addmodal;
    window.autoturnchangesetting = changesetting;

    window.autoturn = { // attempt to bring back user123's code
        isinstalled: true,
        scriptver: scriptver,
        addoption: addoption,
        // addheader: addheader, (future update)
        addseparator: addseparator,
        addmodal: addmodal,
        showmaturelang: showmaturelang // debugging
    }
    // functions (did i write too many comments?)
    function enableautostart() { // enables auto-start (does not toggle it)
        localStorage.setItem('autoturn-autostart', 'true');
    }

    function disableautostart() { // last one, but disables it instead
        localStorage.setItem('autoturn-autostart', 'false');
    }

    function showaboutscript() { // exactly what it says
        $("#autoturn-aboutscript").modal();
    }

    function showoptionshelp() { // also exactly what it says
        $("#autoturn-optionhelp").modal();
        // GM_notification("A new widget is available at the frobber.", "New widget!"); // what it was even for (by user123)
        /* (by swordlink1)
        1. it's "was it", not "it was".
        2. it was just a test ok
        */
    }

    function showchangelog() { // still exactly what it says
        $("#autoturn-changelog").modal();
    }

    function random(min, max) {
        return Math.floor(Math.random() * (max - min) + min);
    }

    function showsettings() { // same as above
        if (showmaturelang) { // this doesn't only show mature language strings, this also mixes them with the family friendly ones
            var mixedstrings = Object.assign(familyfriendlymessages, maturemessages); // mixes them up here
            var randommsgnum = random(0, Object.keys(mixedstrings).length)
            var randommsgname = Object.keys(mixedstrings)[randommsgnum];
            var randommsgcontent = Object.values(mixedstrings)[randommsgnum];
        } else {
            var randommsgnum = random(0, Object.keys(familyfriendlymessages).length)
            var randommsgname = Object.keys(familyfriendlymessages)[randommsgnum];
            var randommsgcontent = Object.values(familyfriendlymessages)[randommsgnum];
        }
        if (msgname == "mv_") {
            document.getElementById("random-message").innerHTML = `<span class="username moderator">${randommsgname}</span><span class="spacer">▸</span>${randommsgcontent}</div>`;
        } else if (msgname == "Hildaboo" || msgname == "CHOCOLATEMAN") {
            document.getElementById("random-message").innerHTML = `<span class="username admin">${randommsgname}</span><span class="spacer">▸</span>${randommsgcontent}</div>`;
        } else {
            document.getElementById("random-message").innerHTML = `<span class="username">${randommsgname}</span><span class="spacer">▸</span>${randommsgcontent}</div>`;
        }
        $("#autoturn-settings").modal();
    }

    function addmodaloptions() {
        addseparator();
        addoption("About Script and FAQ", showaboutscript);
        addoption("Changelog", showchangelog);
        addoption("Options Help", showoptionshelp);
        addoption("Settings " + newlabel, showsettings);
    }

    function sendmsg(msg) { // auto-turn chat commands + afk message
        var oldname = document.getElementById("chat-user").textContent; // restore old username after we're done with the message
        document.getElementById("username-box").value = msgname;
        document.getElementById("username-ok-btn").click();
        document.getElementById("chat-input").value = msg;
        document.getElementById("chat-send-btn").click();
        document.getElementById("username-box").value = oldname;
        document.getElementById("username-ok-btn").click();
    }

    function changesetting(settingnum, btnnum) {
        if (settingnum == 1) {
            if (btnnum == 1) {
                localStorage.setItem('autoturn-disablewhenafk', 'true');
                disablewhenafk = true;
                document.getElementById("autoturn-runwhenafk-btn").classList.remove("btn-danger");
                document.getElementById("autoturn-runwhenafk-btn").classList.add("btn-default");
                document.getElementById("autoturn-disablewhenafk-btn").classList.remove("btn-default");
                document.getElementById("autoturn-disablewhenafk-btn").classList.add("btn-success");
            } else if (btnnum == 2) {
                disablewhenafk = false;
                localStorage.setItem('autoturn-disablewhenafk', 'false');
                document.getElementById("autoturn-disablewhenafk-btn").classList.remove("btn-success");
                document.getElementById("autoturn-disablewhenafk-btn").classList.add("btn-default");
                document.getElementById("autoturn-runwhenafk-btn").classList.remove("btn-default");
                document.getElementById("autoturn-runwhenafk-btn").classList.add("btn-danger");
            }
        } else if (settingnum == 2) {
            if (btnnum == 1) {
                localStorage.setItem('autoturn-afkmsgtype', 'nomsg');
                document.getElementById("msg-input-group").classList.remove("has-error");
                document.getElementById("wrongchatmsg").style.display = "none";
                document.getElementById("autoturn-msg-input").value = afkmsg;
                document.getElementById("autoturn-noafkmsg-btn").classList.remove("btn-default");
                document.getElementById("autoturn-noafkmsg-btn").classList.add("btn-danger");
                document.getElementById("autoturn-defaultafkmsg-btn").classList.remove("btn-primary");
                document.getElementById("autoturn-defaultafkmsg-btn").classList.add("btn-default");
                document.getElementById("autoturn-customafkmsg-btn").classList.remove("btn-info");
                document.getElementById("autoturn-customafkmsg-btn").classList.add("btn-default");
                document.getElementById("custom-msg").style.display = "none";
            } else if (btnnum == 2) {
                localStorage.setItem('autoturn-afkmsgtype', 'default');
                document.getElementById("msg-input-group").classList.remove("has-error");
                document.getElementById("wrongchatmsg").style.display = "none";
                document.getElementById("autoturn-msg-input").value = afkmsg;
                document.getElementById("autoturn-noafkmsg-btn").classList.remove("btn-danger");
                document.getElementById("autoturn-noafkmsg-btn").classList.add("btn-default");
                document.getElementById("autoturn-defaultafkmsg-btn").classList.remove("btn-default");
                document.getElementById("autoturn-defaultafkmsg-btn").classList.add("btn-primary");
                document.getElementById("autoturn-customafkmsg-btn").classList.remove("btn-info");
                document.getElementById("autoturn-customafkmsg-btn").classList.add("btn-default");
                document.getElementById("custom-msg").style.display = "none";
            } else if (btnnum == 3) {
                localStorage.setItem('autoturn-afkmsgtype', 'custom');
                document.getElementById("autoturn-noafkmsg-btn").classList.remove("btn-danger");
                document.getElementById("autoturn-noafkmsg-btn").classList.add("btn-default");
                document.getElementById("autoturn-defaultafkmsg-btn").classList.remove("btn-primary");
                document.getElementById("autoturn-defaultafkmsg-btn").classList.add("btn-default");
                document.getElementById("autoturn-customafkmsg-btn").classList.remove("btn-default");
                document.getElementById("autoturn-customafkmsg-btn").classList.add("btn-info");
                document.getElementById("custom-msg").style.display = "block";
            }
        } else if (settingnum == 3) {
            if (btnnum == 1) {
                localStorage.setItem('autoturn-forcetheme', 'none');
                document.getElementById("autoturn-notheme-btn").classList.remove("btn-default");
                document.getElementById("autoturn-notheme-btn").classList.add("btn-success");
                document.getElementById("autoturn-crabtheme-btn").classList.remove(darkbtnclass);
                document.getElementById("autoturn-crabtheme-btn").classList.add("btn-default");
                document.getElementById("autoturn-bt4theme-btn").classList.add("btn-default");
                document.getElementById("autoturn-bt5theme-btn").classList.add("btn-default");
                document.getElementById("autoturn-betatheme-btn").classList.add("btn-default");
            } else if (btnnum == 2) {
                localStorage.setItem('autoturn-forcetheme', 'crab');
                document.getElementById("autoturn-notheme-btn").classList.remove("btn-success");
                document.getElementById("autoturn-notheme-btn").classList.add("btn-default");
                document.getElementById("autoturn-crabtheme-btn").classList.remove("btn-default");
                document.getElementById("autoturn-crabtheme-btn").classList.add(darkbtnclass);
                document.getElementById("autoturn-bt4theme-btn").classList.add("btn-default");
                document.getElementById("autoturn-bt5theme-btn").classList.add("btn-default");
                document.getElementById("autoturn-betatheme-btn").classList.add("btn-default");
            } else if (btnnum == 3) {
                localStorage.setItem('autoturn-forcetheme', 'bt4');
                document.getElementById("autoturn-notheme-btn").classList.remove("btn-success");
                document.getElementById("autoturn-notheme-btn").classList.add("btn-default");
                document.getElementById("autoturn-crabtheme-btn").classList.remove(darkbtnclass);
                document.getElementById("autoturn-crabtheme-btn").classList.add("btn-default");
                document.getElementById("autoturn-bt4theme-btn").classList.remove("btn-default");
                document.getElementById("autoturn-bt5theme-btn").classList.add("btn-default");
                document.getElementById("autoturn-betatheme-btn").classList.add("btn-default");
            } else if (btnnum == 4) {
                localStorage.setItem('autoturn-forcetheme', 'bt5');
                document.getElementById("autoturn-notheme-btn").classList.remove("btn-success");
                document.getElementById("autoturn-notheme-btn").classList.add("btn-default");
                document.getElementById("autoturn-crabtheme-btn").classList.remove(darkbtnclass);
                document.getElementById("autoturn-crabtheme-btn").classList.add("btn-default");
                document.getElementById("autoturn-bt4theme-btn").classList.add("btn-default");
                document.getElementById("autoturn-bt5theme-btn").classList.remove("btn-default");
                document.getElementById("autoturn-betatheme-btn").classList.add("btn-default");
            } else if (btnnum == 5) {
                localStorage.setItem('autoturn-forcetheme', 'beta');
                document.getElementById("autoturn-notheme-btn").classList.remove("btn-success");
                document.getElementById("autoturn-notheme-btn").classList.add("btn-default");
                document.getElementById("autoturn-crabtheme-btn").classList.remove(darkbtnclass);
                document.getElementById("autoturn-crabtheme-btn").classList.add("btn-default");
                document.getElementById("autoturn-bt4theme-btn").classList.add("btn-default");
                document.getElementById("autoturn-bt5theme-btn").classList.add("btn-default");
                document.getElementById("autoturn-betatheme-btn").classList.remove("btn-default");
            }
        } else if (settingnum == 4) {
            if (btnnum == 1) {
                document.getElementById("name-input-group").classList.remove("has-error");
                document.getElementById("wrongusername").style.display = "none";
                var newnameinput = document.getElementById("autoturn-name-input").value;
                var antiemptyname = newnameinput.trim(); // remove spaces to see if the name is just all spaces
                var allowedname = true; // see if the new name complys with the username guidelines
                var charmatchesallowedchar = false; // see if the new name complys with the username guidelines
                if (antiemptyname.length == 0 || newnameinput.length < 3 || newnameinput.length > 20) {
                    allowedname = false;
                } else {
                    var namearray = Array.from(newnameinput);
                    for (var i = 0; i < namearray.length; ++i) {
                        charmatchesallowedchar = false;
                        for (var j = 0; j < allowednamechars.length; ++j) {
                            if (namearray[i] == allowednamechars[j]) {
                                charmatchesallowedchar = true;
                            }
                        }
                        if (!charmatchesallowedchar) {
                            allowedname = false;
                            break;
                        }
                    }
                }
                if (allowedname) {
                    localStorage.setItem('autoturn-msgname', newnameinput);
                    document.getElementById("username").textContent = newnameinput;
                    document.getElementById("username2").textContent = newnameinput;
                    msgname = newnameinput;
                } else {
                    document.getElementById("name-input-group").classList.add("has-error");
                    document.getElementById("wrongusername").style.display = "inline-block";
                }
            } else if (btnnum == 2) {
                document.getElementById("name-input-group").classList.remove("has-error");
                document.getElementById("wrongusername").style.display = "none";
                msgname = scriptname;
                localStorage.setItem('autoturn-msgname', scriptname);
                document.getElementById("autoturn-name-input").value = "";
                document.getElementById("username").textContent = scriptname;
                document.getElementById("username2").textContent = scriptname;
            }
        } else if (settingnum == 5) {
            if (btnnum == 1) {
                document.getElementById("msg-input-group").classList.remove("has-error");
                document.getElementById("wrongchatmsg").style.display = "none";
                var newmsginput = document.getElementById("autoturn-msg-input").value;
                var antiemptystring = newmsginput.trim(); // remove spaces to see if the string is just all spaces
                newmsginput = newmsginput.replace("<", "&lt;");
                newmsginput = newmsginput.replace(">", "&gt;");
                var allowedmsg = true; // see if the new name complys with the message length
                if (antiemptystring.length === 0 || newmsginput.length < 1 || newmsginput.length > 100) {
                    allowedmsg = false;
                }
                if (allowedmsg) {
                    localStorage.setItem('autoturn-afkmsg', newmsginput);
                    afkmsg = newmsginput;
                    document.getElementById("afkmsg").innerHTML = `<span class="username" id="username2">${msgname}</span><span class="spacer">▸</span>${newmsginput}`;
                } else {
                    document.getElementById("msg-input-group").classList.add("has-error");
                    document.getElementById("wrongchatmsg").style.display = "inline-block";
                }
            }
        } else if (settingnum == 6) {
            if (btnnum == 1) {
                localStorage.setItem('autoturn-maturelang', 'true');
                document.getElementById("autoturn-familyfriendlylang-btn").classList.remove("btn-danger");
                document.getElementById("autoturn-familyfriendlylang-btn").classList.add("btn-default");
                document.getElementById("autoturn-maturelang-btn").classList.remove("btn-default");
                document.getElementById("autoturn-maturelang-btn").classList.add("btn-success");
            } else if (btnnum == 2) {
                localStorage.setItem('autoturn-maturelang', 'false');
                document.getElementById("autoturn-maturelang-btn").classList.remove("btn-success");
                document.getElementById("autoturn-maturelang-btn").classList.add("btn-default");
                document.getElementById("autoturn-familyfriendlylang-btn").classList.remove("btn-default");
                document.getElementById("autoturn-familyfriendlylang-btn").classList.add("btn-danger");
            }
        }
    }

    function addmodal(title, body, btntext, modalid, alert) { // developer convience, and only has support for one generic close button (if you want extra buttons with extra functionality, then modify this function to your likings)
        var modaltoadd = document.createElement("div");
        modaltoadd.classList.add("modal", "fade");
        modaltoadd.id = "" + modalid;
        modaltoadd.setAttribute("tabindex", "-1");
        modaltoadd.setAttribute("aria-labelledby", modalid + "Label");
        if (bt4) {
            modaltoadd.setAttribute("aria-hidden", "true");
            modaltoadd.setAttribute("role", "dialog");
            modaltoadd.innerHTML =
            `
            <div class="modal-dialog" role="document" style="max-width: 600px!important;">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="${modalid}Label">${title}</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        ${body}
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">${btntext}</button>
                </div>
            </div>
            `;
        } else {
            modaltoadd.setAttribute("role", "dialog");
            modaltoadd.innerHTML =
            `
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="${modalid}Label">${title}</h4>
                    </div>
                    <div class="modal-body">
                        ${body}
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">${btntext}</button>
                </div>
            </div>
            `;
        }
        document.body.appendChild(modaltoadd);
    }

    function addoption(optionname, doonclick) { // same comment as above, except that it adds a interactable dropdown option instead
        var optiontoadd = document.createElement("li"), link = document.createElement("a");
        link.href = "javascript:void(0)";
        link.onclick = doonclick;
        link.style.cursor = "pointer";
        link.innerHTML = optionname;
        link.classList.add("dropdown-item");
        if (bt4) {
            dropdownlist.appendChild(link);
        } else {
            optiontoadd.appendChild(link);
            dropdownlist.appendChild(optiontoadd);
        }
    }

    function addseparator() { // same comment as above, except that it adds a separator instead that separates/divides the options
        if (bt4) {
            var separatortoadd = document.createElement("div");
        } else {
            var separatortoadd = document.createElement("li");
        }
        separatortoadd.classList.add("divider", "dropdown-divider");
        separatortoadd.setAttribute("role", "separator");
        if (crab) {
            if (bt4) {
                separatortoadd.style.borderTop = "1px solid #222";
            } else {
                separatortoadd.style.backgroundColor = "#222";
            }
        }
        dropdownlist.appendChild(separatortoadd);
    }

    // setinterval code
	// if browser supports MutationObserver, then use a better way to detect turn end
	if(window.MutationObserver) {
		var observer = new MutationObserver(function(mutations) {
			mutations.forEach(function() {
				if (window.autoturnenabled && turnbtn.style.display != "none") {
					turnbtn.click();
				}
			});
		});
		observer.observe(turnbtn, {attributes: true, attributeFilter: ['style']});
	} else {
    	setInterval(function() {
    		if (window.autoturnenabled && turnbtn.style.display != "none") {
				// checking for autoturnenabled first so it don't check the turnbtn display when unneeded
            	turnbtn.click();
        	}
    	}, 0);
	}

    setInterval(function() { // afk code
    	if (window.autoturnenabled && disablewhenafk == true) {
			afkstopwatch = afkstopwatch + 1;
            console.log(afkstopwatch);
            if (afkstopwatch >= 3) {
                afkstopwatch = 0;
                window.autoturnenabled = false;
                $(endturnbtn).click();
                if (localStorage.getItem('autoturn-afkmsgtype') == "nomsg") {
                    // nothing to do here without any message to send
                } else if (localStorage.getItem('autoturn-afkmsgtype') == "default") {
                    sendmsg(`${scriptname} has automatically been disabled because the user has been AFK for too long.`);
                } else if (localStorage.getItem('autoturn-afkmsgtype') == "custom") {
                    sendmsg(afkmsg);
                }
            }
       	}
    }, 1000);
})();