Guest User

Userscript version

a guest
Sep 15th, 2023
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name the ultimate discord owot chat bundle
  3. // @namespace discord_owotchat
  4. // @version 1.0
  5. // @description Makes OWOT Chat more like Discord
  6. // @author Some_people
  7. // @match https://ourworldoftext.com/*
  8. // @icon https://https://www.google.com/s2/favicons?sz=64&domain=ourworldoftext.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. /* OWOT ECF BY E_G. */
  14. send = function(msg){
  15.     w.chat.send(msg);
  16. }
  17. random = function(min, max){
  18.     return Math.random() * max + min;
  19. }
  20. bot = function(command, func){
  21.     w.on("chatmod", function(e){
  22.         e.id += "";
  23.         if(Function("data", "return " + command)(e)){
  24.             func(e, e.message.split(" ").slice(1), e.realUsername || e.nickname || e.id);
  25.         };
  26.     });
  27. };
  28. client_commands.bot = function(args){
  29.     bot(args[0], Function("data, args, name", args.slice(1).join(" ")));
  30. }
  31. var hasDoneAction = false;
  32. function findReply(e){
  33.     var message = (e.message || [...e.element.children].at(-1).innerHTML);
  34.     var extractedReply = message.substring(!e.message * 6, message.indexOf(")") + 2);
  35.     var matchesSyntax = extractedReply.match(/^reply\(\d+\) /g);
  36.     if(!matchesSyntax) return false;
  37.     var replyDate = matchesSyntax[0].match(/\d+/)[0];
  38.     var reply = [...chatRecordsPage, ...chatRecordsGlobal].filter(x => x.date == replyDate);
  39.     if(reply[0] == undefined) return false;
  40.     addChat(e.location || (e.field.id.startsWith("page") ? "page" : "global"), reply[0].id, "anon", "template", "<span id='template'></span>", "template", true);
  41.     var template = document.getElementById("template").parentNode.parentNode;
  42.     if(e.element) template.parentNode.insertBefore(template, e.element);
  43.     template.outerHTML = reply[0].element.outerHTML;
  44.     var finalReply = [...elm[(e.message ? e.location : e.field.id.startsWith("page") ? "page" : "global")+"_chatfield"].children].filter(x => x.outerHTML == reply[0].element.outerHTML);
  45.     [...[...finalReply].at(-1).children].forEach(y => {y.style.fontSize = "10px"; y.id = ""});
  46.     return finalReply;
  47. };
  48.  
  49. w.on("chatmod", function(e){
  50.     var field = e.location == "page" ? "Page" : "Global";
  51.     e.replyOfMessage = findReply(e);
  52.     if(e.replyOfMessage){
  53.         e.message = e.message.replace(/reply\(\d+\) /, "");
  54.     };
  55.     setTimeout(function(){
  56.         var div = window["chatRecords" + field].filter(x=>x.date == e.date && x.id == e.id)[0].element;
  57.         var matchLink = [...div.children].at(-1).innerHTML.match(/link\(.+\) /);
  58.         if(matchLink){
  59.             [...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>`;
  60.             return;
  61.         };
  62.         var string = [...div.children].at(-1).children.length ? [...div.children].at(-1).children[0].innerHTML : [...div.children].at(-1).innerHTML;
  63.         var hexValues = string.match(/#[0-9A-F]{6}|#[0-9A-F]{3}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)/g);
  64.         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>");
  65.         if(hexValues){
  66.             hexValues.forEach(x => stringSpan = stringSpan.replace(/<span style="color: ">/, `<span style="color: ${x}">`));
  67.             if(stringSpan.startsWith("<span>&gt;")) return;
  68.             [...div.children].at(-1).outerHTML = stringSpan;
  69.         };
  70.         div.onclick = function(x){
  71.             if(!x.shiftKey) return;
  72.             div.remove();
  73.             if(!e.replyOfMessage) return;
  74.             e.replyOfMessage.remove();
  75.         };
  76.         [...div.children].forEach(function(i){
  77.             i.onclick = function(x){
  78.                 if(x.ctrlKey){
  79.                     elm.chatbar.value = "reply(" + e.date + ") ";
  80.                     elm.chatbar.focus();
  81.                 };
  82.             };
  83.         });
  84.     });
  85.     if(hasDoneAction) return;
  86.     hasDoneAction = true;
  87.     [...chatRecordsPage, ...chatRecordsGlobal].forEach(function(e){
  88.         var field = e.location == "page" ? "Page" : "Global";
  89.         e.replyOfMessage = findReply(e);
  90.         if(e.replyOfMessage){
  91.             [...e.element.children].at(-1).innerHTML = [...e.element.children].at(-1).innerHTML.replace(/reply\(\d+\) /, "");
  92.         };
  93.         var matchLink = [...e.element.children].at(-1).innerHTML.match(/link\(.+\) /);
  94.         if(matchLink){
  95.             [...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>`;
  96.             return;
  97.         };
  98.         var string = [...e.element.children].at(-1).innerHTML;
  99.         var hexValues = string.match(/#[0-9A-F]{6}|#[0-9A-F]{3}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)/g);
  100.         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>");
  101.         if(hexValues){
  102.             hexValues.forEach(x => stringSpan = stringSpan.replace(/<span style="color: ">/, `<span style="color: ${x}">`));
  103.             if(stringSpan.startsWith('<span>&nbsp;<span style="color: </span><span style="color: #789922">">&gt;')) return;
  104.             [...e.element.children].at(-1).outerHTML = stringSpan;
  105.         };
  106.     });
  107.     [...chatRecordsPage, ...chatRecordsGlobal].forEach(function(x){
  108.         x.element.onclick = function(e){
  109.             if(e.shiftKey) x.element.remove();
  110.         };
  111.         [...x.element.children].forEach(function(i){
  112.             i.onclick = function(e){
  113.             if(e.ctrlKey) elm.chatbar.value = "reply(" + x.date + ") ";
  114.             elm.chatbar.focus();
  115.             };
  116.         });
  117.     });
  118. });
  119.  
  120. /* OWOT USER INDICATOR BY E_G. */
  121.  
  122. let warn = true;
  123. let people = [];
  124. let timeout;
  125.  
  126. //Part made by KKosty4ka
  127. var chat_upper = document.getElementById("chat_upper");
  128. chat_upper.appendChild(document.createElement("br"));
  129. var typing_display = chat_upper.appendChild(document.createElement("span"));
  130. typing_display.style.display = "flex";
  131. typing_display.style.justifyContent = "center";
  132. typing_display.style.alignItems = "center";
  133. //Part made by KKosty4ka
  134.  
  135. menu.addCheckboxOption('Online Offline warning', function(){
  136.     warn = true;
  137. }, function(){
  138.     warn = false;
  139. }, true);
  140.  
  141. w.broadcastReceive(true);
  142. w.on('cmd', function(e){
  143.     if(!e.username || !warn) return;
  144.     if(e.data.startsWith('online')){
  145.         clientChatResponse(e.username + " is online!");
  146.     }
  147.     else if(e.data.startsWith('offline')){
  148.         clientChatResponse(e.username + " is now offline.");
  149.     }
  150.     else if(e.data.startsWith('back')){
  151.         clientChatResponse(e.username + " is back.");
  152.     }
  153.     else if(e.data.startsWith('afk')){
  154.         clientChatResponse(e.username + " is AFK. (Idle)");
  155.     }
  156.     else if(e.data.startsWith('typing')){
  157.         if(!people.includes(e.username)) people.push(e.username);
  158.         typing_display.innerText = people.join(" and ") + " " + (people.length > 1 ? "are" : "is") + " typing...";
  159.     }
  160.     else if(e.data.startsWith('untyping')){
  161.         people = people.filter((x, i)=>i != people.indexOf(e.username))
  162.         typing_display.innerText = people.length ? people.join(" and ") + " " + (people.length > 1 ? "are" : "is") + " typing..." : "Currently, no one is typing";
  163.     };
  164. });
  165.  
  166. setTimeout(function(){
  167.     w.broadcastCommand('online', true);
  168. }, 1000);
  169.  
  170. window.addEventListener('beforeunload', function(){
  171.     w.broadcastCommand('offline', true)
  172. });
  173.  
  174. window.onblur = function(){w.broadcastCommand('afk', true)};
  175.  
  176. window.onfocus = function(){w.broadcastCommand('back', true)};
  177.  
  178. elm.chatbar.oninput = function(e){
  179.     if(timeout) clearTimeout(timeout);
  180.     if(!elm.chatbar.value.length) w.broadcastCommand("untyping", true);
  181.     if(!!elm.chatbar.value.length && !people.includes(state.userModel.username)) w.broadcastCommand('typing', true);
  182.     timeout = setTimeout(function(){
  183.         w.broadcastCommand("untyping", true);
  184.     }, 5000);
  185. };
  186.  
  187. /* DARK MODE CHAT BY YAGTON */
  188.  
  189. (() => {
  190.     const changes = [
  191.         ["#chat_window", "backgroundColor", "#3c3836"],
  192.         ["#chat_close", "backgroundColor", "#cc241d"],
  193.         ["#chat_upper", "color", "#fbf1c7"],
  194.         ["#chatbar", "backgroundColor", "#282828"],
  195.         ["#chatbar", "color", "#fbf1c7"],
  196.         ["#chatbar", "border", "1px solid #1d2021"],
  197.         ["#chatsend", "backgroundColor", "#282828"],
  198.         ["#chatsend", "color", "#fbf1c7"],
  199.         ["#chatsend", "border", "1px solid #1d2021"],
  200.         [".unread", "color", "#fb4934"],
  201.         [".chatfield", "backgroundColor", "#282828"],
  202.         [".chatfield", "color", "#fbf1c7"],
  203.     ];
  204.  
  205.     for (let i of changes)
  206.         for (let e of document.querySelectorAll(i[0]))
  207.             e.style[i[1]] = i[2];
  208.  
  209.     // because .chat_tab_selected has to be done differently :ohno:
  210.     let head  = document.getElementsByTagName('head')[0];
  211.     let st = document.createElement('style');
  212.     st.innerHTML = ".chat_tab_selected { background-color: #504945; }";
  213.     head.appendChild(st);
  214. })();
  215.  
  216. /* DISCORD SOUNDS BY GUEST-1052 (SPAGHETTI CODE WARNING) */
  217. 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()}}});
  218.  
  219. /* KEYBOARD SOUNDS (USELESS) */
  220.  
  221. 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()}
Advertisement
Add Comment
Please, Sign In to add comment