let urlPart = ".prime.cringe-studios.com" let titleStart = "Is "; let titleEnd = " prime?"; let evasiveString = "this"; function GetQuestion() { let hostname = window.location.hostname; while(true) { if( !hostname.endsWith(urlPart) ) { let dotIndex = hostname.indexOf("."); // If no dot was found, just return the hostname if(dotIndex == -1) { return hostname; } // If there is a dot where the most sub level domain should be, restart with the dot trimmed if(dotIndex == 0) { hostname = hostname.substring(1); continue; } // return everything starting from 0 to the dot index return hostname.substring(0, dotIndex); }else{ if(urlPart.length == hostname.length) { // if the url entered is just the url part, return an evasive string return evasiveString; } let urlPartIndex = hostname.lastIndexOf(urlPart); hostname = hostname.substring(0, urlPartIndex); let dotIndex = hostname.lastIndexOf("."); // If no dot was found, just return the hostname if(dotIndex == -1) { return hostname; } // return everything after the dot return hostname.substring(dotIndex + 1); } } } function SetTitle(question) { document.title = titleStart + question + titleEnd; } function UpdateContents(question) { questionTextElement = document.getElementById("questionText"); questionTextElement.textContent = titleStart + question + titleEnd; } window.onload = function() { let question = GetQuestion(); UpdateContents(question); SetTitle(question); }