Fiction.Live Merged

An attempt to improve fiction.live through the addition of various features.

2021-02-19 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

// ==UserScript==
// @name         Fiction.Live Merged
// @namespace    http://tampermonkey.net/
// @version      43.5
// @description  An attempt to improve fiction.live through the addition of various features.
// @author       You
// @match        https://fiction.live/*
// @grant        none
// @run-at       document-idle
// @noframes
// ==/UserScript==
(function () {
    'use strict';
    function insertCSS() {
        var css = `
    	#loginMenu .dropdown-menu{right:-6.2em;}
    	#confBox,
    	#scriptTitle,
    	#scriptTitle h1,
    	#reportDiv,
    	#reportDiv *,
    	#settingsAlertBox,
    	#settingsAlertBox *,
    	#styleEntries,
    	#styleEntries *,
    	#settingsBlacklist,
    	#settingsBox,
    	#settingsBox *,
    	#styleInput,
    	.toggleBtn,
    	.cssBtn,
    	.settingsToggle,
    	.settingsToggle div,
    	.settingsTab,
    	.settingsTab .entryTitle,
    	.settingsSelect,
    	.blacklistEntry {
    		background: #2a2c3b !important;
    		color:white !important;
    	}
    	#confDisp {
    		height: 100%;
    		position: fixed;
    		top: 0;
    		bottom: 0;
    		left: 0;
    		right: 0;
    		z-index: 9999;
    		display: none;
    		overflow-y: auto;
    		pointer-events: auto;
    	}
    	#confBox * {
    		background: #2a2c3b;
    	}
    	#confBox {
    		height: auto;
    		min-height: 60%;
    		background: #2a2c3b;
    		width: auto;
    		min-width: 60%;
    		position: relative;
    		top: 10px;
    		margin: 10%;
    		padding: 1%;
    		display: flex;
    		flex-flow: column;
    		background: #2a2c3b;
    		box-shadow: 0 0 10px #000000;
    		pointer-events: auto;
    	}
    	#scriptTitle * {
    		margin: 0;
    		display: inline;
    	}
    	#scriptTitle{
    	}
    	.settingsSelect {
    		max-height: 80px;
    		padding-top: 5px;
    	}
    	.settingsSelectDiv {
    		display: inline-block;
    		background: #4b4f6b;
    		box-sizing:border-box;
    		height: 2em;
    	}
    	.settingsSelectBTN {
    		width: 100% !important;
    		height: 100%;
    		font-size: 20px;
    		color: white !important;
    		text-decoration: none;
    		background: #373952 !important;
    		box-sizing: border-box;
    		border: 1px #21222b solid;
    	}
    	.settingsSelectBTN:disabled {
    		background: #4b4f6b !important;
    	}
    	.settingsTab {
    		padding: 5px;
    		display: none;
    	}
    	.entryTitle {
    		min-width: 100%;
    		font-Size: 20px;
    		color:white !important;
    	}
    	.settingsToggle {
    		min-height: 37px;
    		max-height: 37px;
    		min-width: 25%;
    		max-width: 25%;
    		color: white;
    		border: thin solid silver;
    		padding: 5px;
    		float: left;
    	}
    	.toggleCheck {
    		-webkit-appearance: none;
    		background: white !important;
    		color:black !important;
    		padding: 9px;
    		display: inline-block;
    		position: relative;
    		height: 100% !important;
    		max-height: 100% !important;
    		margin-top: 0 !important;
    		margin-bottom: 0 !important;
    		margin-left: 5px !important;
    		margin-right: 0 !important;
    		color: black;
    		font-size: 20px;
    	}
    	.toggleCheck:active,
    	.toggleCheck:checked:active {
    	}
    	.toggleCheck:checked {
    	}
    	.toggleCheck:checked:after {
    		content: '\\2714';
    	}
    	.toggleCheck:after {
    		content: '\\2716';
    		position: absolute;
    		top: -5px;
    		left: 1px;
    	}
    	#settingsBlacklist {
    		padding: 5px;
    	}
    	#settingsBox {
    		margin-bottom: 5px;
    	}
    	.settingsInput {
    		color: white;
    		max-width: 40%;
    		height: 30px;
    		margin: 0 !important;
    	}
    	.blacklistEntry {
    		font-size: 20px;
    		float: left;
    		min-width: 50%;
    		color: white;
    		display: inline-block;
    		border: thin solid silver;
    		padding: 5px;
    	}
    	.blacklistEntry p {
    		margin:0;
    		display:inline;
    		font-size:20px !important;
    	}
    	.blacklistRemove {
    		color: white !important;
    		font-size: 20px;
    		display: inline-block;
    		border: 3px solid red;
    		background: red !important;
    		float: right;
    		padding-left: 5px;
    		padding-right: 5px;
    		-webkit-touch-callout: none;
    		-webkit-user-select: none;
    		-khtml-user-select: none;
    		-moz-user-select: none;
    		-ms-user-select: none;
    		user-select: none;
    	}
    	.blacklistRemove:hover {
    		color: white;
    	}
    	#settingsAlertBox {

    	}
    	#styleEntries {

    	}
    	.styleEntry * {
    		display: inline-block;
    		vertical-align: unset;
    	}
    	.styleEntry {
    		display: inline-block;
    		border: thin solid black;
    		padding: 2px 4px 0 4px;
    		margin: 0 5px 5px 5px;
    		background: #373952;
    	}
    	.styleTitle {
    		margin: 0;
    		height: 100%;
    	}
    	.colorSet {
    		width: 7em;
    		margin: 0 1em 0.25em 1em !important;
    		color: white;
    		max-width: 40%;
    		height: 30px;
    	}
    	.colorPick * {
    		all: unset;
    	}
    	.colorPick {
    		width: 25px !important;
    		height: 1.5em !important;
    		border: none !important;
    		padding: 0 !important;
    		margin: 0 0 0.25em 0 !important;
    	}
    	#styleInput {
    		height: 500px;
    		resize: none;
    	}

    	#liveBox {
    		display: block;
    		height: 100%;
    		width: auto;
    		float: right;
    		padding-left: 1%;
    		padding-right: 1%;
    		border-left: solid;
    		border-Right: solid;
    		border-color: #323448;
    		box-sizing: border-box;
    		font-weight: bold;
    		color: white;
    		text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
    	}
    	.blacklist {
    		height: auto;
    		width: 0px;
    	}
    	.linkDiv {
    		width: 100%;
    		overflow: auto;
    	}

    	.linkDiv img {
    		width: 100%;
    		display: block;
    	}
    	.functionalLink {
    		padding: 0.5em;
    	}
    	.functionalContainer {
    		position: relative;
    		width: 100%;
    		padding-bottom: 100%;
    	}
    	.functionalVideo {
    		position: absolute;
    		width: 100%;
    		height: 100%;
    	}
    	.toggleBtn {
    		//-webkit-appearance: none;
    		//padding: 9px;
    		//border-radius: 3px;
    		//display: inline-block;
    		//position: relative;
    		//height:100% !important;
    		//max-height:100% !important;
    		//margin-top:0 !important;
    		//margin-bottom:0 !important;
    		//margin-left:5px !important;
    		//margin-right:0 !important;
    		border: solid #393a4d;
    		border-width: 1px 1px 1px 1px;
    		box-shadow: 1px 1px 1px 1px #4f516b;
    	}
    	.msgModBox{
    		display: none;
    		padding-bottom:0.5em;
    	}
    	.msgMod {
    		width: auto;
    		color: white;
    		font-weight: bold;
    		padding: 0 0.5em 0 0.5em;
    		margin: 0 3em 0 0;
    	}
	    	.msgMod.edit {
    		display: none;
    	}
    	.vis .msgModBox {
    		display: initial;
    	}
    	.vis.editMode .msgModBox .msgMod.edit {
    		display: initial;
    	}
    	.contactMain, .contactL, .contactR, .topicMessage{
    		background:#2a2c3b !important;
    		color:white !important;
    	}
    	.contactL{float:left;width:50%;}
    	.contactR{float:right;width:50%;}
    	.contactR input{
    		background:#2a2c3b !important;
    	}
    	.topicMessage{
    		resize:none;
    	}
    	.colors{
    		background:#2a2c3b !important;
    		color:white !important;
    	}


            `;
        var style = document.createElement('style');

        if (style.styleSheet) {
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        };
        document.getElementsByTagName('head')[0].appendChild(style);
    }
    insertCSS()

    var rolled = false;
    var lastURL = window.location.href;
    var settings = JSON.parse(localStorage.getItem('FL_Settings'));
    var defaultSettings = {
        'imageResize': true,
        'questRemove': true,
        'questAuthorRemove': true,
        'removeTaggedAuthor': false,
        'anonToggle': false,
        'removeUsernames': false,
        'autoRoller': false,
        'removeTopicForm': true,
        'removeBlankTopics': true,
        'authorHighlight': true,
        'authorBlacklist': [],
        'chatBlacklist': false,
        'chatBlacklistReplies': true,
        'chatBlacklisted': [],
        'tagBlacklist': [],
        'alertBlacklist': [],
        'sortAlerts': false,
        'highlightColor': '#393c59',
        'highlightLight': '#fc8c03',
        'highlightLightToggle': false,
        'liveRestore': true,
        'liveLight': false,
        'functionalLinks': false,
        'functionalVideos': false,
        'removeNSFW': false,
        'updateRequestDismiss': false,
        'alertContainer': 999,
        'akunPlus': 'Ignore',
        'customCSS': [{}, ``],
        'userReveal':false,
        'unpublishBTN':false,
        'messageEdit':false
    };

    //Updates settings when there is a change between versions.
    if (!settings) {
        console.log('Settings set to defaults.');
        settings = defaultSettings
    }
    else if (Object.keys(settings).length !== Object.keys(defaultSettings).length) {
        console.log('Settings differ in length.');
        Object.keys(defaultSettings).forEach(
            function (key) {
                if (!(key in settings)) {
                    settings[key] = defaultSettings[key];
                    console.log('Added ' + key + ' to the current settings.');
                };
            });
        if (Object.keys(settings).length > Object.keys(defaultSettings).length) {
            Object.keys(settings).forEach(
                function (key) {
                    if (!(key in defaultSettings)) {
                        console.log(`Removed invalid variable and value from settings, ${key}:${settings[key]}.`);
                        delete settings[key]
                    };
                });
        }
    };

    localStorage.setItem('FL_Settings', JSON.stringify(settings));
    var USERNAME = getUser();

    function getUser(){
        try{
            var cookies = document.cookie;
            cookies = cookies.split("; ")
            for (let i = 0; i < cookies.length; i++) {
                var cookie = cookies[i].split("=")
                if (/.*distinct_id.*/.test(cookie)) {
                    var cookieName = cookie[0].replace(/_posthog/, '')
                    cookieName = cookieName.replace('ph_', '')
                    USERNAME = JSON.parse(decodeURIComponent(cookie[1])).distinct_id
                    break
                }
            }
            return USERNAME
        }catch(error){
            console.log('Username detect failed',error);
            return ''
        };
    };

    function sortQuestTags() {
        //ignore this
        var list = document.querySelector('span.tags');
        var l2 = [...list.children];
        var l3 = l2.filter(
            function (value, index, arr) {
                if (value.className !== 'tag more ng-scope') {
                    return value
                };
            });
        l3.sort((a, b) => a.innerText > b.innerText ? 1 : -1).forEach(node => list.appendChild(node));
    };

    function blacklistRemove(item) {
        if (settings.alertBlacklist.includes(item)) {
            let position = settings.alertBlacklist.indexOf(item);
            settings.alertBlacklist.splice(position, 1);
            localStorage.setItem('FL_Settings', JSON.stringify(settings));
        };
    };

    function removeNSFW(){
        if (settings.removeNSFW == true) {
            Array.from(document.getElementsByClassName('nsfwCover')).forEach(qst=>qst.classList.remove('nsfwCover'));
        }
    }

    function repeatChecker() {
        try {
            let thisPage = window.location.href;
            if (thisPage !== lastURL) {
                try {
                    questCheck.observerQst.disconnect();
                } catch (error) {}
                try {
                    questCheck.observerTopic.disconnect();
                } catch (error) {}
                pageCheck();
                lastURL = window.location.href;
            };
        } catch (error) {
            console.log('Error with repeatChecker', error);
        };
    };
    setInterval(repeatChecker, 500);

    function chatSend(info) {
        let body = info[1]
        try {
            //var encodedBody = encodeURI(body);
            fetch("https://fiction.live/api/anonkun/dice", {
                "credentials": "include",
                "headers": {
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
                    "Accept": "*/*",
                    "Accept-Language": "en-GB,en;q=0.5",
                    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                    "X-Requested-With": "XMLHttpRequest"
                },
                "referrer": window.location.href,
                "body": body,
                "method": "POST",
                "mode": "cors"
            });
        } catch (error) {
            console.log('Error with chatSend', error);
        }
        try {
            let chapterID = info[0][0]
            let dataID = info[0][1]
            let roll = info[0][2]
            var cookies = document.cookie;
            cookies = cookies.split("; ")
            for (let i = 0; i < cookies.length; i++) {
                var cookie = cookies[i].split("=")
                if (/.*distinct_id.*/.test(cookie)) {
                    var cookieName = cookie[0].replace(/_posthog/, '')
                    cookieName = cookieName.replace('ph_', '')
                }
            }
            fetch("https://fiction.live/api/node", {
                "credentials": "include",
                "headers": {
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
                    "Accept": "*/*",
                    "Accept-Language": "en-GB,en;q=0.5",
                    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                    "X-Requested-With": "XMLHttpRequest"
                },
                "referrer": `https://fiction.live/stories/${body}`,
                "body": encodeURI(`r[]=${chapterID}&r[]=${dataID}&nt=chat&b=%2Froll+`) + encodeURIComponent(`${roll}`) + encodeURI(`&ra[hide]=true&ra[_id]=${dataID}&ra[b]=chapter+${dataID}&token=${cookieName}`),
                "method": "POST",
                "mode": "cors"
            });
        } catch (error) {
            console.log('Error with RollSend', error);
        }
    }

    //Ignored as the same can be done with default behaviour
    function externalImage() {
        var externalInput = ''
        var chatInput = document.querySelector('form.chatInputContainer')
        chatInput.appendChild(externalInput)

        var latestUpdate = document.querySelector('div#storyPosts').firstChild.lastChild;
        var dataID = latestUpdate.getAttribute('data-id');
        var questID = document.querySelector('article.chat').getAttribute('chat');
        var img = encodeURIComponent('https://i.pximg.net/img-original/img/2020/12/09/18/17/11/86193328_p9.png');
        function x() {
            fetch("https://fiction.live/api/node", {
                "credentials": "include",
                "headers": {
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
                    "Accept": "*/*",
                    "Accept-Language": "en-GB,en;q=0.5",
                    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                    "X-Requested-With": "XMLHttpRequest"
                },
                "referrer": `${window.location}`,
                "body": `r%5B%5D=${questID}&r%5B%5D=${dataID}&nt=chat&i=${img}&ra%5Bhide%5D=true&ra%5B_id%5D=${dataID}&ra%5Bb%5D=chapter+${dataID}`,
                "method": "POST",
                "mode": "cors"
            });
        }

    }

    function autoRoll(change) {
        if (settings.autoRoller != true) {
            return;
        };
        try {
            var rollRegex = /[0-9]+d[0-9]+(?<!1d1)(\+[0-9]+)?( ?)(([ie]+)?([ut][0-9]+)?)+/
            if (rollRegex.test(change.innerText)) {
                var roll = change.innerText.match(rollRegex)[0];
                var latestUpdate = document.querySelector('div#storyPosts').firstChild.lastChild;
                var poll = latestUpdate.firstChild.firstChild;
                if (latestUpdate.classList.contains('readerPost') == false || poll.classList.contains('closed')) {
                    return
                } else if (!(poll.classList.contains('closed'))) {
                    var dataID = latestUpdate.getAttribute('data-id');
                    var chapterID = document.querySelector('article.threads').getAttribute('threads');
                    chapterID = chapterID.replace(/\/.*/, '');
                    var rollSend = `/roll ${roll}`;
                    var template = `sid=${chapterID}&dice=${encodeURIComponent(rollSend)}`;
                    if (rolled == false) {
                        chatSend([[chapterID, dataID, roll], template]);
                        rolled = true;
                        poll.classList.add('rolled');
                        setTimeout(function () {
                            rolled = false
                        }, 5000);
                    }
                }
            }
        } catch (error) {}
    }

    function authorCheck(quest) {
        if (/fiction.live\/explore.*/.test(window.location)){return}
        let author = quest.querySelector('div.authorPane');
        if (author == null) {
            try {
                author = quest.parentNode.parentNode.querySelector('span.name').innerText
                quest = quest.parentNode.parentNode.parentNode
            } catch (error) {
                console.log('authorCheck Null', error)
            };
        } else {
            author = author.innerText;
        }
        if (settings.authorBlacklist.includes(author)) {
            try {
                while (true) {
                    if (quest.parentNode == null) {
                        break
                    }
                    if (quest.parentNode.classList.contains('ng-scope') && quest.parentNode.tagName == 'LI') {
                        quest.parentNode.remove()
                        break
                    } else {
                        quest = quest.parentNode
                    }
                }
                return
            } catch (error) {
                //console.log('authorCheck remove',error)
            };
            return;
        };
    };

    function tagCheck(quest) {
        let tags = quest.querySelector('div.tags');
        if (tags == null) {
            let tag = quest.parentNode.parentNode.querySelector('div.displayedTag');
            if (tag) {
                if (settings.tagBlacklist.includes(tag.innerText)) {
                    try {
                        while (true) {
                            if (quest.parentNode == null) {
                                break
                            }
                            if (quest.parentNode.classList.contains('ng-scope') && quest.parentNode.tagName == 'LI') {
                                quest.parentNode.remove()
                                break
                            } else {
                                quest = quest.parentNode
                            }
                        }
                        return
                    } catch (error) {
                        console.log('tagCheck remove', error)
                    };
                };
                return

            } else {
                return
            }
        };
        tags = tags.children;
        for (let i = 0; i < tags.length; i++) {
            let tag = tags[i]
            if (settings.tagBlacklist.includes(tag.innerText)) {
                try {
                    quest.parentNode.parentNode.remove();
                } catch (error) {
                    console.log('tagCheck remove', error)
                };
                return;
            };
        };
    };

    function removeBlacklisted() {
        let quests = document.querySelectorAll('div.storyListItem');
        for (let i = 0; i < quests.length; i++) {
            if (settings.questRemove == true) {
                tagCheck(quests[i].children[0]);
            }
            if (settings.questAuthorRemove == true) {
                authorCheck(quests[i].children[0]);
            }
        };
    };

    function liveRestore() {
        if (document.querySelector('div#liveBox')) {
            return
        };
        var navBar = document.querySelector('[id="mainMenuReplacement"][class="navbar navbar-default navbar-fixed-top"]');
        var liveTimer = document.querySelectorAll('[class="next-live ng-scope"]');
        var myLive = document.createElement('div');
        myLive.setAttribute('id', 'liveBox');
        if (settings.liveLight == true) {
            myLive.style.color = 'black';
            myLive.style.textShadow = '-1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff';
        } else {
            myLive.style.color = 'white';
            myLive.style.textShadow = '-1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000';
        }
        while (liveTimer[0].childNodes.length > 0) {
            myLive.appendChild(liveTimer[0].childNodes[0]);
        }
        navBar.appendChild(myLive);
        liveTimer[0].style.display = 'none';
    };

    function waitForTimer() {
        if (settings.liveRestore == false) {
            return
        };

        var observerTimer = new MutationObserver(awaitTimer);
        function awaitTimer(mutations) {
            for (let mutation of mutations) {
                try {
                    var canvas = document.querySelector('header[class="next-live ng-scope"]');
                } catch (error) {}
                if (canvas && (canvas !== undefined && canvas.length != 0)) {
                    observerTimer.disconnect(); // stop observing
                    liveRestore()
                    return;
                };
            };
        };
        observerTimer.observe(document, {
            childList: true,
            subtree: true
        });
        setTimeout(function () {
            try {
                observerTimer.disconnect();
            } catch (error) {}
        }, 1000);
    };

    function questCheck() {
        if ((settings.questRemove && settings.questAuthorRemove) !== true) {
            return;
        }
        try {
            var options = {
                childList: true,
                subtree: true
            };
            function qstMod(mutations) {
                for (let mutation of mutations) {
                    try {
                        let quest = mutation.addedNodes[0];
                        if (quest) {
                            try {
                                if (quest.parentNode.classList.contains('storyListItem')) {
                                    if (settings.questRemove == true) {
                                        tagCheck(quest);
                                    }
                                    if (settings.questAuthorRemove == true) {
                                        authorCheck(quest);
                                    }
                                    removeNSFW();

                                }
                                else if (quest.parentNode.parentNode.parentNode.parentNode.classList.contains('storyListItem') && /.*fiction.live\/$/.test(URL)) {
                                    if (settings.questRemove == true) {
                                        if (quest) {
                                            tagCheck(quest);
                                        }
                                    }
                                    try {
                                        if (settings.questAuthorRemove == true) {
                                            if (quest) {
                                                authorCheck(quest);
                                            }
                                        }
                                    } catch (error) {
                                        console.log(error)
                                    }

                                }
                            } catch (error) {
                                //console.log('If this appears more than twice, make an issue.')
                                if (error instanceof TypeError) {}
                                else {
                                    console.log(error)
                                }
                            }

                        }
                        //observerMessage.disconnect();
                    } catch (error) {
                        console.log('New quest Error', error);
                    }

                };
            };
            let observerQst = new MutationObserver(qstMod);
            observerQst.observe(document, options);
            questCheck.observerQst = observerQst;
            removeBlacklisted();
        } catch (error) {
            console.log('questCheck', error)
        };

    };

    function exploreBlacklistCheck(){
        function checkTagGroup(x){
            if (settings.tagBlacklist.includes(x.querySelector('h2').innerText.replace('/',''))){
                x.remove();
            }else{
                var tags = x.getElementsByClassName('displayedTag');
                let tt=function(tag){
                    if (settings.tagBlacklist.includes(tag.innerText)){
                        tag.closest('.embla__slide').remove()
                    }
                }
                Array.from(tags).forEach(tag=>{tt(tag)});
            }

        }

        function elementAwaitExplore(mutations) {
            for (let mutation of mutations) {
                try {
                    let topic = mutation.addedNodes[0];
                    if (topic) {
                        try {
                            if (!topic.classList){continue};
                            if (topic.classList.contains('popular-tags-list')){
                                observerTopic.disconnect();
                                Array.from(topic.children).forEach(tag=>{checkTagGroup(tag)});
                                removeNSFW()
                            };

                        } catch (error) {
                            console.log(error)
                        }

                    }
                } catch (error) {
                    console.log('New quest Error', error);
                }

            };
        };

        let observerTopic = new MutationObserver(elementAwaitExplore);
        observerTopic.observe(document, {childList: true, subtree: true});
        questCheck.observerTopic = observerTopic;
    };

    function foryouBlacklistCheck(){
        function checkTag(storyListing){
            try{
                var tag = storyListing.getElementsByClassName('displayedTag')[0]
                if (!tag || tag.length == 0){return}
                if (settings.tagBlacklist.includes(tag.innerText)){
                    storyListing.parentNode.remove()
                }}catch(error){}
        };
        function checkAuthor(storyListing){
            try{
                var name = storyListing.querySelector('span.name').innerText
                if (!name || name.length == 0){return}
                if (settings.authorBlacklist.includes(name)){
                    storyListing.parentNode.remove()
                }}catch(error){}
        };

        function elementAwaitForYou(mutations) {
            for (let mutation of mutations) {
                try {
                    var topic = mutation.addedNodes[0];
                    if (topic) {
                        try {
                            if (!topic.classList){return}
                            if (topic.classList.contains('storyListItem')){}
                            var SLIs=document.getElementsByClassName('storyListItem');
                            //console.log('SLIs',SLIs)
                            if (!SLIs || topic.id != 'main'){continue};
                            if (SLIs){
                                observerTopicx.disconnect();
                                Array.from(SLIs).forEach(SLI=>{checkTag(SLI)});
                                Array.from(SLIs).forEach(SLI=>{checkAuthor(SLI)});
                                removeNSFW();
                            };
                        } catch (error) {
                            console.log(error);
                        }
                    }
                    removeNSFW();
                } catch (error) {
                    console.log('New quest Error', error);
                }
            };
        };

        let observerTopicx = new MutationObserver(elementAwaitForYou);
        observerTopicx.observe(document, {childList: true, subtree: true});
        questCheck.observerTopic = observerTopicx;
    };

    function pageCheck() {
        try {
            let URL = window.location.href;
            if ((/.*(fiction.live\/stories\/).*/.test(URL))) {
                //console.log('quest');
                chatThings();
                waitForTimer();
                //questThings();
            } else if (/.*(fiction.live\/stories\?).*/.test(URL)) {
                //console.log('main/search page');
                //mainThings();
                questCheck();
            } else if (/.*(fiction.live\/social\/threads\/).*/.test(URL)) {
                //mainThings();
                chatThings();
            } else if (/.*(fiction.live\/live\?).*/.test(URL)) {
                //console.log('live page');
                //LiveThings();
                questCheck();
            } else if (/.*(fiction.live\/social).*/.test(URL)) {
                //console.log('thread page');
                removeBlankTopics();
            } else if (/.*fiction.live\/$/.test(URL)) {
                questCheck();
            } else if (/.*fiction.live\/explore/.test(URL)) {
                exploreBlacklistCheck()
            } else if (/.*fiction.live\/foryou/.test(URL)) {
                foryouBlacklistCheck()
            } else if (/.*fiction.live\/user\/.*\/(stories$||collections\/.*)/.test(URL)) {
                if (settings.removeTaggedAuthor == true) {
                    questCheck();
                }
            } else {
                console.log('Page currently has no specific functions.');
            }
        } catch (error) {
            console.log('Error with pageCheck', error)
        }

    };

    function removeBlankTopics() {
        if (settings.removeBlankTopics !== true) {
            return;
        }
        try {
            var options = {
                childList: true,
                subtree: true
            };
            function topicWatch(mutations) {
                for (let mutation of mutations) {
                    try {
                        let topic = mutation.addedNodes[0];
                        if (topic) {
                            try {
                                if (typeof(topic.classList) == 'undefined') {}
                                else if (topic.classList.contains('threadList')) {
                                    //observerTopic.disconnect();
                                    let topicItem = topic.querySelectorAll('li.threadListItem')
                                    for (let i = 0; i < topicItem.length; i++) {
                                        if (topicItem[i].querySelector('div.row.title.header').innerText.length == 0) {
                                            topicItem[i].remove();
                                        };
                                    };
                                };

                                //if (!(topic.querySelector('div.row.title.header').innerText)){console.log('empty',topic)}
                            } catch (error) {
                                console.log(error)
                            }

                        }
                    } catch (error) {
                        console.log('New quest Error', error);
                    }

                };
            };
            let observerTopic = new MutationObserver(topicWatch);
            observerTopic.observe(document, options);
            questCheck.observerTopic = observerTopic;
        } catch (error) {
            console.log('topicCheck', error)
        };
    };

    function chatThings() {
        document.addEventListener("click", function (e) {
            function fetchMessages() {
                b.querySelector('.jadeRepeat').childNodes.forEach(d => handleMsg(d))
            }
            if (e.target.matches(".expandComments.showWhenDiscussionOpened")) {
                var b = e.target.parentNode.parentNode.parentNode
                setTimeout(fetchMessages, 500);
            }
        });

        function chatBlacklist(message) {
            try{
                //var ID = document.querySelector('article.threads').getAttribute('threads');
                let username = message.querySelector('.user span').innerText;
                if (settings.chatBlacklist != true || settings.chatBlacklisted.length == 0) {
                    return;
                };
                if (settings.chatBlacklisted.includes(username)) {
                    //message.remove();
                    message.style.display = 'none';
                    message.classList.add('chatListed');
                    return;
                } else {
                    if (settings.chatBlacklistReplies == true) {
                        replyCheck();
                    }
                };
                async function replyCheck() {
                    let msgData = '';
                    if (message.querySelector('.replyAt')) {
                        //console.log(message);
                        await fetch(`https://fiction.live/api/node/${message.firstChild.getAttribute('data-id')}`).then(response => response.json()).then(data => {
                            msgData = data
                        });
                        if (settings.chatBlacklisted.includes(msgData.ra.u.n)) {
                            message.style.display = 'none';
                            setTimeout(function () {
                                try {
                                    document.querySelectorAll('.chatListed').forEach(mm => mm.remove())
                                } catch (error) {
                                    console.log(error)
                                }
                            }, 500);
                        }
                    }
                };
                async function delMSG(name) {
                    try {
                        var msgID = message.firstChild.getAttribute('data-id');
                    } catch (error) {
                        console.log('id fail')
                    }

                    try {}
                    catch (error) {
                        console.log('error')
                    }
                    try {
                        if (name == message.querySelector('div.user span').innerText) {
                            message.remove();
                            return;
                        } else {
                            var commentName = '';
                            var replyName = '';
                            var msgData = '';

                            await fetch("https://fiction.live/api/node/" + msgID, {}).then(response => response.json()).then(data => {
                                msgData = data
                            });

                            commentName = msgData.u[0].n
                            try {
                                replyName = msgData.ra.u.n
                            } catch (error) {
                                console.log('reply fail')
                            }
                            if (settings.chatBlacklisted.includes(replyName)) {
                                //console.log('reply',document.querySelector(`[data-id="${msgID}"]`))
                                message.remove()
                            } else if (settings.chatBlacklisted.includes(commentName)) {
                                //console.log('comment',document.querySelector(`[data-id="${msgID}"]`))
                                message.remove()
                            }
                        }
                    } catch (error) {
                        console.log('total fail', message.parentNode)
                    };
                };
            } catch (error) {}
        };

        function akunPlus(message) {
            try {
                if (settings.akunPlus == 'Ignore') {
                    return;
                } else if (settings.akunPlus == 'Remove') {
                    message.querySelector('.chatMsg').removeAttribute('plan');
                } else {
                    message.querySelector('.chatMsg').setAttribute('plan', '1');
                }
            } catch (error) {
                //console.log(message.querySelector('span.name'),message.querySelector('.message').innerText,error)
            }
        };

        function functionalLinks(message) {
            try{
                try {
                    if (message.querySelector('.message').querySelector('img')) {
                        return;
                    }
                } catch (error) {}
                let Control = [0, 0, 0]
                var elmDiv = document.createElement('div');
                elmDiv.setAttribute('class', 'linkDiv');
                var elmDivControl = document.createElement('div');

                var elmDivControlA = document.createElement('input');
                elmDivControlA.setAttribute("type", "button");
                elmDivControlA.setAttribute("hide", 'false');
                elmDivControlA.value = 'Disable Link(s)'
                elmDivControlA.onclick = function () {
                    if (this.getAttribute('hide') == 'true' || null) {
                        this.setAttribute('hide', 'false');
                        this.value = 'Disable Link(s)';
                        this.parentNode.parentNode.querySelector('.linkDivA').style.display = 'initial';
                    } else {
                        this.setAttribute('hide', 'true');
                        this.value = 'Enable Link(s)';
                        this.parentNode.parentNode.querySelector('.linkDivA').style.display = 'none';
                    }
                }

                var elmDivControlB = document.createElement('input');
                elmDivControlB.setAttribute("type", "button");
                elmDivControlB.setAttribute("hide", 'false');
                elmDivControlB.value = 'Disable Image(s)'
                elmDivControlB.onclick = function () {
                    if (this.getAttribute('hide') == 'true' || null) {
                        this.setAttribute('hide', 'false');
                        this.value = 'Disable Image(s)';
                        this.parentNode.parentNode.querySelector('.linkDivB').style.display = 'initial';
                    } else {
                        this.setAttribute('hide', 'true');
                        this.value = 'Enable Image(s)';
                        this.parentNode.parentNode.querySelector('.linkDivB').style.display = 'none';
                    }
                }

                var elmDivControlC = document.createElement('input');
                elmDivControlC.setAttribute("type", "button");
                elmDivControlC.setAttribute("hide", 'false');
                elmDivControlC.value = 'Disable Video(s)'
                elmDivControlC.onclick = function () {
                    if (this.getAttribute('hide') == 'true' || null) {
                        this.setAttribute('hide', 'false');
                        this.value = 'Disable Video(s)';
                        this.parentNode.parentNode.querySelector('.linkDivC').style.display = 'initial';
                    } else {
                        this.setAttribute('hide', 'true');
                        this.value = 'Enable Video(s)';
                        this.parentNode.parentNode.querySelector('.linkDivC').style.display = 'none';
                    }
                }

                var elmDivA = document.createElement('div');
                elmDivA.setAttribute('class', 'linkDivA');
                elmDiv.appendChild(elmDivA);

                var elmDivB = document.createElement('div');
                elmDivB.setAttribute('class', 'linkDivB');
                elmDiv.appendChild(elmDivB);

                var elmDivC = document.createElement('div');
                elmDivC.setAttribute('class', 'linkDivC');
                elmDiv.appendChild(elmDivC);

                function link(type, type2, link) {
                    var elm = document.createElement(type);
                    if (type2 == 1) {
                        elm.src = link;
                        elmDiv.childNodes[1].appendChild(elm);
                    } else if (type2 == 2) {
                        elm.href = link;
                        elm.innerHTML = 'Link';
                        elm.setAttribute('class', 'functionalLink');
                        elm.rel = "noopener noreferrer";
                        elm.target = "_blank";
                        elmDiv.childNodes[0].appendChild(elm);
                    } else if (type2 == 3) {
                        elm = document.createElement('iframe');
                        elm.setAttribute('frameborder', '0')
                        elm.setAttribute('allowFullScreen', '')
                        elm.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
                        elm.src = link;
                        elm.setAttribute('class', 'functionalVideo');
                        let functionalContainer = document.createElement('div');
                        functionalContainer.setAttribute('class', 'functionalContainer');
                        functionalContainer.appendChild(elm);
                        elmDiv.childNodes[2].appendChild(functionalContainer);
                    }
                    return elmDiv
                }

                if (settings.functionalLinks != true) {
                    return;
                }
                try {
                    //var regex = new RegExp(/(https?:\/\/(www\.)?)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)*/g);
                    var regex = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)*/g);
                    var text = message.querySelector('div.fieldBody').innerText;
                    if (regex.test(text)) {
                        var matches = text.match(regex);
                        var mCount = 0

                        function linkProcess(match) {
                            try {
                                //If theres already a link container, check if the links been embedded
                                if (message.querySelector('.linkDiv')) {
                                    var qq = message.querySelector('.linkDiv').querySelectorAll('a').forEach(
                                        x => {
                                            if (x.href == match) {
                                                return;
                                            };
                                        });
                                };
                            } catch (error) {
                                console.log(error);
                            };
                            if (typeof match == 'undefined' || match.startsWith('/') || match.length < 5 || /.+\..+/.test(match) == false) {}
                            else {
                                try {
                                    if (/([a-z]*\.{2,}[a-z]*)/.test(match) == true) {
                                        return
                                    };
                                    var elm;
                                    if (/https?:\/\//.test(match) == false) {
                                        match = 'https://'.concat(match)
                                    };
                                    if (/.*(jpg|jpeg|png|gif|webm|webp)/.test(match)) {
                                        elm = new link('img', 1, match);
                                        Control[1] = 1;

                                    } else if (settings.functionalVideos == true && /youtube/.test(match)) {
                                        if (/.*v=(\w+).*/.test(match)) {
                                            let src = `https://www.youtube.com/embed/${(match.match(/v=(\w+)/)[1])}`;
                                            elm = new link('iframe', 3, `https://www.youtube.com/embed/${(match.match(/v=(\w+)/)[1])}`);
                                            message.querySelector('.chatMsg').parentNode.appendChild(elm);
                                        } else if (/be\/(\w+)/.test(match)) {
                                            let src = `https://www.youtube.com/embed/${(match.match(/be\/(\w+)/)[1])}`;
                                            elm = new link('iframe', 3, `https://www.youtube.com/embed/${(match.match(/be\/(\w+)/)[1])}`)
                                            message.querySelector('.chatMsg').parentNode.appendChild(elm);
                                        }
                                        Control[2] = 1;
                                    } else {
                                        elm = new link('a', 2, match);
                                        Control[0] = 1;
                                    }
                                } catch (error) {
                                    console.log(error)
                                };
                            }
                        }
                        matches.forEach(match => linkProcess(match))

                        if (Control[0] == 1) {
                            elmDivControl.appendChild(elmDivControlA);
                        };
                        if (Control[1] == 1) {
                            elmDivControl.appendChild(elmDivControlB);
                        };
                        if (Control[2] == 1) {
                            elmDivControl.appendChild(elmDivControlC);
                        };
                        elmDiv.prepend(elmDivControl);
                        message.querySelector('.chatMsg').parentNode.appendChild(elmDiv);
                        elmDiv.scrollIntoView()
                    };
                } catch (error) {
                    //console.log(error)
                }
            } catch (error) {}
        };

        function removeUsernames(message) {
            //return;
            //console.log('this shouldnt be seen')
            if (settings.removeUsernames == true && message.querySelector('span.name')) {
                message.querySelector('span.name').style.display = 'none';
                let authorList = document.querySelectorAll('span.author.ng-scope');
                let authors = []
                authorList.forEach(element => authors.push(element.querySelector('span.name').innerText))

                try {
                    if (authors.includes(message.querySelector('span.name').innerText)) {
                        message.querySelector('span.name').style.display = 'initial';
                        return;
                    } else {
                        setTimeout(function () {
                            try {
                                message.querySelector('img.avatar').remove()
                            } catch (error) {};
                            try {
                                message.querySelector('span.name').innerText = 'anon'
                                message.querySelector('span.name').style.display = 'initial';
                            } catch (error) {
                                console.log('Error forcing anon', error);
                            };
                            setTimeout(function () {
                                if (message.querySelector('span.name').innerText != 'anon') {
                                    message.querySelector('span.name').innerText = 'anon'
                                }
                            }, 100);
                        }, 100);

                    }
                } catch (error) {
                    console.log('Author highlighter failed', error);
                };
            } else{
                return}

        };

        function authorHighlight(message) {
            if (settings.authorHighlight == true && message.querySelector('span.name')) {
                var currentColor = settings.highlightColor;
                if (settings.highlightLightToggle == true) {
                    currentColor = settings.highlightLight;
                }
                let authorList = document.querySelectorAll('span.author.ng-scope');
                let authors = []
                authorList.forEach(element => authors.push(element.querySelector('span.name').innerText))
                try {
                    if (authors.includes(message.querySelector('span.name').innerText)) {
                        if (settings.highlightColor) {
                            try {
                                message.style.backgroundColor = currentColor;
                            } catch (error) {
                                console.log('Failed using custom color', error);
                                message.style.backgroundColor = '#393c59';
                                settings.highlightColor = '#393c59';
                            }
                        } else {
                            message.style.backgroundColor = '#393c59';
                        };
                    };
                } catch (error) {
                    console.log('Author highlighter failed', error);
                };
            } else{
                return}

        };

        function imageResize(message) {
            if (settings.imageResize == true) {
                let msgImage = message.querySelector('div.message').querySelector('img');
                if (msgImage !== null && msgImage !== undefined) {
                    let image = message.querySelector('div.message').querySelector('img');
                    image.src = image.src.replace(/(h[0-9]+\-w[0-9]+)/, 'h5600-w5600');
                    let page = image.src;
                    image.setAttribute('onclick', "window.open('" + page + "', '_blank');")
                    try {
                        image.onerror = (function () {
                            setTimeout(this.src = this.src, 100)
                        })
                    } catch (error) {
                        'img error add fail'
                    };
                };
            } else{
                return}
        };

        async function userReveal(message){
            if (settings.userReveal != true){return}
            try{
                //Gets the userID
                if (message.querySelector('.user span').innerText != 'anon'){return;}
                //console.log('gotMSG')
                var messageID=message.firstChild.getAttribute('data-id')
                var returnedData=message.firstChild.getAttribute('data-id')
                try{
                    await fetch(`https://fiction.live/api/node/${messageID}`).then(response => response.json()).then(data => {returnedData=data});
                    if (!returnedData.u[0]._id){
                        //console.log('no _id')
                        //console.log(returnedData.u)
                        return;
                    };
                    //console.log('got_id',returnedData.u[0]._id)
                    var userID=returnedData.u[0]._id;
                    await fetch(`https://fiction.live/api/anonkun/userCollections/${userID}`, {
                    }).then(response => response.json()).then(data => {userID=data});
                    //console.log(userID)
                    if (userID.length == 0){
                        //console.log('len=0',userID,message);
                        return}
                    message.querySelector('.user span').innerText=userID[0].u[0].n;
                }catch(error){
                    //console.log('no collections',message,error);
                    return;
                }
            }catch(error){
                //console.log(error);
                return;
            }
        };

        function messageEdit(message){
            try{
                if (!message.querySelector('span.name') || USERNAME == ''){return}
            } catch (error) {//console.log('err',error);
            }
            try{
                if (message.querySelector('span.name').innerText != USERNAME){return;}
                let messageID=message.firstChild.getAttribute('data-id');
                let messageCont = document.createElement('div');
                messageCont.setAttribute('class','msgModBox')

                let messageEdit = document.createElement('input');
                messageEdit.setAttribute('type','button')
                messageEdit.setAttribute('class','msgMod const')
                messageEdit.onclick = editMsg;
                messageEdit.value = 'Open Edit Mode';
                messageCont.appendChild(messageEdit)
                function editMsg(){
                    if (settings.messageEdit != true){return}
                    if (messageEdit.closest('.logItem').classList.contains('editMode')){
                        messageEdit.value = 'Open Edit Mode';
                        messageEdit.closest('.logItem').classList.remove('editMode');
                        message.children[2].remove();
                        message.children[1].style.display = '';
                    }
                    else{
                        messageEdit.value = 'Close Edit Mode';
                        messageEdit.closest('.logItem').classList.add('editMode')
                        var messageText = document.createElement('textarea');
                        messageText.setAttribute('placeholder', 'Add any more complicated CSS here.');
                        messageText.setAttribute("cols", "1");
                        messageText.setAttribute("rows", "5");
                        messageText.style.resize = 'none';
                        messageText.style.height = '100px';
                        fetch(`https://fiction.live/api/node/${messageID}`).then(response => response.json()).then(data => {messageText.value = data.b});
                        message.children[1].style.display = 'none';
                        message.appendChild(messageText)
                    }


                };

                let messageSave = document.createElement('input');
                messageSave.setAttribute('type','button')
                messageSave.setAttribute('class','msgMod edit')
                messageSave.onclick = saveMsg;
                messageSave.value = 'Save';
                messageCont.appendChild(messageSave)
                function saveMsg(){
                    let messageContent = message.children[2].value;
                    fetch("https://fiction.live/api/node", {
                        "headers": {
                            "User-Agent": "",
                            "Accept": "application/json, text/javascript, */*; q=0.01",
                            "Accept-Language": "en-GB,en;q=0.5",
                            "Content-Type": "application/json",
                            "X-Requested-With": "XMLHttpRequest"
                        },
                        "body": `{\"_id\":\"${messageID}\",\"b\":\"${messageContent}\"}`,
                        "method": "PUT",
                        "mode": "cors"
                    });

                    messageCont.closest('.logItem').classList.remove('editMode');
                    messageEdit.value = 'Open Edit Mode';
                    message.children[2].remove();
                    message.children[1].style.display = '';
                };

                let messageDiscard = document.createElement('input');
                messageDiscard.setAttribute('type','button')
                messageDiscard.setAttribute('class','msgMod edit')
                messageDiscard.onclick = discardMsg;
                messageDiscard.value = 'Discard';
                messageCont.appendChild(messageDiscard)
                function discardMsg(){
                    message.children[2].value = '';
                };

                let messageDelete = document.createElement('input');
                messageDelete.setAttribute('type','button')
                messageDelete.setAttribute('class','msgMod const')
                messageDelete.onclick = deleteMsg;
                messageDelete.value = 'Delete';
                messageCont.appendChild(messageDelete)
                function deleteMsg(){
                    if (settings.unpublishBTN != true){return}
                    fetch("https://fiction.live/api/node", {
                        "headers": {
                            "User-Agent": "",
                            "Accept": "application/json, text/javascript, */*; q=0.01",
                            "Content-Type": "application/json",
                            "X-Requested-With": "XMLHttpRequest"
                        },
                        "body": `{\"_id\":\"${messageID}\",\"trash\":true}`,
                        "method": "PUT",
                        "mode": "cors"
                    });
                    //messageDelete.remove()
                    message.remove()
                };
                message.prepend(messageCont)
            } catch (error) {
                //console.log('Error',error);
            }
        };

        function onX(message){
            message.addEventListener('mouseover',function(){
                if (this.querySelector('div.user span').innerText!=USERNAME){return;}
                this.classList.add('vis');
                if (this.querySelectorAll('input').length <= 3){messageEdit(this)};this.children[0].scrollIntoView()
            })
            message.addEventListener('mouseout',function(){
                this.classList.remove('vis');
            })
        }

        function whenNewMessage(chat) {
            var options = {
                childList: true
            };
            function messageMod(mutations) {
                for (let mutation of mutations) {
                    try {
                        var message = mutation.addedNodes[0];
                        chatBlacklist(message);
                        userReveal(message);
                        removeUsernames(message);
                        userReveal(message);
                        authorHighlight(message);
                        imageResize(message);
                        autoRoll(message);
                        functionalLinks(message);
                        akunPlus(message);
                        onX(message);
                        //observerMessage.disconnect();
                    } catch (error) {
                        //console.log('New Message Error',error);
                    }

                };
            };
            let observerMessage = new MutationObserver(messageMod);
            observerMessage.observe(chat, options);
        };

        function withOldMessage(chat) {
            var messages = chat.childNodes;
            try {
                messages.forEach(message => {
                    try {
                        chatBlacklist(message);
                        imageResize(message);
                        userReveal(message);
                        authorHighlight(message);
                        removeUsernames(message);
                        functionalLinks(message);
                        akunPlus(message);
                        onX(message);
                    } catch (error) {
                    };
                });
            } catch (error) {
                console.log('OldMsg', error)
            };
        };

        function handleMsg(message) {
            if (message.tagName == 'HEADER') {
                return;
            }try{
                chatBlacklist(message);
                imageResize(message);
                authorHighlight(message);
                functionalLinks(message);
                removeUsernames(message);
                akunPlus(message);
            } catch (error) {}
        }

        function waitForChat() {
            //waits for chat to exist
            var observerChat = new MutationObserver(awaitChat);
            observerChat.observe(document, {
                childList: true,
                subtree: true
            })

            function awaitChat(mutations) {
                for (let mutation of mutations) {
                    try {
                        var chat = document.querySelector('article.chatLog').querySelector('div.jadeRepeat');
                    } catch (TypeError) {};
                    if (chat && chat !== (undefined || null) && chat.length != 0) {
                        observerChat.disconnect();
                        var chatLog = document.querySelectorAll('article.chatLog')
                        for (var i = 0; i < chatLog.length; i++) {
                            whenNewMessage(chatLog[i].querySelector('div.jadeRepeat'));
                            withOldMessage(chatLog[i].querySelector('div.jadeRepeat'));
                        }
                        break;
                    };
                };
            };
        };

        waitForChat();
    };

    function deleteTopicCreate() {
        try {
            if (settings.removeTopicForm == true) {
                let formItem = document.querySelector('div.formItem');
                if (formItem) {
                    formItem.parentNode.remove();
                };
            };
        } catch (error) {
            console.log('Error with removing topic form', error);
        };

    };

    function blacklistAdd() {
        let title = this.parentNode.querySelector('[set-text="item.value.value"]').textContent.replace(' went live', '');
        let author = this.parentNode.querySelector('span.user').innerText;
        let entry = title + '___' + author;
        settings.alertBlacklist.push(entry);
        localStorage.setItem('FL_Settings', JSON.stringify(settings));
        let dismiss = this.parentNode.querySelector('a.dismiss');
        simClick(dismiss);
        document.querySelector('.settingsTab[name="Alerts"]').querySelector('div#settingsBlacklist').appendChild(elementBlacklisted(entry));
    };

    function blacklistCheck(alert) {
        function alertBlacklistButton(alert) {
            function createBlacklistButton() {
                var blacklistButton = document.createElement('a');
                blacklistButton.setAttribute('class', 'blacklist');
                blacklistButton.innerText = '∅';
                blacklistButton.onclick = blacklistAdd;
                return blacklistButton
            }
            alert.childNodes[0].after(createBlacklistButton());
        };
        try {
            var title = alert.querySelector('[set-text="item.value.value"]').textContent.replace(' went live', '');
            var author = alert.querySelector('span.user').innerText;
            var dismiss = alert.querySelector('a.dismiss');
            if (settings.alertBlacklist.includes(title + '___' + author)) {
                simClick(dismiss);
            } else {
                if (!alert.querySelector('a.blacklist')){
                    alertBlacklistButton(alert);
                }
            };
        } catch (error) {
            console.log('blacklist checker error', error)
        };
    };

    function updateCheck(alert) {
        if (settings.updateRequestDismiss == false) {
            return;
        }
        else if (alert.classList.length == 0) {
            return
        }
        try {
            var title = alert.querySelector('[set-text="item.value.value"]').innerText;
            if (/.*Looks forward to the next update for.*/.test(title)) {
                var dismiss = alert.querySelector('a.dismiss');
                simClick(dismiss);
            }
        } catch (error) {
            console.log('updateCheck error', error)
        };
    };

    function simClick(elem) {
        var evt = new MouseEvent('click', {
            bubbles: true,
            cancelable: true,
            view: window
        });
        var canceled = !elem.dispatchEvent(evt);
    };

    function sortAlerts() {
        return;
        //this is broken
        try {
            var sort_by_name = function (a, b) {
                return a.querySelector('.user').innerText.localeCompare(b.querySelector('.user').innerText);
            }
            var list = Array.from(document.querySelectorAll('ul.feedType.ng-scope')[1].querySelectorAll('li'));
            list.sort(sort_by_name);
            for (var i = 0; i < list.length; i++) {
                list[i].parentNode.appendChild(list[i]);
            }
        } catch (error) {}

    };

    function alertUpdate(alert){
        try{
            //console.log('alert up',alert)
            if (settings.updateRequestDismiss == false) {
                return;
            }
            else if (alert.classList.length == 0) {
                return
            }
            var dismiss = alert.querySelector('a.dismiss');
            simClick(dismiss);
        }catch(error){console.log('AU Error',error)}
    };

    function awaitAlerts(){
        try{
            var alerts = document.querySelector('span.feedCount')
            if (alerts){
                //console.log('Alerts Exist');
                try{
                    observerFCP.disconnect();
                }catch(error){};
                monitorFeedCount(alerts.parentNode);
                monitorFeeds();

                let alertContainer = document.querySelectorAll('li.feedItem');
                alertContainer.forEach(alert => {
                    if (/.*went live.*/.test(alert.innerText)) {
                        blacklistCheck(alert);
                    }
                    else if (/.*Looks forward to the next update for.*/.test(alert.innerText)) {
                        alertUpdate(alert)
                    }
                    else if (/.*PM:.*/.test(alert.innerText)) {
                    }
                });
            }
            else{
                //console.log('Alerts Dont Exist');
                var observerFCP = new MutationObserver(awaitFeedCount);
                observerFCP.observe(document, {
                    childList: true,
                    subtree: true
                });
            };

            function awaitFeedCount(mutations){
                //Wait for the feed count, when found stop and start the FC monitor
                try{
                    for (let mutation of mutations) {
                        let alerts = document.querySelector('span.feedCount')
                        if (mutation.addedNodes.length > 0){
                            var elm = mutation.addedNodes[0];
                            if (elm.tagName == 'SPAN' && elm.classList.contains('feedCount')){
                                observerFCP.disconnect();
                                monitorFeedCount(alerts.parentNode);
                                monitorFeeds();
                            };
                        };
                    };
                }
                catch(error){
                    console.log('AFC',error)
                };
            };

            function monitorFeedCount(FC){
                //Monitors feed count parent for when alerts appear or disappear.
                try{
                    var observerFC = new MutationObserver(function(x){
                        if (x[0].removedNodes.length > 0){
                            //console.log('Alerts Removed.');
                            try{
                                window.alertWatcher.disconnect();
                                //console.log('AW');
                            }catch(error){}
                            try{
                                window.observerDrop.disconnect();
                                //console.log('DW');
                            }catch(error){}
                        }
                        else if (x[0].addedNodes.length > 0){
                            //console.log('Alerts Added.',x[0].addedNodes);
                            monitorFeeds();
                        }
                    })
                    observerFC.observe(FC, {childList:true})
                }catch(error){console.log('MFC',error)}
            };

            function monitorFeeds(){
                //Alerts are stored in feeds, this monitors them
                function dropdownWatch(mutations){
                    try{
                        if (dropdown.length == 1){
                            console.log('Dropdown has a single child.')
                            return
                        }
                        for (let mutation of mutations){
                            if (mutation.addedNodes.length > 0 && mutation.addedNodes[0].tagName == 'LI'){
                                let text=mutation.addedNodes[0].innerText
                                let alert = mutation.addedNodes[0]
                                if (/.*went live.*/.test(text)) {
                                    blacklistCheck(alert);
                                }
                                else if (/.*Looks forward to the next update for.*/.test(text)) {
                                    //console.log('update')
                                    alertUpdate(alert)
                                }
                                else if (/.*PM:.*/.test(text)) {
                                    //console.log('pm')
                                }
                            }
                        };
                    }
                    catch(error){
                        console.log('DW',error)
                    };
                };

                var dropdown = document.querySelector('#loginMenu').children[1];
                //console.log('dropdown',dropdown);
                var observerDrop = new MutationObserver(dropdownWatch);
                observerDrop.observe(dropdown, {childList:true,subtree:true});
                window.observerDrop = observerDrop;

                let alertContainer = document.querySelectorAll('li.feedItem');
                alertContainer.forEach(alert => {
                    if (/.*went live.*/.test(alert.innerText)) {
                        blacklistCheck(alert);
                    }
                    else if (/.*Looks forward to the next update for.*/.test(alert.innerText)) {
                        alertUpdate(alert)
                    }
                    else if (/.*PM:.*/.test(alert.innerText)) {
                    }
                });
            }
        }catch(error){console.log('AAlerts',error)}
    }

    function awaitMainMenu() {
        try {
            var options = {
                childList: true,
                subtree: true
            };
            let observerMenu = new MutationObserver(awaitMenu);
            observerMenu.observe(document, options);
            function awaitMenu(mutations) {
                for (let mutation of mutations) {
                    try {
                        var mainMenu = document.querySelector('nav#mainMenu');
                    } catch (error) {};
                    if (mainMenu) {
                        observerMenu.disconnect();
                        settingsContainer();
                        deleteTopicCreate();
                    };
                };
            };
        } catch (error) {
            console.log('Error awaiting main menu', error)
        };

    };

    function elementBlacklisted(element) {
        var settingsBlacklisted = document.createElement('div');
        settingsBlacklisted.setAttribute('class', 'blacklistEntry');

        var settingsBlacklistedText = document.createElement('p');
        settingsBlacklistedText.setAttribute('class', 'colors');
        settingsBlacklistedText.innerText = element;
        settingsBlacklistedText.innerText = settingsBlacklistedText.innerText.replace('___', '     Author: ');

        var settingsBlacklistRemove = document.createElement('a');
        settingsBlacklistRemove.setAttribute('class', 'blacklistRemove')
        settingsBlacklistRemove.innerText = 'Remove'
        settingsBlacklistRemove.onclick = function () {
            blacklistRemove(element);
            this.parentNode.remove();
        }

        settingsBlacklisted.appendChild(settingsBlacklistedText)
        settingsBlacklisted.appendChild(settingsBlacklistRemove)
        return settingsBlacklisted
    };

    function settingsContainer() {
        function settingsDisplay() {
            try {
                if (!document.querySelector('#confDisp')) {
                    function configDisplay() {
                        var confDisp = document.createElement('div');
                        confDisp.setAttribute('id', 'confDisp');
                        return confDisp
                    };
                    function configBox() {
                        var confBox = document.createElement('div');
                        confBox.setAttribute('id', 'confBox');
                        return confBox
                    };

                    //Blacklists start here
                    //Blacklists start here
                    //Blacklists start here
                    //Blacklists start here
                    //Blacklists start here

                    function settingsUserBlacklist() {
                        var settingsTab = document.createElement('div');
                        settingsTab.setAttribute('class', 'settingsTab');
                        settingsTab.setAttribute('name', 'Chat');
                        function chatBlacklistRemove(item) {
                            if (settings.chatBlacklisted.includes(item)) {
                                let position = settings.chatBlacklisted.indexOf(item);
                                settings.chatBlacklisted.splice(position, 1);
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                settings = JSON.parse(localStorage.getItem('FL_Settings'));
                            };
                        };

                        function chatBlacklisted(element) {
                            try {
                                var chatBlacklisted = document.createElement('div');
                                chatBlacklisted.setAttribute('class', 'blacklistEntry');

                                var chatBlacklistedText = document.createElement('p');
                                chatBlacklistedText.setAttribute('class', 'colors');
                                chatBlacklistedText.innerText = element;

                                var settingsUserRemove = document.createElement('a');
                                settingsUserRemove.setAttribute('class', 'blacklistRemove');
                                settingsUserRemove.innerText = 'Remove';
                                settingsUserRemove.onclick = function () {
                                    try {
                                        chatBlacklistRemove(element);
                                        this.parentNode.remove();
                                    } catch (error) {
                                        console.log('Error removing user', error)
                                    }
                                };
                                chatBlacklisted.appendChild(chatBlacklistedText);
                                chatBlacklisted.appendChild(settingsUserRemove);
                                return chatBlacklisted;
                            } catch (error) {
                                console.log('44', error)
                            }
                        };

                        function userAddBlacklist() {
                            var settingsUserBox = document.createElement('div');
                            settingsUserBox.setAttribute('id', 'settingsBox');

                            var settingsUserInput = document.createElement('input');
                            settingsUserInput.setAttribute("type", "text");
                            settingsUserInput.setAttribute("class", "settingsInput");
                            settingsUserInput.setAttribute("placeholder", "Input username here.");

                            var settingsUserAdd = document.createElement('input');
                            settingsUserAdd.setAttribute("type", "button");
                            settingsUserAdd.style.height = '30px';
                            settingsUserAdd.value = 'Add User';
                            settingsUserAdd.onclick = function () {
                                if (settings.chatBlacklisted.includes(this.parentNode.childNodes[0].value)) {
                                    return;
                                }
                                settings.chatBlacklisted.push(this.parentNode.childNodes[0].value);
                                this.parentNode.parentNode.appendChild(chatBlacklisted(this.parentNode.childNodes[0].value));
                                this.parentNode.childNodes[0].value = "";
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                settings = JSON.parse(localStorage.getItem('FL_Settings'));
                                removeBlacklisted();
                            };

                            settingsUserBox.appendChild(settingsUserInput);
                            settingsUserBox.appendChild(settingsUserAdd);

                            return settingsUserBox
                        };

                        var settingsUserBlacklist = document.createElement('div');
                        settingsUserBlacklist.setAttribute('id', 'settingsBlacklist');
                        settingsUserBlacklist.style.padding = '5px';
                        settings.chatBlacklisted = [...new Set(settings.chatBlacklisted)]
                        settings.chatBlacklisted.forEach(element => settingsUserBlacklist.appendChild(chatBlacklisted(element)));

                        var settingsUserBlacklistText = document.createElement('div');
                        settingsUserBlacklistText.setAttribute('class', 'entryTitle');
                        settingsUserBlacklistText.innerText = 'Chat User Blacklist';
                        settingsUserBlacklist.prepend(userAddBlacklist());
                        settingsUserBlacklist.prepend(settingsUserBlacklistText);

                        settingsTab.appendChild(settingsUserBlacklist)
                        return settingsTab;
                    };

                    function settingsAuthorsBlacklist() {
                        var settingsTab = document.createElement('div');
                        settingsTab.setAttribute('class', 'settingsTab');
                        settingsTab.setAttribute('name', 'Author');
                        function authorBlacklistRemove(item) {
                            if (settings.authorBlacklist.includes(item)) {
                                let position = settings.authorBlacklist.indexOf(item);
                                settings.authorBlacklist.splice(position, 1);
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                settings = JSON.parse(localStorage.getItem('FL_Settings'));
                            };
                        };
                        function authorBlacklisted(element) {
                            try {
                                var authorBlacklisted = document.createElement('div');
                                authorBlacklisted.setAttribute('class', 'blacklistEntry')
                                var authorBlacklistedText = document.createElement('p');
                                authorBlacklistedText.setAttribute('class', 'colors');
                                authorBlacklistedText.innerText = element;

                                var settingsAuthorRemove = document.createElement('a');
                                settingsAuthorRemove.setAttribute('class', 'blacklistRemove');
                                settingsAuthorRemove.innerText = 'Remove';
                                settingsAuthorRemove.onclick = function () {
                                    try {
                                        authorBlacklistRemove(element);
                                        this.parentNode.remove();
                                    } catch (error) {
                                        console.log('Error removing author', error)
                                    }
                                };
                                authorBlacklisted.appendChild(authorBlacklistedText);
                                authorBlacklisted.appendChild(settingsAuthorRemove);
                                return authorBlacklisted;
                            } catch (error) {
                                console.log('55', error)
                            }
                        };

                        function authorAddBlacklist() {
                            var settingsAuthorBox = document.createElement('div');
                            settingsAuthorBox.setAttribute('id', 'settingsBox');
                            settingsAuthorBox.style.marginBottom = '5px';

                            var settingsAuthorsInput = document.createElement('input');
                            settingsAuthorsInput.setAttribute("type", "text");
                            settingsAuthorsInput.setAttribute("class", "settingsInput");
                            settingsAuthorsInput.setAttribute("placeholder", "Input author here.");

                            var settingsAuthorsAdd = document.createElement('input');
                            settingsAuthorsAdd.setAttribute("type", "button");
                            settingsAuthorsAdd.style.height = '30px';
                            settingsAuthorsAdd.value = 'Add Author';
                            settingsAuthorsAdd.onclick = function () {
                                if (settings.authorBlacklist.includes(this.parentNode.childNodes[0].value)) {
                                    return;
                                }
                                settings.authorBlacklist.push(this.parentNode.childNodes[0].value);
                                this.parentNode.parentNode.appendChild(authorBlacklisted(this.parentNode.childNodes[0].value));
                                this.parentNode.childNodes[0].value = "";
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                settings = JSON.parse(localStorage.getItem('FL_Settings'));
                                removeBlacklisted();
                            };

                            settingsAuthorBox.appendChild(settingsAuthorsInput);
                            settingsAuthorBox.appendChild(settingsAuthorsAdd);

                            return settingsAuthorBox
                        };

                        var settingsAuthorsBlacklist = document.createElement('div');
                        settingsAuthorsBlacklist.setAttribute('id', 'settingsBlacklist');
                        settings.authorBlacklist = [...new Set(settings.authorBlacklist)]
                        settings.authorBlacklist.sort().forEach(element => settingsAuthorsBlacklist.appendChild(authorBlacklisted(element)));

                        var settingsAuthorsBlacklistText = document.createElement('div');
                        settingsAuthorsBlacklistText.innerText = 'Authors Blacklist';
                        settingsAuthorsBlacklistText.setAttribute('class', 'entryTitle');
                        settingsAuthorsBlacklist.prepend(authorAddBlacklist());
                        settingsAuthorsBlacklist.prepend(settingsAuthorsBlacklistText);

                        settingsTab.appendChild(settingsAuthorsBlacklist)
                        return settingsTab;
                    };

                    function settingsTagsBlacklist() {
                        var settingsTab = document.createElement('div');
                        settingsTab.setAttribute('class', 'settingsTab');
                        settingsTab.setAttribute('name', 'Tags');
                        function tagBlacklistRemove(item) {
                            if (settings.tagBlacklist.includes(item)) {
                                let position = settings.tagBlacklist.indexOf(item);
                                settings.tagBlacklist.splice(position, 1);
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                settings = JSON.parse(localStorage.getItem('FL_Settings'));
                            };
                        };
                        function tagBlacklisted(element) {
                            try {
                                var tagBlacklisted = document.createElement('div');
                                tagBlacklisted.setAttribute('class', 'blacklistEntry');
                                var tagBlacklistedText = document.createElement('p');
                                tagBlacklistedText.setAttribute('class', 'colors');
                                tagBlacklistedText.innerText = element;

                                var settingsTagRemove = document.createElement('a');
                                settingsTagRemove.setAttribute('class', 'blacklistRemove');
                                settingsTagRemove.innerText = 'Remove';
                                settingsTagRemove.onclick = function () {
                                    try {
                                        tagBlacklistRemove(element);
                                        this.parentNode.remove();
                                    } catch (error) {
                                        console.log('Error removing tag', error)
                                    }
                                };
                                tagBlacklisted.appendChild(tagBlacklistedText);
                                tagBlacklisted.appendChild(settingsTagRemove);
                                return tagBlacklisted;
                            } catch (error) {
                                console.log('78', error)
                            }
                        };

                        function tagAddBlacklist() {
                            var settingsTagBox = document.createElement('div');
                            settingsTagBox.setAttribute('id', 'settingsBox');

                            var settingsTagsInput = document.createElement('input');
                            settingsTagsInput.setAttribute("type", "text");
                            settingsTagsInput.setAttribute("class", "settingsInput");
                            settingsTagsInput.setAttribute("placeholder", "Input tag here.");

                            var settingsTagsAdd = document.createElement('input');
                            settingsTagsAdd.setAttribute("type", "button");
                            settingsTagsAdd.style.height = '30px';
                            settingsTagsAdd.value = 'Add Tag';
                            settingsTagsAdd.onclick = function () {
                                if (settings.tagBlacklist.includes(this.parentNode.childNodes[0].value)) {
                                    return;
                                }
                                settings.tagBlacklist.push(this.parentNode.childNodes[0].value);
                                this.parentNode.parentNode.appendChild(tagBlacklisted(this.parentNode.childNodes[0].value));
                                this.parentNode.childNodes[0].value = "";
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                settings = JSON.parse(localStorage.getItem('FL_Settings'));
                                removeBlacklisted();
                            };

                            settingsTagBox.appendChild(settingsTagsInput);
                            settingsTagBox.appendChild(settingsTagsAdd);

                            return settingsTagBox
                        };

                        var settingsTagsBlacklist = document.createElement('div');
                        settingsTagsBlacklist.setAttribute('id', 'settingsBlacklist');
                        settings.tagBlacklist = [...new Set(settings.tagBlacklist)]
                        settings.tagBlacklist.sort().forEach(element => settingsTagsBlacklist.appendChild(tagBlacklisted(element)));

                        var settingsTagsBlacklistText = document.createElement('div');
                        settingsTagsBlacklistText.innerText = 'Tags Blacklist';
                        settingsTagsBlacklistText.setAttribute('class', 'entryTitle');
                        settingsTagsBlacklist.prepend(tagAddBlacklist());
                        settingsTagsBlacklist.prepend(settingsTagsBlacklistText);

                        settingsTab.appendChild(settingsTagsBlacklist)
                        return settingsTab;
                    };

                    function settingsBlacklist() {
                        var settingsTab = document.createElement('div');
                        settingsTab.setAttribute('class', 'settingsTab');
                        settingsTab.setAttribute('name', 'Alerts');
                        var settingsAlertBox = document.createElement('div');
                        settingsAlertBox.setAttribute('id', 'settingsAlertBox');
                        settingsAlertBox.style.marginBottom = '5px';

                        var settingsAlertAdd = document.createElement('input');
                        settingsAlertAdd.setAttribute("type", "button");
                        settingsAlertAdd.style.height = '30px';
                        settingsAlertAdd.value = 'Blacklist Current Quest';
                        settingsAlertAdd.onclick = function () {
                            try {
                                let author = document.querySelector('span.author span.name').innerText;
                                let title = document.querySelector('header.page-title').innerText;
                                let entry = title + '___' + author;
                                settings.alertBlacklist.push(entry);
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                settingsBlacklist.appendChild(elementBlacklisted(entry));

                            } catch (error) {
                                console.log('Something went wrong when trying to blacklist this quest.', error);
                            }
                        };

                        var settingsBlacklist = document.createElement('div');
                        settingsBlacklist.setAttribute('id', 'settingsBlacklist');
                        settings.alertBlacklist = [...new Set(settings.alertBlacklist)]
                        settings.alertBlacklist.forEach(element => settingsBlacklist.appendChild(elementBlacklisted(element)));

                        var settingsBlacklistText = document.createElement('div');
                        settingsBlacklistText.innerText = 'Alert Blacklist';
                        settingsBlacklistText.setAttribute('class', 'entryTitle');

                        var settingsSearchBox = document.createElement('div');
                        settingsSearchBox.setAttribute('id', 'settingsBox');

                        var settingsAlertSearchInput = document.createElement('input');
                        settingsAlertSearchInput.setAttribute("type", "text");
                        settingsAlertSearchInput.setAttribute("class", "settingsInput");
                        settingsAlertSearchInput.setAttribute("name", "alertSearch");
                        settingsAlertSearchInput.setAttribute("placeholder", "Enter a title or QM to search.");

                        var settingsAlertSearch = document.createElement('input');
                        settingsAlertSearch.setAttribute("type", "button");
                        settingsAlertSearch.style.height = '30px';
                        settingsAlertSearch.value = 'Search';
                        settingsAlertSearch.onclick = function () {
                            this.closest('#settingsBlacklist').querySelectorAll('.blacklistEntry').forEach(x => {
                                x.style.display = 'initial';
                            })
                            let search = this.parentNode.querySelector('[name="alertSearch"]').value.toLowerCase();
                            let xx = this.closest('#settingsBlacklist').querySelectorAll('.blacklistEntry');
                            xx.forEach(x => {
                                let text = x.firstChild.textContent.toLowerCase().replace('author:')
                                if (!text.includes(search)) {
                                    x.style.display = 'none';
                                } else {}
                            })
                        }

                        var settingsAlertSearchClear = document.createElement('input');
                        settingsAlertSearchClear.setAttribute("type", "button");
                        settingsAlertSearchClear.style.height = '30px';
                        settingsAlertSearchClear.value = 'Clear Search';
                        settingsAlertSearchClear.onclick = function () {
                            this.parentNode.querySelector('[name="alertSearch"]').value = '';
                            this.closest('#settingsBlacklist').querySelectorAll('.blacklistEntry').forEach(x => {
                                x.style.display = 'initial';
                            })

                        }

                        settingsSearchBox.appendChild(settingsAlertSearchInput);
                        settingsSearchBox.appendChild(settingsAlertSearch);
                        settingsSearchBox.appendChild(settingsAlertSearchClear);
                        settingsAlertBox.appendChild(settingsSearchBox);
                        settingsAlertBox.appendChild(settingsAlertAdd);
                        settingsBlacklist.prepend(settingsAlertBox);
                        settingsBlacklist.prepend(settingsBlacklistText);
                        settingsTab.appendChild(settingsBlacklist)
                        return settingsTab;
                    };


                    function settingsStyle() {
                        function genStyle(styleAttribute, styleText) {
                            var settingsStyleEntryText = document.createElement('p');
                            settingsStyleEntryText.setAttribute('class', 'styleTitle');
                            settingsStyleEntryText.innerText = styleText;

                            var settingsStylePicker = document.createElement('input');
                            settingsStylePicker.setAttribute('class', 'colorPick');
                            settingsStylePicker.setAttribute('type', 'color');
                            settingsStylePicker.onchange = function () {
                                this.parentNode.querySelector('.colorSet').value = this.value
                            };

                            var settingsStyleInput = document.createElement('input');
                            settingsStyleInput.setAttribute('class', 'colorSet');
                            settingsStyleInput.setAttribute('type', 'text');

                            if ([styleAttribute]in settings.customCSS[0]) {
                                settingsStyleInput.value = settings.customCSS[0][styleAttribute]
                                settingsStylePicker.value = settings.customCSS[0][styleAttribute]
                            };

                            var settingsStyleEntry = document.createElement('div');
                            settingsStyleEntry.setAttribute('class', 'styleEntry');
                            settingsStyleEntry.setAttribute('name', styleAttribute);
                            settingsStyleEntry.appendChild(settingsStyleEntryText);
                            settingsStyleEntry.appendChild(settingsStyleInput);
                            settingsStyleEntry.appendChild(settingsStylePicker);

                            return settingsStyleEntry;
                        };

                        var settingsStyle = document.createElement('div');
                        settingsStyle.setAttribute('class', 'settingsTab');
                        settingsStyle.setAttribute('name', 'Site Style');

                        var settingsStyleText = document.createElement('div');
                        settingsStyleText.setAttribute('class', 'entryTitle');
                        settingsStyleText.innerText = 'Custom Site Style - Beta';

                        var settingsStyleTextBox = new genStyle('color', 'Text Color');
                        var settingsStyleBackgroundBox = new genStyle('background', 'Background Color');

                        var settingsStyleSave = document.createElement('input');
                        settingsStyleSave.setAttribute("type", "button");
                        settingsStyleSave.setAttribute('class', 'cssBtn');
                        settingsStyleSave.style.height = '30px';
                        settingsStyleSave.onclick = function () {
                            try{
                                try{
                                    document.querySelectorAll('.styleEntry').forEach(
                                        x => {
                                            let name = x.getAttribute("name");
                                            let value = x.querySelector('.colorSet').value;
                                            if (value !== undefined) {
                                                settings.customCSS[0][name] = value;
                                            }
                                        });
                                }catch(error){}

                                try{
                                    for (var key in settings.customCSS[0]) {
                                        if (settings.customCSS[0].hasOwnProperty(key)) {
                                            console.log(key, settings.customCSS[0][key]);
                                        }
                                    }
                                }catch(error){}

                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                let styleS = `*{color:${settings.customCSS[0].color}!important;background:${settings.customCSS[0].background} !important;}`;

                                let style = document.createElement('style');
                                style.setAttribute("name", "styleSheet");
                                if (document.querySelector('[name="styleSheet"]')) {
                                    document.querySelector('[name="styleSheet"]').remove();
                                    style.appendChild(document.createTextNode(styleS));
                                } else {
                                    style.appendChild(document.createTextNode(styleS));
                                }
                                document.getElementsByTagName('head')[0].appendChild(style);
                            }catch(error){}
                        };
                        settingsStyleSave.value = 'Apply Styling';

                        var settingsStyleToggle = document.createElement('input');
                        settingsStyleToggle.setAttribute("type", "button");
                        settingsStyleToggle.setAttribute('class', 'cssBtn');
                        settingsStyleToggle.value = 'Toggle CSS Input';
                        settingsStyleToggle.style.height = '30px';
                        settingsStyleToggle.onclick = function () {
                            let styleInput = document.querySelector('#styleInput');
                            let styleSaveCSS = document.querySelector('#styleSaveCSS');
                            if (styleInput.style.display != 'none') {
                                styleInput.style.display = 'none';
                                styleSaveCSS.style.display = 'none';
                            } else {
                                styleInput.style.display = 'initial';
                                styleSaveCSS.style.display = 'initial';
                            }
                        };

                        var settingsStyleBoxSave = document.createElement('input');
                        settingsStyleBoxSave.setAttribute("type", "button");
                        settingsStyleBoxSave.setAttribute('id', 'styleSaveCSS');
                        settingsStyleBoxSave.setAttribute('class', 'cssBtn');
                        settingsStyleBoxSave.value = 'Save CSS Input';
                        settingsStyleBoxSave.style.display = 'none';
                        settingsStyleBoxSave.style.height = '30px';
                        settingsStyleBoxSave.onclick = function () {
                            let styleS = document.querySelector('#styleInput').value
                            if (styleS !== undefined) {
                                settings.customCSS[1] = styleS;
                            }
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));

                            let style = document.createElement('style');
                            style.setAttribute("name", "styleSheet");
                            if (document.querySelector('[name="styleSheet"]')) {
                                document.querySelector('[name="styleSheet"]').remove();
                                style.appendChild(document.createTextNode(styleS));
                            } else {
                                style.appendChild(document.createTextNode(styleS));
                            }
                            document.getElementsByTagName('head')[0].appendChild(style);
                        };

                        var settingsStyleClear = document.createElement('input');
                        settingsStyleClear.setAttribute("type", "button");
                        settingsStyleClear.setAttribute('class', 'cssBtn');
                        settingsStyleClear.value = 'Reset Style Settings';
                        settingsStyleClear.style.height = '30px';
                        settingsStyleClear.onclick = function () {
                            try{
                                document.querySelector('[name="styleSheet"]').remove();
                                document.querySelectorAll('.colorPick').forEach(x => {
                                    x.value = ''
                                });
                                document.querySelectorAll('.colorSet').forEach(x => {
                                    x.value = ''
                                });
                                document.querySelector('#styleInput').value = '';
                                settings.customCSS = [{}, ``];
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            }catch(error){}
                        };

                        var settingsStyleBox = document.createElement('textarea');
                        settingsStyleBox.setAttribute('id', 'styleInput');
                        settingsStyleBox.setAttribute('placeholder', 'Add any more complicated CSS here.');
                        settingsStyleBox.setAttribute("cols", "50");
                        settingsStyleBox.setAttribute("rows", "5");
                        settingsStyleBox.style.display = 'none';
                        if (settings.customCSS[1] !== ``) {
                            settingsStyleBox.value = settings.customCSS[1];
                        }

                        var settingsStyleEntries = document.createElement('div');
                        settingsStyleEntries.setAttribute('id', 'styleEntries');
                        settingsStyleEntries.appendChild(settingsStyleTextBox);
                        settingsStyleEntries.appendChild(settingsStyleBackgroundBox);

                        settingsStyle.appendChild(settingsStyleText);
                        settingsStyle.appendChild(settingsStyleEntries);
                        settingsStyle.appendChild(settingsStyleSave);
                        settingsStyle.appendChild(settingsStyleToggle);
                        settingsStyle.appendChild(settingsStyleBoxSave);
                        settingsStyle.appendChild(settingsStyleClear);
                        settingsStyle.appendChild(settingsStyleBox);
                        try {
                            if (settings.customCSS[0] != {}) {
                                let A=''
                                let B=''
                                if (settings.customCSS[0].color != undefined){A=`color:${settings.customCSS[0].color}!important;`}
                                if (settings.customCSS[0].background != undefined){B=`background:${settings.customCSS[0].background} !important;}`}
                                var styleS = `*{${A}${B}}`;
                                if (styleS!='*{}'){
                                    var style = document.createElement('style');
                                    style.setAttribute("name", "styleSheet");
                                    if (document.querySelector('[name="styleSheet"]')) {
                                        document.querySelector('[name="styleSheet"]').remove();
                                        style.setAttribute("name", "styleSheet");
                                        style.appendChild(document.createTextNode(styleS));
                                    } else {
                                        style.appendChild(document.createTextNode(styleS));
                                    }
                                    document.getElementsByTagName('head')[0].appendChild(style);
                                }
                            };
                        } catch (error) {
                            console.log(error)
                        }

                        try {
                            if (settings.customCSS[1] != ``) {
                                var style2 = document.createElement('style');
                                var styleS2 = settings.customCSS[1]
                                if (document.querySelector('[name="styleSheet"]')) {
                                    document.querySelector('[name="styleSheet"]').remove();
                                    style2.setAttribute("name", "styleSheet");
                                    style2.appendChild(document.createTextNode(styleS2));
                                }
                                else {
                                    style2.setAttribute("name", "styleSheet");
                                    style2.appendChild(document.createTextNode(styleS2));
                                }
                                document.getElementsByTagName('head')[0].appendChild(style2);
                            }
                        } catch (error) {
                            console.log('customcss',error)
                        }

                        return settingsStyle;
                    }

                    //Toggles for features start here
                    //Toggles for features start here
                    //Toggles for features start here
                    //Toggles for features start here
                    //Toggles for features start here

                    function settingsImageResize() {
                        var settingsImageResize = document.createElement('div');
                        settingsImageResize.setAttribute('class', 'settingsToggle');

                        var settingsImageResizeText = document.createElement('div');
                        settingsImageResizeText.style.display = 'inline';
                        settingsImageResizeText.innerText = 'Resize images in chat.';

                        var settingsImageResizeCheckbox = document.createElement('input');
                        settingsImageResizeCheckbox.setAttribute("type", "checkbox");
                        settingsImageResizeCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.imageResize == true) {
                            settingsImageResizeCheckbox.checked = true;
                        };
                        settingsImageResizeCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.imageResize = true;
                            } else {
                                settings.imageResize = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsImageResize.appendChild(settingsImageResizeText);
                        settingsImageResize.appendChild(settingsImageResizeCheckbox);
                        return settingsImageResize
                    };

                    function settingsRemoveBlankTopics() {
                        var settingsRemoveBlankTopics = document.createElement('div');
                        settingsRemoveBlankTopics.setAttribute('class', 'settingsToggle');

                        var settingsRemoveBlankTopicsText = document.createElement('div');
                        settingsRemoveBlankTopicsText.style.display = 'inline';
                        settingsRemoveBlankTopicsText.innerText = 'Remove blank topics.';

                        var settingsRemoveBlankTopicsCheckbox = document.createElement('input');
                        settingsRemoveBlankTopicsCheckbox.setAttribute("type", "checkbox");
                        settingsRemoveBlankTopicsCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.removeBlankTopics == true) {
                            settingsRemoveBlankTopicsCheckbox.checked = true;
                        };

                        settingsRemoveBlankTopicsCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.removeBlankTopics = true;
                            } else {
                                settings.removeBlankTopics = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsRemoveBlankTopics.appendChild(settingsRemoveBlankTopicsText);
                        settingsRemoveBlankTopics.appendChild(settingsRemoveBlankTopicsCheckbox);
                        return settingsRemoveBlankTopics
                    };

                    function settingsFormRemove() {
                        var settingsFormRemove = document.createElement('div');
                        settingsFormRemove.setAttribute('class', 'settingsToggle');

                        var settingsFormRemoveText = document.createElement('div');
                        settingsFormRemoveText.style.display = 'inline';
                        settingsFormRemoveText.innerText = 'Remove topic submission form.';

                        var settingsFormRemoveCheckbox = document.createElement('input');
                        settingsFormRemoveCheckbox.setAttribute("type", "checkbox");
                        settingsFormRemoveCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.removeTopicForm == true) {
                            settingsFormRemoveCheckbox.checked = true;
                        };
                        settingsFormRemoveCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.removeTopicForm = true;
                            } else {
                                settings.removeTopicForm = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsFormRemove.appendChild(settingsFormRemoveText);
                        settingsFormRemove.appendChild(settingsFormRemoveCheckbox);
                        return settingsFormRemove
                    };

                    function settingsChatBlacklist() {
                        var settingsChatBlacklist = document.createElement('div');
                        settingsChatBlacklist.setAttribute('class', 'settingsToggle');

                        var settingsChatBlacklistText = document.createElement('div');
                        settingsChatBlacklistText.style.display = 'inline';
                        settingsChatBlacklistText.innerText = 'Hide blacklisted users in chat.';

                        var settingsChatBlacklistCheckbox = document.createElement('input');
                        settingsChatBlacklistCheckbox.setAttribute("type", "checkbox");
                        settingsChatBlacklistCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.chatBlacklist == true) {
                            settingsChatBlacklistCheckbox.checked = true;
                        };
                        settingsChatBlacklistCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.chatBlacklist = true;
                            } else {
                                settings.chatBlacklist = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsChatBlacklist.appendChild(settingsChatBlacklistText);
                        settingsChatBlacklist.appendChild(settingsChatBlacklistCheckbox);
                        return settingsChatBlacklist
                    };

                    function settingsAuthorBlacklist() {
                        var settingsAuthorBlacklist = document.createElement('div');
                        settingsAuthorBlacklist.setAttribute('class', 'settingsToggle')

                        var settingsAuthorBlacklistText = document.createElement('div');
                        settingsAuthorBlacklistText.style.display = 'inline';
                        settingsAuthorBlacklistText.innerText = 'Hide quests with blacklisted authors.';

                        var settingsAuthorBlacklistCheckbox = document.createElement('input');
                        settingsAuthorBlacklistCheckbox.setAttribute("type", "checkbox");
                        settingsAuthorBlacklistCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.questAuthorRemove == true) {
                            settingsAuthorBlacklistCheckbox.checked = true;
                        };
                        settingsAuthorBlacklistCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.questAuthorRemove = true;
                            } else {
                                settings.questAuthorRemove = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsAuthorBlacklist.appendChild(settingsAuthorBlacklistText);
                        settingsAuthorBlacklist.appendChild(settingsAuthorBlacklistCheckbox);
                        return settingsAuthorBlacklist
                    };

                    function settingsTagBlacklist() {
                        var settingsTagBlacklist = document.createElement('div');
                        settingsTagBlacklist.setAttribute("class", "settingsToggle");

                        var settingsTagBlacklistText = document.createElement('div');
                        settingsTagBlacklistText.style.display = 'inline';
                        settingsTagBlacklistText.innerText = 'Hide quests with blacklisted tags.';

                        var settingsTagBlacklistCheckbox = document.createElement('input');
                        settingsTagBlacklistCheckbox.setAttribute("type", "checkbox");
                        settingsTagBlacklistCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.questRemove == true) {
                            settingsTagBlacklistCheckbox.checked = true;
                        };
                        settingsTagBlacklistCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.questRemove = true;
                            } else {
                                settings.questRemove = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsTagBlacklist.appendChild(settingsTagBlacklistText);
                        settingsTagBlacklist.appendChild(settingsTagBlacklistCheckbox);
                        return settingsTagBlacklist
                    };

                    function settingsNamefagToggle() {

                        var settingsNamefagToggle = document.createElement('div');
                        settingsNamefagToggle.setAttribute('class', 'settingsToggle');

                        var settingsNamefagToggleText = document.createElement('div');
                        settingsNamefagToggleText.style.display = 'inline';
                        settingsNamefagToggleText.innerText = 'Make everyone Anon.';

                        var settingsNamefagToggleCheckbox = document.createElement('input');
                        settingsNamefagToggleCheckbox.setAttribute("type", "checkbox");
                        settingsNamefagToggleCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.removeUsernames == true) {
                            settingsNamefagToggleCheckbox.checked = true;
                        };
                        settingsNamefagToggleCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.removeUsernames = true;
                                try{
                                    let authorList = document.querySelectorAll('span.author.ng-scope');
                                    let authors = []
                                    authorList.forEach(element => authors.push(element.querySelector('span.name').innerText))
                                    let names = document.querySelectorAll('div.user span.name')
                                    names.forEach(name => {
                                        let txt = name.innerText;
                                        if (!authors.includes(txt)){
                                            name.innerText = 'anon';
                                        }
                                    })
                                }catch(error){console.log('anonForce',error)}
                            } else {
                                settings.removeUsernames = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsNamefagToggle.appendChild(settingsNamefagToggleText);
                        settingsNamefagToggle.appendChild(settingsNamefagToggleCheckbox);
                        return settingsNamefagToggle
                    };

                    function settingsRollerToggle() {
                        var settingsRollerToggle = document.createElement('div');
                        settingsRollerToggle.setAttribute('class', 'settingsToggle');

                        var settingsRollerToggleText = document.createElement('div');
                        settingsRollerToggleText.style.display = 'inline';
                        settingsRollerToggleText.innerText = 'Toggle Auto Roller.';

                        var settingsRollerToggleCheckbox = document.createElement('input');
                        settingsRollerToggleCheckbox.setAttribute("type", "checkbox");
                        settingsRollerToggleCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.autoRoller == true) {
                            settingsRollerToggleCheckbox.checked = true;
                        };
                        settingsRollerToggleCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.autoRoller = true;
                            } else {
                                settings.autoRoller = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsRollerToggle.appendChild(settingsRollerToggleText);
                        settingsRollerToggle.appendChild(settingsRollerToggleCheckbox);
                        return settingsRollerToggle
                    };

                    function settingsAnonToggle() {
                        function toggleAnonStatus() {
                            var x = 1
                            try {
                                try {
                                    var username = localStorage.getItem('username');
                                    var refURL = "https://fiction.live/user/" + username;
                                    var profile = window.ty.currentUser.profile;
                                    profile.asAnon = settings.anonToggle;
                                } catch (error) {
                                    console.log('Toggle Anon Prep', error);
                                    x = 2;
                                };
                                if (x = 1) {
                                    fetch("https://fiction.live/api/user", {
                                        "credentials": "include",
                                        "headers": {
                                            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
                                            "Accept": "application/json, text/javascript, */*; q=0.01",
                                            "Accept-Language": "en-GB,en;q=0.5",
                                            "Content-Type": "application/json",
                                            "X-Requested-With": "XMLHttpRequest"
                                        },
                                        "referrer": refURL,
                                        "body": JSON.stringify(profile),
                                        "method": "PUT",
                                        "mode": "cors"
                                    });
                                };
                            } catch (error) {
                                console.log('Toggle Anon Set', error);
                            };
                        };

                        var settingsAnonToggle = document.createElement('div');
                        settingsAnonToggle.setAttribute('class', 'settingsToggle');

                        var settingsAnonToggleText = document.createElement('div');
                        settingsAnonToggleText.style.display = 'inline';
                        settingsAnonToggleText.innerText = 'Toggle Anon status.';

                        var settingsAnonToggleCheckbox = document.createElement('input');
                        settingsAnonToggleCheckbox.setAttribute("type", "checkbox");
                        settingsAnonToggleCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.anonToggle == true) {
                            settingsAnonToggleCheckbox.checked = true;
                        };
                        settingsAnonToggleCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.anonToggle = true;
                                toggleAnonStatus();
                            } else {
                                settings.anonToggle = false;
                                toggleAnonStatus();
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsAnonToggle.appendChild(settingsAnonToggleText);
                        settingsAnonToggle.appendChild(settingsAnonToggleCheckbox);
                        return settingsAnonToggle
                    };

                    function settingsLiveRestore() {
                        var settingsLiveRestore = document.createElement('div');
                        settingsLiveRestore.setAttribute('class', 'settingsToggle');

                        var settingsLiveRestoreText = document.createElement('div');
                        settingsLiveRestoreText.style.display = 'inline';
                        settingsLiveRestoreText.innerText = 'Restore live timer to nav bar.';

                        var settingsLiveRestoreCheckbox = document.createElement('input');
                        settingsLiveRestoreCheckbox.setAttribute("type", "checkbox");
                        settingsLiveRestoreCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.liveRestore == true) {
                            settingsLiveRestoreCheckbox.checked = true;
                        };
                        settingsLiveRestoreCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.liveRestore = true;
                                let canvas = document.querySelector('header[class="next-live ng-scope"]');
                                if (canvas){
                                    liveRestore()
                                }
                            } else {
                                settings.liveRestore = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsLiveRestore.appendChild(settingsLiveRestoreText);
                        settingsLiveRestore.appendChild(settingsLiveRestoreCheckbox);
                        return settingsLiveRestore
                    };

                    function settingsLiveLight() {
                        var settingsLiveLight = document.createElement('div');
                        settingsLiveLight.setAttribute('class', 'settingsToggle');

                        var settingsLiveLightText = document.createElement('div');
                        settingsLiveLightText.style.display = 'inline';
                        settingsLiveLightText.innerText = 'Light mode live timer.';

                        var settingsLiveLightCheckbox = document.createElement('input');
                        settingsLiveLightCheckbox.setAttribute("type", "checkbox");
                        settingsLiveLightCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.liveLight == true) {
                            settingsLiveLightCheckbox.checked = true;
                        };
                        settingsLiveLightCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.liveLight = true;
                            } else {
                                settings.liveLight = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsLiveLight.appendChild(settingsLiveLightText);
                        settingsLiveLight.appendChild(settingsLiveLightCheckbox);
                        return settingsLiveLight
                    };

                    function settingsAuthorHighlight() {
                        var settingsAuthorHighlight = document.createElement('div');
                        settingsAuthorHighlight.setAttribute('class', 'settingsToggle');

                        var settingsAuthorHighlightText = document.createElement('div');
                        settingsAuthorHighlightText.style.display = 'inline';
                        settingsAuthorHighlightText.innerText = 'Highlight author(s) in chat.';

                        var settingsAuthorHighlightCheckbox = document.createElement('input');
                        settingsAuthorHighlightCheckbox.setAttribute("type", "checkbox");
                        settingsAuthorHighlightCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.authorHighlight == true) {
                            settingsAuthorHighlightCheckbox.checked = true;
                        };
                        settingsAuthorHighlightCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.authorHighlight = true;
                                try{
                                    let authorList = document.querySelectorAll('span.author.ng-scope');
                                    let authors = []
                                    authorList.forEach(element => authors.push(element.querySelector('span.name').innerText))
                                    var currentColor = settings.highlightColor;
                                    if (settings.highlightLightToggle == true) {
                                        currentColor = settings.highlightLight;
                                    }
                                    document.querySelectorAll('div.user span.name').forEach(name => {
                                        if (authors.includes(name.innerText)){
                                            name.closest('.logItem').style.background = currentColor
                                        }
                                    })
                                }catch(error){}
                            } else {
                                settings.authorHighlight = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsAuthorHighlight.appendChild(settingsAuthorHighlightText);
                        settingsAuthorHighlight.appendChild(settingsAuthorHighlightCheckbox);
                        return settingsAuthorHighlight
                    };

                    function settingsLightHighlight() {
                        var settingsLightHighlight = document.createElement('div');
                        settingsLightHighlight.setAttribute('class', 'settingsToggle');

                        var settingsLightHighlightText = document.createElement('div');
                        settingsLightHighlightText.style.display = 'inline';
                        settingsLightHighlightText.innerText = 'Light mode highlighting.';

                        var settingsLightHighlightCheckbox = document.createElement('input');
                        settingsLightHighlightCheckbox.setAttribute("type", "checkbox");
                        settingsLightHighlightCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.highlightLightToggle == true) {
                            settingsLightHighlightCheckbox.checked = true;
                        };
                        settingsLightHighlightCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.highlightLightToggle = true;
                                try{
                                    let authorList = document.querySelectorAll('span.author.ng-scope');
                                    let authors = []
                                    authorList.forEach(element => authors.push(element.querySelector('span.name').innerText))
                                    var currentColor = settings.highlightColor;
                                    if (settings.highlightLightToggle == true) {
                                        currentColor = settings.highlightLight;
                                    }
                                    document.querySelectorAll('div.user span.name').forEach(name => {
                                        if (authors.includes(name.innerText)){
                                            name.closest('.logItem').style.background = currentColor
                                        }
                                    })
                                }catch(error){}
                            } else {
                                settings.highlightLightToggle = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsLightHighlight.appendChild(settingsLightHighlightText);
                        settingsLightHighlight.appendChild(settingsLightHighlightCheckbox);
                        return settingsLightHighlight
                    };

                    function settingsTaggedAuthor() {
                        var settingsTaggedAuthor = document.createElement('div');
                        settingsTaggedAuthor.setAttribute('class', 'settingsToggle');

                        var settingsTaggedAuthorText = document.createElement('div');
                        settingsTaggedAuthorText.style.display = 'inline';
                        settingsTaggedAuthorText.innerText = 'Hide tagged on author pages.';

                        var settingsTaggedAuthorCheckbox = document.createElement('input');
                        settingsTaggedAuthorCheckbox.setAttribute("type", "checkbox");
                        settingsTaggedAuthorCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.removeTaggedAuthor == true) {
                            settingsTaggedAuthorCheckbox.checked = true;
                        };
                        settingsTaggedAuthorCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.removeTaggedAuthor = true;
                            } else {
                                settings.removeTaggedAuthor = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsTaggedAuthor.appendChild(settingsTaggedAuthorText);
                        settingsTaggedAuthor.appendChild(settingsTaggedAuthorCheckbox);
                        return settingsTaggedAuthor
                    };

                    function settingsFunctionalLinks() {
                        var settingsFunctionalLinks = document.createElement('div');
                        settingsFunctionalLinks.setAttribute('class', 'settingsToggle');

                        var settingsFunctionalLinksText = document.createElement('div');
                        settingsFunctionalLinksText.style.display = 'inline';
                        settingsFunctionalLinksText.innerText = 'Make text links functional.';

                        var settingsFunctionalLinksCheckbox = document.createElement('input');
                        settingsFunctionalLinksCheckbox.setAttribute("type", "checkbox");
                        settingsFunctionalLinksCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.functionalLinks == true) {
                            settingsFunctionalLinksCheckbox.checked = true;
                        };
                        settingsFunctionalLinksCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.functionalLinks = true;
                            } else {
                                settings.functionalLinks = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsFunctionalLinks.appendChild(settingsFunctionalLinksText);
                        settingsFunctionalLinks.appendChild(settingsFunctionalLinksCheckbox);
                        return settingsFunctionalLinks
                    };

                    function settingsFunctionalVideos() {
                        var settingsFunctionalVideos = document.createElement('div');
                        settingsFunctionalVideos.setAttribute('class', 'settingsToggle');

                        var settingsFunctionalVideosText = document.createElement('div');
                        settingsFunctionalVideosText.style.display = 'inline';
                        settingsFunctionalVideosText.innerText = 'Make video links functional.';

                        var settingsFunctionalVideosCheckbox = document.createElement('input');
                        settingsFunctionalVideosCheckbox.setAttribute("type", "checkbox");
                        settingsFunctionalVideosCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.functionalVideos == true) {
                            settingsFunctionalVideosCheckbox.checked = true;
                        };
                        settingsFunctionalVideosCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.functionalVideos = true;
                            } else {
                                settings.functionalVideos = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsFunctionalVideos.appendChild(settingsFunctionalVideosText);
                        settingsFunctionalVideos.appendChild(settingsFunctionalVideosCheckbox);
                        return settingsFunctionalVideos
                    };

                    function settingsNSFWToggle() {
                        var settingsNSFWToggle = document.createElement('div');
                        settingsNSFWToggle.setAttribute('class', 'settingsToggle');

                        var settingsNSFWToggleText = document.createElement('div');
                        settingsNSFWToggleText.style.display = 'inline';
                        settingsNSFWToggleText.innerText = 'Remove NSFW covers from quests.';

                        var settingsNSFWToggleCheckbox = document.createElement('input');
                        settingsNSFWToggleCheckbox.setAttribute("type", "checkbox");
                        settingsNSFWToggleCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.removeNSFW == true) {
                            settingsNSFWToggleCheckbox.checked = true;
                        };
                        settingsNSFWToggleCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.removeNSFW = true;
                                removeNSFW();
                            } else {
                                settings.removeNSFW = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsNSFWToggle.appendChild(settingsNSFWToggleText);
                        settingsNSFWToggle.appendChild(settingsNSFWToggleCheckbox);
                        return settingsNSFWToggle
                    };

                    function settingsUpdateRequestDismissToggle() {
                        var settingsUpdateRequestDismissToggle = document.createElement('div');
                        settingsUpdateRequestDismissToggle.setAttribute('class', 'settingsToggle');

                        var settingsUpdateRequestText = document.createElement('div');
                        settingsUpdateRequestText.style.display = 'inline';
                        settingsUpdateRequestText.innerText = 'Auto dismiss update requests.';

                        var settingsUpdateRequestDismissToggleCheckbox = document.createElement('input');
                        settingsUpdateRequestDismissToggleCheckbox.setAttribute("type", "checkbox");
                        settingsUpdateRequestDismissToggleCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.updateRequestDismiss == true) {
                            settingsUpdateRequestDismissToggleCheckbox.checked = true;
                        };
                        settingsUpdateRequestDismissToggleCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.updateRequestDismiss = true;
                                let alertContainer = document.querySelectorAll('li.feedItem');
                                alertContainer.forEach(alert => {
                                    if (/.*Looks forward to the next update for.*/.test(alert.innerText)) {
                                        alertUpdate(alert)
                                    }
                                });
                            } else {
                                settings.updateRequestDismiss = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsUpdateRequestDismissToggle.appendChild(settingsUpdateRequestText);
                        settingsUpdateRequestDismissToggle.appendChild(settingsUpdateRequestDismissToggleCheckbox);
                        return settingsUpdateRequestDismissToggle
                    };

                    function settingsAkunPlusToggle() {
                        var settingsAkunPlusToggle = document.createElement('div');
                        settingsAkunPlusToggle.setAttribute('class', 'settingsToggle');

                        var settingsAkunPlusToggleText = document.createElement('div');
                        settingsAkunPlusToggleText.style.display = 'inline';

                        var settingsAkunPlusToggleBtn = document.createElement('input');
                        settingsAkunPlusToggleBtn.style.marginLeft = '10px';
                        settingsAkunPlusToggleBtn.setAttribute("type", "button");
                        settingsAkunPlusToggleBtn.setAttribute("class", "toggleBtn");

                        if (settings.akunPlus == 'Ignore') {
                            settingsAkunPlusToggleText.innerText = '(Chat) Ignore Akun Premium';
                            settingsAkunPlusToggleBtn.value = 'Remove';
                        } else if (settings.akunPlus == 'Remove') {
                            settingsAkunPlusToggleText.innerText = '(Chat) Remove Akun Premium';
                            settingsAkunPlusToggleBtn.value = 'Global';
                        } else {
                            settingsAkunPlusToggleText.innerText = '(Chat) Global Akun Premium';
                            settingsAkunPlusToggleBtn.value = 'Ignore';
                        };
                        settingsAkunPlusToggleBtn.onclick = function () {
                            try {
                                if (settings.akunPlus == 'Ignore') {
                                    this.parentNode.childNodes[0].innerText = '(Chat) Remove Akun Premium';
                                    this.value = 'Global';
                                    settings.akunPlus = 'Remove';
                                } else if (settings.akunPlus == 'Remove') {
                                    this.parentNode.childNodes[0].innerText = '(Chat) Global Akun Premium';
                                    this.value = 'Ignore';
                                    settings.akunPlus = 'Global';
                                } else {
                                    this.parentNode.childNodes[0].innerText = '(Chat) Ignore Akun Premium';
                                    this.value = 'Remove';
                                    settings.akunPlus = 'Ignore';
                                };
                                localStorage.setItem('FL_Settings', JSON.stringify(settings));
                                settings = JSON.parse(localStorage.getItem('FL_Settings'));
                            } catch (error) {
                                console.log('Error changin akunPlus', error);
                            };
                        };
                        settingsAkunPlusToggle.appendChild(settingsAkunPlusToggleText);
                        settingsAkunPlusToggle.appendChild(settingsAkunPlusToggleBtn);
                        return settingsAkunPlusToggle
                    };

                    function settingsChatBlacklistRepliesToggle() {
                        var settingsChatBlacklistReplies = document.createElement('div');
                        settingsChatBlacklistReplies.setAttribute('class', 'settingsToggle');

                        var settingsChatBlacklistRepliesText = document.createElement('div');
                        settingsChatBlacklistRepliesText.style.display = 'inline';
                        settingsChatBlacklistRepliesText.innerText = 'Remove replies to blacklisted users.';

                        var settingsChatBlacklistRepliesCheckbox = document.createElement('input');
                        settingsChatBlacklistRepliesCheckbox.setAttribute("type", "checkbox");
                        settingsChatBlacklistRepliesCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.chatBlacklistReplies == true) {
                            settingsChatBlacklistRepliesCheckbox.checked = true;
                        };

                        settingsChatBlacklistRepliesCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.chatBlacklistReplies = true;
                            } else {
                                settings.chatBlacklistReplies = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsChatBlacklistReplies.appendChild(settingsChatBlacklistRepliesText);
                        settingsChatBlacklistReplies.appendChild(settingsChatBlacklistRepliesCheckbox);
                        return settingsChatBlacklistReplies
                    };

                    function settingsSortAlerts() {
                        var settingsSortAlerts = document.createElement('div');
                        settingsSortAlerts.setAttribute('class', 'settingsToggle');

                        var settingsSortAlertsText = document.createElement('div');
                        settingsSortAlertsText.style.display = 'inline';
                        settingsSortAlertsText.innerText = 'Sort alerts by author name.';

                        var settingsSortAlertsCheckbox = document.createElement('input');
                        settingsSortAlertsCheckbox.setAttribute("type", "checkbox");
                        settingsSortAlertsCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.sortAlerts == true) {
                            settingsSortAlertsCheckbox.checked = true;
                            //sortAlerts();
                        };

                        settingsSortAlertsCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.sortAlerts = true;
                                sortAlerts();
                            } else {
                                settings.sortAlerts = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsSortAlerts.appendChild(settingsSortAlertsText);
                        settingsSortAlerts.appendChild(settingsSortAlertsCheckbox);
                        return settingsSortAlerts
                    };

                    function settingsUnpublishToggle() {
                        var settingsUnpublishToggle = document.createElement('div');
                        settingsUnpublishToggle.setAttribute('class', 'settingsToggle');

                        var settingsUnpublishToggleText = document.createElement('div');
                        settingsUnpublishToggleText.style.display = 'inline';
                        settingsUnpublishToggleText.innerText = 'Add delete button to your messages.';

                        var settingsUnpublishToggleCheckbox = document.createElement('input');
                        settingsUnpublishToggleCheckbox.setAttribute("type", "checkbox");
                        settingsUnpublishToggleCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.unpublishBTN == true) {
                            settingsUnpublishToggleCheckbox.checked = true;
                        };

                        settingsUnpublishToggleCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.unpublishBTN = true;
                                sortAlerts();
                            } else {
                                settings.unpublishBTN = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsUnpublishToggle.appendChild(settingsUnpublishToggleText);
                        settingsUnpublishToggle.appendChild(settingsUnpublishToggleCheckbox);
                        return settingsUnpublishToggle
                    };

                    function settingsAnonRevealToggle() {
                        var settingsAnonRevealToggle = document.createElement('div');
                        settingsAnonRevealToggle.setAttribute('class', 'settingsToggle');

                        var settingsAnonRevealToggleText = document.createElement('div');
                        settingsAnonRevealToggleText.style.display = 'inline';
                        settingsAnonRevealToggleText.innerText = 'Attempt to reveal anon usernames in chat.';

                        var settingsAnonRevealToggleCheckbox = document.createElement('input');
                        settingsAnonRevealToggleCheckbox.setAttribute("type", "checkbox");
                        settingsAnonRevealToggleCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.userReveal == true) {
                            settingsAnonRevealToggleCheckbox.checked = true;
                            //sortAlerts();
                        };

                        settingsAnonRevealToggleCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.userReveal = true;
                                sortAlerts();
                            } else {
                                settings.userReveal = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsAnonRevealToggle.appendChild(settingsAnonRevealToggleText);
                        settingsAnonRevealToggle.appendChild(settingsAnonRevealToggleCheckbox);
                        return settingsAnonRevealToggle
                    };

                    function settingsMsgEditToggle() {
                        var settingsToggle = document.createElement('div');
                        settingsToggle.setAttribute('class', 'settingsToggle');

                        var settingsText = document.createElement('div');
                        settingsText.style.display = 'inline';
                        settingsText.innerText = 'Allow message editing in chat.';

                        var settingsCheckbox = document.createElement('input');
                        settingsCheckbox.setAttribute("type", "checkbox");
                        settingsCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.messageEdit == true) {
                            settingsCheckbox.checked = true;
                        };

                        settingsCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.messageEdit = true;
                            } else {
                                settings.messageEdit = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsToggle.appendChild(settingsText);
                        settingsToggle.appendChild(settingsCheckbox);
                        return settingsToggle
                    };

                    //Toggle Template
                    function settingsToggle() {
                        var settingsToggle = document.createElement('div');
                        settingsToggle.setAttribute('class', 'settingsToggle');

                        var settingsText = document.createElement('div');
                        settingsText.style.display = 'inline';
                        settingsText.innerText = 'WhatItDo?';

                        var settingsCheckbox = document.createElement('input');
                        settingsCheckbox.setAttribute("type", "checkbox");
                        settingsCheckbox.setAttribute("class", "toggleCheck");
                        if (settings.setting == true) {
                            settingsCheckbox.checked = true;
                            //sortAlerts();
                        };

                        settingsCheckbox.addEventListener('change', (event) => {
                            if (event.target.checked) {
                                settings.setting = true;
                            } else {
                                settings.setting = false;
                            };
                            localStorage.setItem('FL_Settings', JSON.stringify(settings));
                            settings = JSON.parse(localStorage.getItem('FL_Settings'));
                        });
                        settingsToggle.appendChild(settingsText);
                        settingsToggle.appendChild(settingsCheckbox);
                        return settingsToggle
                    };

                    function settingsActual() {
                        var settingsActual = document.createElement('div');
                        settingsActual.setAttribute('class', 'settingsTab');
                        settingsActual.setAttribute('name', 'General');
                        settingsActual.style.display = 'initial';

                        var settingsActualText = document.createElement('div');
                        settingsActualText.innerText = 'General Script Settings';
                        settingsActualText.setAttribute('class', 'entryTitle');



                        var settingsText = document.createElement('div');
                        settingsText.innerText = 'Chat Settings';
                        settingsText.setAttribute('class', 'entryTitle');
                        settingsText.style.fontSize = '18px'
                        settingsText.style.float = 'left'
                        settingsText.style.marginTop = '0.5em'

                        //Settings Checkboxes
                        settingsActual.appendChild(settingsUpdateRequestDismissToggle());
                        //settingsActual.appendChild(settingsSortAlerts());
                        settingsActual.appendChild(settingsNSFWToggle());
                        settingsActual.appendChild(settingsLiveRestore());
                        settingsActual.appendChild(settingsLiveLight());
                        settingsActual.appendChild(settingsRemoveBlankTopics());
                        settingsActual.appendChild(settingsFormRemove());
                        settingsActual.appendChild(settingsTagBlacklist());
                        settingsActual.appendChild(settingsTaggedAuthor());
                        settingsActual.appendChild(settingsAuthorBlacklist());
                        settingsActual.appendChild(settingsText);

                        settingsActual.appendChild(settingsAnonToggle());
                        settingsActual.appendChild(settingsRollerToggle());
                        settingsActual.appendChild(settingsAuthorHighlight());
                        settingsActual.appendChild(settingsLightHighlight());
                        settingsActual.appendChild(settingsNamefagToggle());
                        settingsActual.appendChild(settingsAnonRevealToggle());
                        settingsActual.appendChild(settingsUnpublishToggle());
                        settingsActual.appendChild(settingsChatBlacklist());
                        settingsActual.appendChild(settingsChatBlacklistRepliesToggle());
                        settingsActual.appendChild(settingsAkunPlusToggle());
                        settingsActual.appendChild(settingsImageResize());
                        settingsActual.appendChild(settingsFunctionalLinks());
                        settingsActual.appendChild(settingsFunctionalVideos());
                        settingsActual.appendChild(settingsMsgEditToggle());

                        settingsActual.prepend(settingsActualText);

                        return settingsActual
                    }

                    var settingsTop = document.createElement('div');
                    settingsTop.setAttribute('id', 'scriptTitle');
                    var settingsTopText = document.createElement('h1');
                    settingsTopText.innerText = 'Script Config';
                    settingsTopText.style.margin = '0';
                    settingsTop.appendChild(settingsTopText)

                    try {
                        var settingsSelect = document.createElement('div');
                        settingsSelect.setAttribute("class", "settingsSelect");
                        var settingsTabs = ['General', 'Tags', 'Chat', 'Alerts', 'Author', 'Site Style'];
                        let tabC = 0;
                        function createTab(tab) {
                            let settingsSelectBTN = document.createElement('input');
                            settingsSelectBTN.setAttribute("type", "button");
                            settingsSelectBTN.setAttribute("class", "settingsSelectBTN");
                            settingsSelectBTN.value = String(tab);
                            if (tabC == 0) {
                                settingsSelectBTN.style.backgroundColor = '#4b4f6b';
                                settingsSelectBTN.disabled = true;
                                tabC = 1;
                                var settingTab = document.querySelector(`.settingsTab[name="${String(tab)}"]`)

                                }
                            settingsSelectBTN.onclick = function () {
                                let len = document.querySelectorAll('input.settingsSelectBTN');
                                for (let i = 0; i < len.length; i++) {
                                    if (len[i].disabled == true) {
                                        len[i].disabled = false;
                                        len[i].style.backgroundColor = '#373952';
                                    }
                                };
                                this.disabled = true;
                                this.style.backgroundColor = '#4b4f6b';
                                try {
                                    var settingTab = document.querySelector(`.settingsTab[name="${String(tab)}"]`)
                                    if (settingTab) {
                                        var tabs = document.querySelectorAll(`div.settingsTab`)
                                        for (let i = 0; i < tabs.length; i++) {
                                            tabs[i].style.display = 'none';
                                        };
                                        settingTab.style.display = 'initial'
                                    }
                                } catch (error) {
                                    console.log(error);
                                };
                            };

                            let settingsSelectDiv = document.createElement('div');
                            settingsSelectDiv.setAttribute('class', 'settingsSelectDiv');
                            settingsSelectDiv.style.width = String(100 / settingsTabs.length) + '%';
                            settingsSelectDiv.appendChild(settingsSelectBTN);
                            settingsSelect.appendChild(settingsSelectDiv);
                        }
                        settingsTabs.forEach(tab => createTab(tab));
                    } catch (error) {
                        console.log(error);
                    }

                    var settingsExit = document.createElement('a');
                    settingsExit.setAttribute('class', 'blacklistRemove');
                    settingsExit.innerText = 'Exit'
                    settingsExit.onclick = function () {
                        document.querySelector('#confDisp').style.display = 'none'
                    };

                    function contact() {
                        function topicSendMessage(){
                            try{
                                let message = document.querySelector('[name="topicMessage"]').value;
                                fetch("https://fiction.live/api/node", {
                                    "headers": {
                                        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
                                        "Accept": "*/*",
                                        "Accept-Language": "en-GB,en;q=0.5",
                                        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                                        "X-Requested-With": "XMLHttpRequest",
                                        "Cache-Control": "max-age=0"
                                    },
                                    "referrer": "https://fiction.live/social/threads/Fiction-live-script-Update-19-Custom-Site-Colors/snFwRdTqfhBoQxutt",
                                    "body": `r%5B%5D=snFwRdTqfhBoQxutt&nt=chat&b=${message}`,
                                    "method": "POST",
                                    "mode": "cors"
                                });
                                document.querySelector('[name="topicMessage"]').value = null;
                            }catch(error){console.log(error)}

                        }
                        var contactLeft = document.createElement('div');
                        contactLeft.setAttribute('class', 'contactL');

                        var contactContainer = document.createElement('div');
                        contactContainer.setAttribute('id', 'reportDiv');
                        contactContainer.innerText = 'Report any issues you encounter to me through either of the links below or the comment box to the side.';
                        contactContainer.style.fontSize = '20px';
                        contactContainer.style.padding = '5px';
                        contactContainer.style.color = 'white';

                        var contactAkun = document.createElement('a');
                        contactAkun.innerText = 'Akun Script Topic';
                        contactAkun.href = 'https://fiction.live/social/threads/snFwRdTqfhBoQxutt';
                        contactAkun.rel = "noopener noreferrer";
                        contactAkun.target = "_blank";

                        var contactGreasyfork = document.createElement('a');
                        contactGreasyfork.innerText = 'Greasyfork Page';
                        contactGreasyfork.href = 'https://greasyfork.org/en/scripts/418607-fiction-live-merged';
                        contactGreasyfork.rel = "noopener noreferrer";
                        contactGreasyfork.target = "_blank";

                        var contactRight = document.createElement('div');
                        contactRight.setAttribute('class', 'contactR');

                        var topicMessage = document.createElement('textarea');
                        topicMessage.setAttribute('name', 'topicMessage');
                        topicMessage.setAttribute('class', 'topicMessage');
                        topicMessage.setAttribute('placeholder', "You can use this to report issues. Fill the box in then press the button. Check the topic for replies.");
                        topicMessage.setAttribute("cols", "1");
                        topicMessage.setAttribute("rows", "5");

                        var sendMessage = document.createElement('input');
                        sendMessage.setAttribute("type", "button");
                        sendMessage.setAttribute("class", "colors");
                        sendMessage.value='Send report to topic.'
                        sendMessage.onclick=topicSendMessage;
                        sendMessage.style.background = 'rgb(42,44,59) !important';

                        var contact = document.createElement('div');
                        contact.setAttribute('class', 'contactMain');
                        contactContainer.appendChild(document.createElement('br'));
                        contactContainer.appendChild(contactAkun);
                        contactContainer.appendChild(document.createElement('br'));
                        contactContainer.appendChild(contactGreasyfork);
                        contactLeft.appendChild(contactContainer);
                        contactRight.appendChild(topicMessage);
                        contactRight.appendChild(sendMessage);
                        contact.appendChild(contactLeft);
                        contact.appendChild(contactRight);

                        return contact;
                    };

                    settingsTop.appendChild(settingsExit)
                    var confDisp = configDisplay();
                    var confBox = configBox();
                    confBox.appendChild(settingsTop);
                    confBox.appendChild(settingsSelect);
                    confBox.appendChild(settingsActual());
                    confBox.appendChild(settingsTagsBlacklist());
                    confBox.appendChild(settingsUserBlacklist());
                    confBox.appendChild(settingsAuthorsBlacklist());
                    confBox.appendChild(settingsStyle());
                    confBox.appendChild(settingsBlacklist());
                    confBox.appendChild(contact());
                    confDisp.appendChild(confBox);
                    document.querySelector('body').prepend(confDisp);
                }
            } catch (error) {
                console.log('Settings Display Error', error);
            };
        };

        function settingsOpen() {
            var myLive = document.createElement('li');
            myLive.setAttribute('id', 'confScript');
            myLive.style.textShadow = '-1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000';
            myLive.style.fontWeight = 'bold';

            var configOpen = document.createElement('a');
            configOpen.innerText = 'Config';
            configOpen.onclick = function () {
                document.querySelector('#confDisp').style.display = 'block'
            };
            myLive.appendChild(configOpen);
            return myLive
        };

        function settingsInsert() {
            try {
                let mainMenu = document.querySelector('nav#mainMenu');
                settingsDisplay()
                if (!(mainMenu.querySelector('#confScript'))) {
                    mainMenu.childNodes[2].appendChild(settingsOpen());
                }
            } catch (error) {
                console.log('Errors inserting Settings', error)
            };
        };

        settingsInsert()
    };

    pageCheck();
    awaitAlerts()
    awaitMainMenu();
})();