// ==UserScript==
// @name the ultimate discord owot chat bundle
// @namespace discord_owotchat
// @version 1.0
// @description Makes OWOT Chat more like Discord
// @author Some_people
// @match https://ourworldoftext.com/*
// @icon https://https://www.google.com/s2/favicons?sz=64&domain=ourworldoftext.com
// @grant none
// @license MIT
// ==/UserScript==
/* OWOT ECF BY E_G. */
send = function(msg){
w.chat.send(msg);
}
random = function(min, max){
return Math.random() * max + min;
}
bot = function(command, func){
w.on("chatmod", function(e){
e.id += "";
if(Function("data", "return " + command)(e)){
func(e, e.message.split(" ").slice(1), e.realUsername || e.nickname || e.id);
};
});
};
client_commands.bot = function(args){
bot(args[0], Function("data, args, name", args.slice(1).join(" ")));
}
var hasDoneAction = false;
function findReply(e){
var message = (e.message || [...e.element.children].at(-1).innerHTML);
var extractedReply = message.substring(!e.message * 6, message.indexOf(")") + 2);
var matchesSyntax = extractedReply.match(/^reply\(\d+\) /g);
if(!matchesSyntax) return false;
var replyDate = matchesSyntax[0].match(/\d+/)[0];
var reply = [...chatRecordsPage, ...chatRecordsGlobal].filter(x => x.date == replyDate);
if(reply[0] == undefined) return false;
addChat(e.location || (e.field.id.startsWith("page") ? "page" : "global"), reply[0].id, "anon", "template", "<span id='template'></span>", "template", true);
var template = document.getElementById("template").parentNode.parentNode;
if(e.element) template.parentNode.insertBefore(template, e.element);
template.outerHTML = reply[0].element.outerHTML;
var finalReply = [...elm[(e.message ? e.location : e.field.id.startsWith("page") ? "page" : "global")+"_chatfield"].children].filter(x => x.outerHTML == reply[0].element.outerHTML);
[...[...finalReply].at(-1).children].forEach(y => {y.style.fontSize = "10px"; y.id = ""});
return finalReply;
};
w.on("chatmod", function(e){
var field = e.location == "page" ? "Page" : "Global";
e.replyOfMessage = findReply(e);
if(e.replyOfMessage){
e.message = e.message.replace(/reply\(\d+\) /, "");
};
setTimeout(function(){
var div = window["chatRecords" + field].filter(x=>x.date == e.date && x.id == e.id)[0].element;
var matchLink = [...div.children].at(-1).innerHTML.match(/link\(.+\) /);
if(matchLink){
[...div.children].at(-1).outerHTML = `<a> </a><a href=${matchLink[0].substring(5,matchLink[0].length-2)} style="color: #0070E0"><u>${[...div.children].at(-1).innerHTML.replace(/link\(.+\) /, "").substring(6)}</u></a>`;
return;
};
var string = [...div.children].at(-1).children.length ? [...div.children].at(-1).children[0].innerHTML : [...div.children].at(-1).innerHTML;
var hexValues = string.match(/#[0-9A-F]{6}|#[0-9A-F]{3}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)/g);
var stringSpan = "<span>" + (string.split(/#[0-9A-F]{6}|#[0-9A-F]{3}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)/g).join`</span><span style="color: ">` + "</span>");
if(hexValues){
hexValues.forEach(x => stringSpan = stringSpan.replace(/<span style="color: ">/, `<span style="color: ${x}">`));
if(stringSpan.startsWith("<span>>")) return;
[...div.children].at(-1).outerHTML = stringSpan;
};
div.onclick = function(x){
if(!x.shiftKey) return;
div.remove();
if(!e.replyOfMessage) return;
e.replyOfMessage.remove();
};
[...div.children].forEach(function(i){
i.onclick = function(x){
if(x.ctrlKey){
elm.chatbar.value = "reply(" + e.date + ") ";
elm.chatbar.focus();
};
};
});
});
if(hasDoneAction) return;
hasDoneAction = true;
[...chatRecordsPage, ...chatRecordsGlobal].forEach(function(e){
var field = e.location == "page" ? "Page" : "Global";
e.replyOfMessage = findReply(e);
if(e.replyOfMessage){
[...e.element.children].at(-1).innerHTML = [...e.element.children].at(-1).innerHTML.replace(/reply\(\d+\) /, "");
};
var matchLink = [...e.element.children].at(-1).innerHTML.match(/link\(.+\) /);
if(matchLink){
[...e.element.children].at(-1).outerHTML = `<a> </a><a href=${matchLink[0].substring(5,matchLink[0].length-2)} style="color: #0070E0"><u>${[...e.element.children].at(-1).innerHTML.replace(/link\(.+\) /, "").substring(6)}</u></a>`;
return;
};
var string = [...e.element.children].at(-1).innerHTML;
var hexValues = string.match(/#[0-9A-F]{6}|#[0-9A-F]{3}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)/g);
var stringSpan = "<span>" + (string.split(/#[0-9A-F]{6}|#[0-9A-F]{3}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)/g).join`</span><span style="color: ">` + "</span>");
if(hexValues){
hexValues.forEach(x => stringSpan = stringSpan.replace(/<span style="color: ">/, `<span style="color: ${x}">`));
if(stringSpan.startsWith('<span> <span style="color: </span><span style="color: #789922">">>')) return;
[...e.element.children].at(-1).outerHTML = stringSpan;
};
});
[...chatRecordsPage, ...chatRecordsGlobal].forEach(function(x){
x.element.onclick = function(e){
if(e.shiftKey) x.element.remove();
};
[...x.element.children].forEach(function(i){
i.onclick = function(e){
if(e.ctrlKey) elm.chatbar.value = "reply(" + x.date + ") ";
elm.chatbar.focus();
};
});
});
});
/* OWOT USER INDICATOR BY E_G. */
let warn = true;
let people = [];
let timeout;
//Part made by KKosty4ka
var chat_upper = document.getElementById("chat_upper");
chat_upper.appendChild(document.createElement("br"));
var typing_display = chat_upper.appendChild(document.createElement("span"));
typing_display.style.display = "flex";
typing_display.style.justifyContent = "center";
typing_display.style.alignItems = "center";
//Part made by KKosty4ka
menu.addCheckboxOption('Online Offline warning', function(){
warn = true;
}, function(){
warn = false;
}, true);
w.broadcastReceive(true);
w.on('cmd', function(e){
if(!e.username || !warn) return;
if(e.data.startsWith('online')){
clientChatResponse(e.username + " is online!");
}
else if(e.data.startsWith('offline')){
clientChatResponse(e.username + " is now offline.");
}
else if(e.data.startsWith('back')){
clientChatResponse(e.username + " is back.");
}
else if(e.data.startsWith('afk')){
clientChatResponse(e.username + " is AFK. (Idle)");
}
else if(e.data.startsWith('typing')){
if(!people.includes(e.username)) people.push(e.username);
typing_display.innerText = people.join(" and ") + " " + (people.length > 1 ? "are" : "is") + " typing...";
}
else if(e.data.startsWith('untyping')){
people = people.filter((x, i)=>i != people.indexOf(e.username))
typing_display.innerText = people.length ? people.join(" and ") + " " + (people.length > 1 ? "are" : "is") + " typing..." : "Currently, no one is typing";
};
});
setTimeout(function(){
w.broadcastCommand('online', true);
}, 1000);
window.addEventListener('beforeunload', function(){
w.broadcastCommand('offline', true)
});
window.onblur = function(){w.broadcastCommand('afk', true)};
window.onfocus = function(){w.broadcastCommand('back', true)};
elm.chatbar.oninput = function(e){
if(timeout) clearTimeout(timeout);
if(!elm.chatbar.value.length) w.broadcastCommand("untyping", true);
if(!!elm.chatbar.value.length && !people.includes(state.userModel.username)) w.broadcastCommand('typing', true);
timeout = setTimeout(function(){
w.broadcastCommand("untyping", true);
}, 5000);
};
/* DARK MODE CHAT BY YAGTON */
(() => {
const changes = [
["#chat_window", "backgroundColor", "#3c3836"],
["#chat_close", "backgroundColor", "#cc241d"],
["#chat_upper", "color", "#fbf1c7"],
["#chatbar", "backgroundColor", "#282828"],
["#chatbar", "color", "#fbf1c7"],
["#chatbar", "border", "1px solid #1d2021"],
["#chatsend", "backgroundColor", "#282828"],
["#chatsend", "color", "#fbf1c7"],
["#chatsend", "border", "1px solid #1d2021"],
[".unread", "color", "#fb4934"],
[".chatfield", "backgroundColor", "#282828"],
[".chatfield", "color", "#fbf1c7"],
];
for (let i of changes)
for (let e of document.querySelectorAll(i[0]))
e.style[i[1]] = i[2];
// because .chat_tab_selected has to be done differently :ohno:
let head = document.getElementsByTagName('head')[0];
let st = document.createElement('style');
st.innerHTML = ".chat_tab_selected { background-color: #504945; }";
head.appendChild(st);
})();
/* DISCORD SOUNDS BY GUEST-1052 (SPAGHETTI CODE WARNING) */
sa=new Audio ("https://www.myinstants.com/media/sounds/discordmute.mp3");la=new Audio("https://www.myinstants.com/media/sounds/discord-message.mp3");w.on('chatmod',e=>{if(/@silent/i.test(e.message)){} else{if(e.realUsername=="[ Server ]"&&/deleted|blocked|muted/i.test(e.message)){sa.currentTime=0;sa.play()} else{la.currentTime=0;la.play()}}});
/* KEYBOARD SOUNDS (USELESS) */
onkeydown=_=>{ze=new Audio("https://www.myinstants.com/media/sounds/pressing-a-pc-key.mp3");ze.playbackRate=3.2;ze.volume=0.25;ze.play()}