? Chat JS Add-Ons (Page 4) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
This is the development website, where we test out new features. This isn't the place you're looking for! Go here

Chat JS Add-Ons

1 2 3 4 5
  • #61 ✎ 1 Trimitro21 If the crappy mobile detector regex thinks you're on a smartphone it rearranges chat so things are out of the way swipe from left to pull out tabs and pm rooms swipe from right to pull out userlist to retract the menus swipe from outside the menu toward the edge the menu came from https://pastebin.com/raw/id2UsQHZ Posted Edited by Trimitro21
  • #62 ✎ 38 snail_ Avatar Taboo I didn't change my avatar for 180 days Website Deep Sleep Hidden Website Minecraft Is Awesome! I love Minecraft! Express Yourself PM room log dumper. Type /dump in a PM room to do. Saves in JSON format, convert to plaintext SBS chatlog format with separate Dump Converter tool (coming soon?) EDIT: Markdown isn't actually produced, it's just plain text with no formatting codes. Maybe I'll fix it? //pm log dump { /* Command function. This gathers up all the messages in the room and dumps them. */ function dumpPM(room) { //argument sanity checking room = room.trim(); if(room === '') room = currentTag(); match = room.match(/\d+/); if(match === null) { warningMessage("Bad arg! Not in a PM room?"); return; } tag = "room_" + match[0] messages = document.querySelectorAll("#messagepane li[data-tags~=" + tag + "]"); if(messages.length === 0) { warningMessage("No messages for this room! Are you a member? Does it exist?"); return; } //dump messages dump = { request: { time: new Date().toString(), tag: tag, user: { name: username, uid: useruid, icon: document.querySelector("#userAvatar").src }, version: '1.1.0' }, messages: [] } for(msg of messages) { obj = { user: { uid: msg.dataset.user } } if(msg.getAttribute('class') === 'modulemessage' && msg.dataset.module == 'fun') { obj.user.name = msg.textContent.split(' ')[0]; obj.type = 'me'; obj.content = msg.textContent; } else { obj.type = 'normal'; obj.time = msg.querySelector('time').getAttribute('datetime'), obj.user.name = msg.querySelector('figcaption').textContent; obj.user.icon = msg.querySelector('figure img').src; obj.parts = []; for(part of msg.querySelectorAll('message-part')) { out = { type: part.getAttribute('data-encoding') } switch(out.type) { case 'draw': out.content = part.querySelector('a').href; break; case 'image': out.content = part.querySelector('img').src; break; default: out.content = part.textContent; break; } obj.parts.push(out); } } dump.messages.push(obj); } console.log(dump); uri = 'data:application/octet-stream,' + encodeURIComponent(JSON.stringify(dump, null, '\t')); location.href = uri; } //push the command into the thingy commands.push(new Command("dump", dumpPM, "Dump the contents of a PM room.")); } //pm log dump ends here. Posted Edited by snail_
  • #63 ✎ 38 snail_ Avatar Taboo I didn't change my avatar for 180 days Website Deep Sleep Hidden Website Minecraft Is Awesome! I love Minecraft! Express Yourself User Dropdown PM Jump Puts an Open PM action into the user dropdown list, underneath Ignore. Switches focus to a personal PM room with you and the other user, creating it if it does not already exist. This is a useful shortcut if you have your sidebar collapsed (as I usually do on mobile.) Note this does not jump to group PM rooms that just contain this user. This only works with individual PM rooms. // replace userlist hook let oldHook = refreshUserList; refreshUserList = function(userList) { oldHook(userList); // append buttons let userItems = document.querySelectorAll("#userpane li ul"); for(user of userItems) { let listItem = document.createElement("li"); let anchor = document.createElement("a"); anchor.textContent = "Open PM"; anchor.addEventListener("click", pmJumpHandler); listItem.appendChild(anchor); user.appendChild(listItem); } } // onclick event handler for pm jumping function pmJumpHandler(event) { let userID = event.target.parentNode.parentNode.parentNode.dataset.uid; jumpToPM(userID); } // jump chat to appropriate pm room function jumpToPM(uid) { console.log("Jumping to " + uid); // select personal PM room with this user let target = undefined; if(uid === useruid) { target = 1 } else { target = 2 } let rooms = document.querySelectorAll("#roomlist label"); let selected = false; for(rm of rooms) { let members = rm.querySelectorAll("div.roomuserlist img"); members = Array.prototype.map.call(members, function(e) { return e.dataset.uid }); if(members.length === target && members.includes(uid)) { document.querySelector( 'input[id="'+rm.attributes["for"].value+'"]' ).click(); selected = true; break; } } // make the desired room if it isn't open if(!selected) { let handler = function(message) { if(message.textContent.startsWith("You created a chatroom for ") && message.dataset.module === "pm") { document.querySelector("#roomlist input:last-of-type").click(); removeMessageEvent(handler); } } addMessageEvent(handler); sendMessage("/pmcreate #" + uid); } } Posted
  • #64 ✎ 38 snail_ Avatar Taboo I didn't change my avatar for 180 days Website Deep Sleep Hidden Website Minecraft Is Awesome! I love Minecraft! Express Yourself Put it in your Custom CSS to show textareas in monospace. Much nicer for editing pages IMO. textarea { font-family: monospace !important; } Posted
  • #65 ✎ 38 snail_ Avatar Taboo I didn't change my avatar for 180 days Website Deep Sleep Hidden Website Minecraft Is Awesome! I love Minecraft! Express Yourself Use this to automatically expand/collapse the chat sidebar based on width. This event fires every window resize. It doesn't care if you keep the sidebar open or not; if you don't want the computer to do it for you, just don't use this script lol. Change the value of collapseWidth (in px) to change the transition width. /*------------------------------ Automatically Collapse Sidebar by snail_ 2017 version 1.0.0 ------------------------------*/ let collapseWidth = 800; function checkWidth(event) { let collapser = document.querySelector("#sidepanepulltab"); let collapsed = collapser.dataset.collapsed; if((window.innerWidth < collapseWidth && !collapsed) || (window.innerWidth >= collapseWidth && collapsed)) { collapser.click(); } } checkWidth(); window.addEventListener("resize", checkWidth); // Automatically Collapse Sidebar ends here. */ ALSO THIS THREAD SHOULD BE STICKIED Posted Edited by snail_
  • #66 ✎ 10 ShadowCX13 Avatar Taboo I didn't change my avatar for 180 days Website Due to popular demand: Extinguisher This script hides practically any trace of a user in chat, including their being in PM rooms, in the userlist, and their messages. It uses MutationObservers and ES6 so uhhhhhhhh... Might not work on older browsers. If people want to hack together their own script, feel free. Version 2.0 (latest) https://0bin.net/paste/KMy40xPaJdjLsg9V#0sncPtC1hPIJ3lxqFNmIC2MYUMbKmsGTdkCJ7grWuQH UPDATE: If you're using a script to show messages in your titlebar, messages by extinguished users will still be shown. Instead, delete it and use this script instead. addMessageEvent(function(messageElement) { if (messageElement.className) { titleTag.innerHTML=messageElement.textContent; } else if(extinguished.indexOf(messageElement.dataset.user) === -1){ titleTag.innerHTML=messageElement.dataset.username+": "+messageElement.querySelector("message-content").textContent; } }); If you're a chatJS programmer, you can test if a user is extinguished by checking if the UID is in the extinguished array Posted Edited by ShadowCX13
  • #67 ✎ 103 12Me21 Forum Moderator Night Person I like the quiet night and sleep late. Express Yourself "popular demand" Posted
  • #68 ✎ 258 Y____ Head Admin Gardening I like to garden! Hobbies Reading I like to read books! Hobbies Drawing I like to draw! Hobbies /* Remember: internal tags are: Programming : general Off-Topic : offtopic Staff : staff modules : any PMs : room_# (not revealed without settings) */ function scls(param){ var params = quickParamParse(param); if(params.length > 1) { warningMessage("Incorrect parameter (ex. /cls general)"); return; } if (params.length == 1 && params[0] !== "") { elements = document.querySelectorAll("li[data-tags="+params[0]+"]"); } else { elements = document.querySelectorAll("#messagepane ol li"); } for (var element of elements) { element.parentElement.removeChild(element); } systemMessage('Messages cleared (selectively)'); } commands.push(new Command("scls", scls)); Posted
  • #69 ✎ 258 Y____ Head Admin Gardening I like to garden! Hobbies Reading I like to read books! Hobbies Drawing I like to draw! Hobbies function rgb2sb(param){ var params = quickParamParse(param); if(params.length != 3 && params.length != 1) { warningMessage("Bad form? (/rgb2sb R G B or /rgb2sb #RRGGBB)"); return; } if (params.length == 3) { localModuleMessage( '[<span style="color:#F00">' + '█ '.repeat(1+Math.floor(params[0] / 36.6)) + '</span>]\n' + '[<span style="color:#0F0">' + '█ '.repeat(1+Math.floor(params[1] / 36.6)) + '</span>]\n' + '[<span style="color:#00F">' + '█ '.repeat(1+Math.floor(params[2] / 36.6)) + '</span>]' ); } else { localModuleMessage( '[<span style="color:#F00">' + '█ '.repeat(1+Math.floor(parseInt(params[0].substring(1,3),16) / 36.6)) + '</span>]\n' + '[<span style="color:#0F0">' + '█ '.repeat(1+Math.floor(parseInt(params[0].substring(3,5),16) / 36.6)) + '</span>]\n' + '[<span style="color:#00F">' + '█ '.repeat(1+Math.floor(parseInt(params[0].substring(5,7),16) / 36.6)) + '</span>]' ); } } commands.push(new Command("rgb2sb", rgb2sb));/code][/spoiler] Posted Edited by Y____
  • #70 ✎ 103 12Me21 Forum Moderator Night Person I like the quiet night and sleep late. Express Yourself window.nicknames={}; function time_until(time){ return Math.max(time-Date.now(), 0); } var last_request = Date.now(); function call_all(functions, arg){ for(var i=0;i<functions.length;i++) functions[i](arg); } var sent = {}; var get_nickname=function(username, callback){ //nickname unknown if(nicknames[username]!==undefined) return nicknames[username]; //if request was already sent, and the response hasn't been recieved, add the callback to the list if(sent[username]){ sent[username].push(callback); }else{ sent[username]=[]; var delay = time_until(last_request + 100); last_request = Date.now() + delay; //console.log(Date.now(), last_request, Date.now()-last_request, delay); window.setTimeout(function(){ console.log("req"); //make sure name hasn't already been loaded if(nicknames[username]===undefined) genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname) call_all(sent[username], nicknames[username] = nickname); //doesn't have nickname else nicknames[username] = false; sent[username] = undefined; }); else if(nicknames[username]){ call_all(sent[username], nicknames[username]); sent[username] = undefined; } },delay); } /*window.setTimeout(function(){ genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname) callback(nicknames[username] = nickname); //doesn't have nickname else nicknames[username] = false; }); }, delay);*/ } //this function can probably be improved addMessageEvent(function(message){ var username = message.dataset.username; var part = message.querySelector("message-part"); if(part){ var match = part.textContent.match(/^\[rpl22nick] (.*)'s name is now (.*)/); if(match) nicknames[username] = match[2]; } if(username && !message.className){ var nickname = get_nickname(username, function(nickname){ change_message_author(message, nickname); }); if(nickname) change_message_author(message, nickname); } }); function change_message_author(message, name){ message.querySelector("figcaption").textContent = name; } function write_persistent(name, value){ var data = new FormData(); data.append("name", name); data.append("value", value); genericXHR("/query/submit/varstore?session=" + StorageUtilities.GetPHPSession(), data); } commands.push(new Command("nick",function(param){ var nickname = param.substring(1); nicknames[username] = nickname; sendMessage("[rpl22nick] " + username + "'s name is now " + nickname); write_persistent("nickname_tcf", nickname); })); function roll(n){ //Rolls an n-sided die return (Math.random() * n | 0) + Math.sign(n); } commands.push(new Command("roll", function(param) { var n = Number.parseInt(param) || 20; var result = roll(n); sendMessage("[rpl22roll] "+nicknames[username]+" rolled a d"+n+" and got "+result+"!"); })); Posted Edited by 12Me21
  • #71 ✎ 258 Y____ Head Admin Gardening I like to garden! Hobbies Reading I like to read books! Hobbies Drawing I like to draw! Hobbies /* ***************** *\ |* Die/Name Commands *| \* ***************** */ window.nicknames={}; function time_until(time){ return Math.max(time-Date.now(), 0); } var last_request = Date.now(); function call_all(functions, arg){ for(var i=0;i<functions.length;i++) functions[i](arg); } var sent = {}; var get_nickname=function(username, callback){ //nickname unknown if(nicknames[username]!==undefined) return nicknames[username]; //if request was already sent, and the response hasn't been recieved, add the callback to the list if(sent[username]){ sent[username].push(callback); }else{ sent[username]=[]; var delay = time_until(last_request + 100); last_request = Date.now() + delay; //console.log(Date.now(), last_request, Date.now()-last_request, delay); window.setTimeout(function(){ console.log("req"); //make sure name hasn't already been loaded if(nicknames[username]===undefined) genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname) call_all(sent[username], nicknames[username] = nickname); //doesn't have nickname else nicknames[username] = false; sent[username] = undefined; }); else if(nicknames[username]){ call_all(sent[username], nicknames[username]); sent[username] = undefined; } },delay); } /*window.setTimeout(function(){ genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname) callback(nicknames[username] = nickname); //doesn't have nickname else nicknames[username] = false; }); }, delay);*/ } //this function can probably be improved addMessageEvent(function(message){ var username = message.dataset.username; var part = message.querySelector("message-part"); if(part){ var match = part.textContent.match(/^\[rpl22nick] (.*?)'s name is now (.*)/); if(match) nicknames[username] = match[2]; } if(username && !message.className){ var nickname = get_nickname(username, function(nickname){ change_message_author(message, nickname); }); if(nickname) change_message_author(message, nickname); } }); function change_message_author(message, name){ if (name.length > 40) name = name.substring(0,40); message.querySelector("figcaption").textContent = name; } function write_persistent(name, value){ var data = new FormData(); data.append("name", name); data.append("value", value); genericXHR("/query/submit/varstore?session=" + StorageUtilities.GetPHPSession(), data); } commands.push(new Command("nick",function(param){ var nickname = param.substring(1); if (nickname.length > 40) nickname = nickname.substring(0,40); nicknames[username] = nickname; write_persistent("nickname_tcf", nickname); sendMessage("[rpl22nick] " + username + "'s name is now " + nickname); })); commands.push(new Command("alias",function(param) { var result = ""; param = param.substring(1); matches = param === "" ? Object.keys(nicknames).filter(key => nicknames[key] !== false) : Object.keys(nicknames).filter(key => nicknames[key] === param) for(var user of matches) { result += user + " has nickname " + nicknames[user] + "\n"; } localModuleMessage(result); })); function roll(n){ //Rolls an n-sided die return (Math.random() * n | 0) + Math.sign(n); } commands.push(new Command("roll", function(param) { var n = Number.parseInt(param) || 20; var result = roll(n); var action = (n == 2) ? " flipped a coin" : " rolled a d" + n; sendMessage("[rpl22roll] "+nicknames[username]+action+" and got "+result+"!"); })); Posted Edited by Y____
  • #72 ✎ 103 12Me21 Forum Moderator Night Person I like the quiet night and sleep late. Express Yourself Very important update: allows you to actually remove your nickname /* ***************** *\ |* Die/Name Commands *| \* ***************** */ window.nicknames={}; function time_until(time){ return Math.max(time-Date.now(), 0); } var last_request = Date.now(); function call_all(functions, arg){ for(var i=0;i<functions.length;i++) functions[i](arg); } var sent = {}; var get_nickname=function(username, callback){ //nickname unknown if(nicknames[username]!==undefined) callback(nicknames[username]); else{ //if request was already sent, and the response hasn't been recieved, add the callback to the list if(sent[username]){ sent[username].push(callback); }else{ sent[username]=[callback]; var delay = time_until(last_request + 100); last_request = Date.now() + delay; window.setTimeout(function(){ console.log("req"); //make sure name hasn't already been loaded if(nicknames[username]===undefined) genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname && nickname !== "\r\n"){ call_all(sent[username], nicknames[username] = nickname); //doesn't have nickname }else nicknames[username] = false; sent[username] = undefined; }); else if(nicknames[username]){ call_all(sent[username], nicknames[username]); sent[username] = undefined; } },delay); } } } //this function can probably be improved addMessageEvent(function(message){ var username = message.dataset.username; var part = message.querySelector("message-part"); if(part){ var match = part.textContent.match(/^\[rpl23nick] (.*?)'s name is now (.*)/); if(match) nicknames[username] = match[2]; } if(username && !message.className){ get_nickname(username, function(nickname){ change_message_author(message, nickname); }); } }); function change_message_author(message, name){ if (name){ if (name.length > 40) name = name.substring(0,40); message.querySelector("figcaption").textContent = name; } } function write_persistent(name, value){ var data = new FormData(); data.append("name", name || "\n"); data.append("value", value); genericXHR("/query/submit/varstore?session=" + StorageUtilities.GetPHPSession(), data); } commands.push(new Command("nick",function(param){ var nickname = param.substring(1); if (nickname.length > 40) nickname = nickname.substring(0,40); nicknames[username] = nickname; write_persistent("nickname_tcf", nickname); sendMessage("[rpl23nick] " + username + "'s name is now " + nickname); })); commands.push(new Command("alias",function(param) { var result = ""; param = param.substring(1); for(var username in nicknames){ if(nicknames[username] === param) result += username+" has nickname "+param+"\n"; } localModuleMessage(result); })); function roll(n){ //Rolls an n-sided die return (Math.random() * n | 0) + Math.sign(n); } commands.push(new Command("roll", function(param) { var n = Number.parseInt(param) || 20; var result = roll(n); var action; if(n==2){ action = "flipped a coin"; result = (result===1?"tails":"heads"); }else{ action = "rolled a d"+n; } sendMessage("[rpl23roll] "+nicknames[username]+" "+action+" and got "+result+"!"); })); Posted
  • #73 ✎ 258 Y____ Head Admin Gardening I like to garden! Hobbies Reading I like to read books! Hobbies Drawing I like to draw! Hobbies /* ***************** *\ |* Die/Name Commands *| \* ***************** */ window.nicknames={}; function time_until(time){ return Math.max(time-Date.now(), 0); } var last_request = Date.now(); function call_all(functions, arg){ for(var i=0;i<functions.length;i++) functions[i](arg); } var sent = {}; var get_nickname=function(username, callback){ //nickname unknown if(nicknames[username]!==undefined) callback(nicknames[username]); else{ //if request was already sent, and the response hasn't been recieved, add the callback to the list if(sent[username]){ sent[username].push(callback); }else{ sent[username]=[callback]; var delay = time_until(last_request + 100); last_request = Date.now() + delay; window.setTimeout(function(){ console.log("req"); //make sure name hasn't already been loaded if(nicknames[username]===undefined) genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname && nickname !== "\r\n"){ call_all(sent[username], nicknames[username] = nickname); //doesn't have nickname }else nicknames[username] = false; sent[username] = undefined; }); else if(nicknames[username]){ call_all(sent[username], nicknames[username]); sent[username] = undefined; } },delay); } } } //this function can probably be improved addMessageEvent(function(message){ var username = message.dataset.username; var part = message.querySelector("message-part"); if(part){ var match = part.textContent.match(/^\[rpl23nick] (.*?)'s name is now (.*)/); if(match) nicknames[username] = match[2]; } if(username && !message.className){ get_nickname(username, function(nickname){ change_message_author(message, nickname); }); } }); function change_message_author(message, name){ if (name){ if (name.length > 40) name = name.substring(0,40); message.querySelector("figcaption").textContent = name; } } function write_persistent(name, value){ var data = new FormData(); data.append("name", name || "\n"); data.append("value", value); genericXHR("/query/submit/varstore?session=" + StorageUtilities.GetPHPSession(), data); } commands.push(new Command("nick",function(param){ var nickname = param.substring(1); if (nickname.length > 40) nickname = nickname.substring(0,40); nicknames[username] = nickname; write_persistent("nickname_tcf", nickname); sendMessage("[rpl23nick] " + username + "'s name is now " + nickname); })); commands.push(new Command("alias",function(param) { var result = ""; // noarg is intended to list all nicknames matches = param === "" ? Object.keys(nicknames).filter(key => nicknames[key] !== false && nicknames[key] !== "") : Object.keys(nicknames).filter(key => nicknames[key] === param) for(var user of matches) { result += user + " has nickname " + nicknames[user] + "\n"; } localModuleMessage(result); })); function roll(n){ //Rolls an n-sided die return (Math.random() * n | 0) + Math.sign(n); } commands.push(new Command("roll", function(param) { var n = Number.parseInt(param) || 20; var result = roll(n); var action; if(n==2){ action = "flipped a coin"; result = (result===1?"tails":"heads"); }else{ action = "rolled a d"+n; } sendMessage("[rpl23roll] "+nicknames[username]+" "+action+" and got "+result+"!"); })); Posted Edited by Y____
  • #74 ✎ 103 12Me21 Forum Moderator Night Person I like the quiet night and sleep late. Express Yourself (fixed /alias) nicknames table values: - undefined = unknown - other falsey value = no nickname set - other = nickname /* ***************** *\ |* Die/Name Commands *| \* ***************** */ window.nicknames={}; function time_until(time){ return Math.max(time-Date.now(), 0); } var last_request = Date.now(); function call_all(functions, arg){ for(var i=0;i<functions.length;i++) functions[i](arg); } var sent = {}; var get_nickname=function(username, callback){ //nickname unknown if(nicknames[username]!==undefined) callback(nicknames[username]); else{ //if request was already sent, and the response hasn't been recieved, add the callback to the list if(sent[username]){ sent[username].push(callback); }else{ sent[username]=[callback]; var delay = time_until(last_request + 100); last_request = Date.now() + delay; window.setTimeout(function(){ console.log("req"); //make sure name hasn't already been loaded if(nicknames[username]===undefined) genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname >= " " && nickname != "\r\n"){ call_all(sent[username], nicknames[username] = nickname); //doesn't have nickname }else nicknames[username] = false; sent[username] = undefined; }); else if(nicknames[username]){ call_all(sent[username], nicknames[username]); sent[username] = undefined; } },delay); } } } //this function can probably be improved addMessageEvent(function(message){ var username = message.dataset.username; var part = message.querySelector("message-part"); if(part){ var match = part.textContent.match(/^\[rpl2\dnick] (.*?)'s name is now (.*)/); if(match) nicknames[username] = match[2]; } if(username && !message.className){ get_nickname(username, function(nickname){ change_message_author(message, nickname); }); } }); function change_message_author(message, name){ if (name){ if (name.length > 40) name = name.substring(0,40); message.querySelector("figcaption").textContent = name; } } function write_persistent(name, value){ var data = new FormData(); data.append("name", name); data.append("value", value); genericXHR("/query/submit/varstore?session=" + StorageUtilities.GetPHPSession(), data); } commands.push(new Command("nick",function(param){ var nickname = param.substring(1); if (nickname.length > 40) nickname = nickname.substring(0,40); nicknames[username] = nickname; write_persistent("nickname_tcf", nickname || "\0"); sendMessage("[rpl24nick] " + username + "'s name is now " + nickname); })); commands.push(new Command("alias",function(param) { var result = ""; param = param.substring(1); for(var username in nicknames){ if(nicknames[username] && (!param || nicknames[username] === param)) result += username+" has nickname "+nicknames[username]+"\n"; } localModuleMessage(result); })); function roll(n){ //Rolls an n-sided die return (Math.random() * n | 0) + Math.sign(n); } commands.push(new Command("roll", function(param) { var n = Number.parseInt(param) || 20; var result = roll(n); var action; if(n==2){ action = "flipped a coin"; result = (result===1?"tails":"heads"); }else{ action = "rolled a d"+n; } sendMessage("[rpl24roll] "+nicknames[username]+" "+action+" and got "+result+"!"); })); Posted Edited by 12Me21
  • #75 ✎ 258 Y____ Head Admin Gardening I like to garden! Hobbies Reading I like to read books! Hobbies Drawing I like to draw! Hobbies add guard to roll name lookup /* ***************** *\ |* Die/Name Commands *| \* ***************** */ window.nicknames={}; function time_until(time){ return Math.max(time-Date.now(), 0); } var last_request = Date.now(); function call_all(functions, arg){ for(var i=0;i<functions.length;i++) functions[i](arg); } var sent = {}; var get_nickname=function(username, callback){ //nickname unknown if(nicknames[username]!==undefined) callback(nicknames[username]); else{ //if request was already sent, and the response hasn't been recieved, add the callback to the list if(sent[username]){ sent[username].push(callback); }else{ sent[username]=[callback]; var delay = time_until(last_request + 100); last_request = Date.now() + delay; window.setTimeout(function(){ console.log("req"); //make sure name hasn't already been loaded if(nicknames[username]===undefined) genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname >= " " && nickname != "\r\n"){ call_all(sent[username], nicknames[username] = nickname); //doesn't have nickname }else nicknames[username] = false; sent[username] = undefined; }); else if(nicknames[username]){ call_all(sent[username], nicknames[username]); sent[username] = undefined; } },delay); } } } //this function can probably be improved addMessageEvent(function(message){ var username = message.dataset.username; var part = message.querySelector("message-part"); if(part){ var match = part.textContent.match(/^\[rpl2\dnick] (.*?)'s name is now (.*)/); if(match) nicknames[username] = match[2]; } if(username && !message.className){ get_nickname(username, function(nickname){ change_message_author(message, nickname); }); } }); function change_message_author(message, name){ if (name){ if (name.length > 40) name = name.substring(0,40); message.querySelector("figcaption").textContent = name; } } function write_persistent(name, value){ var data = new FormData(); data.append("name", name); data.append("value", value); genericXHR("/query/submit/varstore?session=" + StorageUtilities.GetPHPSession(), data); } commands.push(new Command("nick",function(param){ var nickname = param.substring(1); if (nickname.length > 40) nickname = nickname.substring(0,40); nicknames[username] = nickname; write_persistent("nickname_tcf", nickname || "\0"); sendMessage("[rpl24nick] " + username + "'s name is now " + nickname); })); commands.push(new Command("alias",function(param) { var result = ""; param = param.substring(1); for(var username in nicknames){ if(nicknames[username] && (!param || nicknames[username] === param)) result += username+" has nickname "+nicknames[username]+"\n"; } localModuleMessage(result); })); function roll(n){ //Rolls an n-sided die return (Math.random() * n | 0) + Math.sign(n); } commands.push(new Command("roll", function(param) { var n = Number.parseInt(param) || 20; var result = roll(n); var action; if(n==2){ action = "flipped a coin"; result = (result===1?"tails":"heads"); }else{ action = "rolled a d"+n; } var name = username; if (nicknames[username] && nicknames[username] !== "") name = nicknames[username] sendMessage("[rpl24roll] "+name+" "+action+" and got "+result+"!"); })); Posted
  • #76 ✎ 103 12Me21 Forum Moderator Night Person I like the quiet night and sleep late. Express Yourself /* ***************** *\ |* Die/Name Commands *| \* ***************** */ window.nicknames={}; function time_until(time){ return Math.max(time-Date.now(), 0); } var last_request = Date.now(); function call_all(functions, arg){ for(var i=0;i<functions.length;i++) functions[i](arg); } var sent = {}; var get_nickname=function(username, callback){ //nickname unknown if(nicknames[username]!==undefined) callback(nicknames[username]); else{ //if request was already sent, and the response hasn't been recieved, add the callback to the list if(sent[username]){ sent[username].push(callback); }else{ sent[username]=[callback]; var delay = time_until(last_request + 100); last_request = Date.now() + delay; window.setTimeout(function(){ console.log("req"); //make sure name hasn't already been loaded if(nicknames[username]===undefined) genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname if(nickname >= " " && nickname != "\r\n"){ call_all(sent[username], nicknames[username] = nickname); //doesn't have nickname }else nicknames[username] = false; sent[username] = undefined; }); else if(nicknames[username]){ call_all(sent[username], nicknames[username]); sent[username] = undefined; } },delay); } } } //this function can probably be improved addMessageEvent(function(message){ var username = message.dataset.username; var part = message.querySelector("message-part"); if(part){ var match = part.textContent.match(/^\[rpl2\dnick] (.*?)'s name is now (.*)/); if(match) nicknames[username] = match[2]; } if(username && !message.className){ get_nickname(username, function(nickname){ change_message_author(message, nickname); }); } }); function change_message_author(message, name){ if (name){ if (name.length > 40) name = name.substring(0,40); message.querySelector("figcaption").textContent = name; } } function write_persistent(name, value){ genericXHRSimple("/query/submit/varstore?nameb64="+btoa(name)+"&valueb64="+btoa(value)+"&session=" + StorageUtilities.GetPHPSession(),function(){}); } commands.push(new Command("nick",function(param){ var nickname = param.substring(1); if (nickname.length > 40) nickname = nickname.substring(0,40); nicknames[username] = nickname; write_persistent("nickname_tcf", nickname || "\0"); sendMessage("[rpl25nick] " + username + "'s name is now " + nickname); })); commands.push(new Command("alias",function(param) { var result = ""; param = param.substring(1); for(var username in nicknames){ if(nicknames[username] && (!param || nicknames[username] === param)) result += username+" has nickname "+nicknames[username]+"\n"; } localModuleMessage(result); })); function roll(n){ //Rolls an n-sided die return (Math.random() * n | 0) + Math.sign(n); } commands.push(new Command("roll", function(param) { var n = Number.parseInt(param) || 20; var result = roll(n); var action; if(n==2){ action = "flipped a coin"; result = (result===1?"tails":"heads"); }else{ action = "rolled a d"+n; } sendMessage("[rpl25roll] "+(nicknames[username] || username)+" "+action+" and got "+result+"!"); })); Posted
  • #77 ✎ 103 12Me21 Forum Moderator Night Person I like the quiet night and sleep late. Express Yourself Update: now keeps rank tags /* ***************** *\ |* Die/Name Commands *| \* ***************** */ window.nicknames={}; function time_until(time){ return Math.max(time-Date.now(), 0); } var last_request = Date.now(); function call_all(functions, arg){ for(var i=0;i<functions.length;i++) functions[i](arg); } oldSendMessage = sendMessage sendMessage = function(message,addCommand){ message=getOrDefault(message,messageInput.value); addCommand=getOrDefault(addCommand,true); if(message.trim().length===0) return; var json={'type':'message','text':message,'key':auth,'tag':currentTag()}; commandList.push(message); polyChat.sendMessage(JSON.stringify(json)); if(!shouldScroll()) autoScroll(); }; function escape_name(name){ var out="" for(var i=0;i<name.length;i++){ console.log(i) var chr=name.charAt(i); if(chr=="\0" || chr>="\x7F" || chr=="%") out+=escape(chr); else out+=chr; } return out; } var sent = {}; var get_nickname=function(username, callback){ //nickname unknown if(nicknames[username]!==undefined) callback(nicknames[username]); else{ //if request was already sent, and the response hasn't been recieved, add the callback to the list if(sent[username]){ sent[username].push(callback); }else{ sent[username]=[callback]; var delay = time_until(last_request + 100); last_request = Date.now() + delay; window.setTimeout(function(){ console.log("req"); //make sure name hasn't already been loaded if(nicknames[username]===undefined) genericXHRSimple("/query/tinycomputerprograms?username="+username+"&program=nickname",function(nickname){ //has nickname nickname = unescape(nickname) if(nickname >= " " && nickname != "\r\n"){ call_all(sent[username], nicknames[username] = nickname); //doesn't have nickname }else nicknames[username] = false; sent[username] = undefined; }); else if(nicknames[username]){ call_all(sent[username], nicknames[username]); sent[username] = undefined; } },delay); } } } //this function can probably be improved addMessageEvent(function(message){ var username = message.dataset.username; var part = message.querySelector("message-part"); if(part){ var match = part.textContent.match(/^\[rpl[23]\dnick] (.*?)'s name is now (.*)/); if(match) nicknames[username] = match[2]; } if(username && !message.className){ get_nickname(username, function(nickname){ change_message_author(message, nickname); }); } }); function change_message_author(message, name){ if (name){ if (name.length > 40) name = name.substring(0,40); var label = message.querySelector("figcaption") label.firstChild.textContent = name; } } function write_persistent(name, value){ genericXHRSimple("/query/submit/varstore?nameb64="+btoa(name)+"&valueb64="+btoa(escape_name(value))+"&session=" + StorageUtilities.GetPHPSession(),function(a){ console.log(a); }); } commands.push(new Command("nick",function(param){ var nickname = param.substring(1); if (nickname.length > 40) nickname = nickname.substring(0,40); nicknames[username] = nickname; write_persistent("nickname_tcf", nickname || "\r\n"); sendMessage("[rpl29nick] " + username + "'s name is now " + nickname); })); commands.push(new Command("alias",function(param) { var result = ""; param = param.substring(1); for(var username in nicknames){ if(nicknames[username] && (!param || nicknames[username] === param)) result += username+" has nickname "+nicknames[username]+"\n"; } localModuleMessage(result); })); function roll(n){ //Rolls an n-sided die return (Math.random() * n | 0) + Math.sign(n); } commands.push(new Command("roll", function(param) { var n = Number.parseInt(param) || 20; var result = roll(n); var action; if(n==2){ action = "flipped a coin"; result = (result===1?"tails":"heads"); }else{ action = "rolled a d"+n; } sendMessage("[rpl25roll] "+(nicknames[username] || username)+" "+action+" and got "+result+"!"); })); Posted Edited by 12Me21
  • #78 ✎ 258 Y____ Head Admin Gardening I like to garden! Hobbies Reading I like to read books! Hobbies Drawing I like to draw! Hobbies function to_braille(numbers){ var id; if(/[fdsjkla;]/.test(numbers)) { id = [... numbers] .map(key => "fdsjkla;".indexOf(key)); } else { id = [... numbers] .map(key => "/85*9623".indexOf(key)); } id = id .filter(dot => dot>=0) .reduce((pattern,dot) => pattern | 1<<dot, 0); console.log(id); if(id || numbers=="") return String.fromCharCode(0x2800 + id); return "" } function asciitobraille(text){ return [...text.toUpperCase()] .map(chr=>" A1B'[email protected]/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)=".indexOf(chr)) .filter(id=>id>=0) .map(id=>String.fromCharCode(id+0x2800)) .join(""); } function brailletoascii(braille){ return [...braille] .map(chr=>chr.charCodeAt()-0x2800) .map(id=>" A1B'[email protected]/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)=".toLowerCase().charAt(id)) .join(""); } var contractions = [" 1"," 2"," 3"," 4","\\b5\\b"," 5"," 6"," 7"," 8"," 9","\\b0\\b", "#a","#b","#c","#d","#e","#f","#g","#h","#i","#j", ",n",",y","\\.d","\\.e","\\.n","\\.s","\\.t","\\^u","\\^!", "^\\?","\\^:","\\^w","_c","_h","_m","_s","_!","_w", ";e",";g",";l",";n",";s",";t",";y", "\\bb\\b","\\bc\\b","\\bd\\b","\\be\\b","\\bf\\b","\\bg\\b","\\bh\\b","\\bj\\b", "\\bk\\b","\\bl\\b","\\bm\\b","\\bn\\b","\\bp\\b","\\bq\\b","\\br\\b","\\bs\\b","\\bt\\b", "\\bu\\b","\\bv\\b","\\bx\\b","\\by\\b","\\bz\\b","\\b&\\b","\\b=\\b", "\\b\\*\\b","\\b%\\b","\\b\\?\\b","\\b:\\b","\\b\\\\b","\\bw\\b"]; var expansion = [" EA"," BE"," CON"," DIS","ENOUGH"," EN"," TO"," WERE"," HIS"," IN", "WAS", "#1","#2","#3","#4","#5","#6","#7","#8","#9","#0", "ATION","ALLY","OUND","ANCE","SION","LESS","OUNT","UPON","THESE", "THOSE","WHOSE","WORD","CANNOT","HAD","MANY","SPIRIT","THEIR","WORLD", "ENCE","ONG","FUL","TION","NESS","MENT","ITY", "BUT","CAN","DO","EVERY","FROM","GO","HAVE","JUST", "KNLG.","LIKE","MORE","NOT","PEOPLE","QUITE","RATHER","SO","THAT", "US","VERY","IT","YOU","AS","AND","FOR", "CHILD","SHALL","THIS","WHICH","OUT","WILL"]; //commands.push(new Command("8", window.braille = function(param) { var seqs = param.trim().split(/[\-\+\. ]/); var message = ""; seqs.forEach(function(numbers){message+=to_braille(numbers)}); message += "\n" + brailletoascii(message); for(i = 0; i < contractions.length; i++) { var contraction = new RegExp(contractions[i],"g"); message = message.replace(contraction,expansion[i].toLowerCase()); } sendMessage(message); }; onSubmitMessage.events.push(function (msg) { if(msg.value.substr(0,2)=="/-"||msg.value.substr(0,2)=="/;") { window.braille(msg.value.substr(2)); return true; } return false; }); Posted Edited by Y____
  • #79 ✎ 10 ShadowCX13 Avatar Taboo I didn't change my avatar for 180 days Website // Works like you'd expect. // Pressing tab multiple times goes down the list of possible choices // Also supports fixing @(partial username) as a special case. var userlist = document.getElementById("userpane"); var textarea = document.querySelector("#sendpane textarea"); var guessIdx = 0; var lastInp = ""; var mention = false; textarea.addEventListener("keydown", function(event){ if(event.code == "Tab" && textarea.selectionStart == textarea.selectionEnd){ event.preventDefault(); var idx = textarea.selectionStart; var users = slice.call(userlist.childNodes).map(node => node.dataset.username).join(" "); var inp = getWordRange(textarea.value, idx); if(lastInp === ""){ if(inp[2].replace(/\s+/g, "") == ""){ return; } lastInp = inp[2]; mention = lastInp[0] === "@"; if(mention) lastInp = lastInp.substr(1); } let ex = new RegExp("(" + lastInp + ")\\S*(?: |$)", "gi"); let matches = users.match(ex); if(matches == null) return; matches = matches.sort((a, b) => a.toLowerCase().indexOf(lastInp.toLowerCase()) - b.toLowerCase().indexOf(lastInp.toLowerCase())) let match = getWordRange(users, users.indexOf(matches[guessIdx++])); match = match[2]; guessIdx %= matches.length; textarea.value = (textarea.value.substring(0, inp[0]).trimRight() + (inp[0] == 0 ? "" : " ") + (mention ? "@" : "") + match + " " + textarea.value.substr(inp[1]).trimLeft()).trimRight(); textarea.selectionStart = textarea.selectionEnd = (inp[1] + (match.length - inp[3])) + (mention ? 1 : 0); } else { guessIdx = 0; lastInp = ""; } }); Posted
  • #80 ✎ 103 12Me21 Forum Moderator Night Person I like the quiet night and sleep late. Express Yourself var hotel_mario = document.createElement("audio"); hotel_mario.src="//12me21.github.io/external/headout.ogg"; addMessageEvent(function(messageElement){ if(messageElement.querySelector('img[src="/static_images/emotes/headout.png"]')){ hotel_mario.play() } }); Posted Edited by 12Me21
1 2 3 4 5