Skip to content

Commit

Permalink
闲着也是闲着
Browse files Browse the repository at this point in the history
  • Loading branch information
Kroos372 committed Nov 14, 2023
1 parent b2fcacc commit 8cc6f08
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 35 deletions.
48 changes: 31 additions & 17 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ $("#close-channel").onclick = function() {
}
$("#users-change").onchange = function(e) {
var channel = e.target.value;
if (actAnnel == channel) return;
usersPrint(channel);
}
$("#channel-color").onclick = function(e) {
Expand Down Expand Up @@ -631,6 +630,7 @@ var COMMANDS = {
customHistory[customId].push(newText);

var atBottom = isAtBottom();
message.text = newText;
message.ele.innerHTML = md.render(verifyLatex(newText));
message.ele.ondblclick = function() {
copy(customHistory[customId].join("\n"));
Expand All @@ -639,11 +639,10 @@ var COMMANDS = {
}
}
function pushMessage(args) {
var text = lastMsg = args.text;
var text = lastMsg = args.text, customId = args.customId;
// 消息节点
var messageEl = document.createElement("div");
messageEl.classList.add("message");

// 频道
if (args.channel) {
if (args.nick && isShielded(args.channel, args.nick)) return;
Expand Down Expand Up @@ -692,6 +691,12 @@ function pushMessage(args) {
tripEl.title = args.hash;
tripEl.onclick = function () {
copy(args.hash);
};
tripEl.ondblclick = function() {
if (args.channel && channels[channel]) {
$("#users-change").value = channel;
usersPrint(channel);
}
}
}
if (args.nick) {
Expand All @@ -718,8 +723,17 @@ function pushMessage(args) {
moveMenu(e, $("#msg-ctm"));
choiced.ele = messageEl;
choiced.nick = args.nick + "#" + (args.trip || "");
choiced.text = text;
choiced.channel = args.channel;
if (typeof (customId) === "string") {
for (let i of customMsg) {
if (i.customId === customId) {
choiced.text = i.text;
break;
}
}
} else {
choiced.text = text;
}
}
}

Expand All @@ -733,7 +747,7 @@ function pushMessage(args) {
var textEl = document.createElement("p");
textEl.classList.add("text");
textEl.classList.add("fold");
textEl.innerHTML = md.render(verifyLatex(text))
textEl.innerHTML = md.render(verifyLatex(text));

textEl.onclick = function(e) {
if (document.getSelection().toString()) return;
Expand All @@ -744,9 +758,9 @@ function pushMessage(args) {
}
}
// 最讨厌的一集
if (typeof (args.customId) === "string") {
addCustom(args.customId, args.userid, text, textEl);
textEl.setAttribute("cusId", args.customId);
if (typeof (customId) === "string") {
addCustom(customId, args.userid, text, textEl);
textEl.setAttribute("cusId", customId);
}

messageEl.appendChild(textEl);
Expand Down Expand Up @@ -860,14 +874,15 @@ $("#chatinput").onkeydown = function(e) {
e.stopPropagation();
}
updateInputSize();
function mainpage() {
if (ws && ws.readyState == ws.OPEN) {
ws.send(JSON.stringify({ cmd: "session" }));
}
}


if (actAnnel == "") {
var ws = new WebSocket("wss://hack.chat/chat-ws");
ws.onopen = function (){
if (ws && ws.readyState == ws.OPEN) {
ws.send(JSON.stringify({cmd: "session"}));
}
};
ws.onmessage = function(message) {
var result = JSON.parse(message.data);
var rooms = result.public;
Expand All @@ -878,16 +893,15 @@ if (actAnnel == "") {
string += "| ?" + keys[i] + "|" + rooms[keys[i]];
if (i % 2) {
string += "|";
frontpage.splice(14 + i / 2, 0, string);
frontpageH.push(string);
string = "";
}
}
frontpage = frontpage.join("\n");
pushMessage({ text: frontpage, hash: "Qm9jY2hpQ2hhbg", change: "info" });
var frontpage = frontpageH.concat(frontpageF).join("\n");
pushMessage({text: frontpage, hash: "Qm9jY2hpQ2hhbg", change: "info" });
$(".text").classList.remove("fold");
}
}
ws.onopen = mainpage;
} else {
var nick = location.hash.slice(1);
join(actAnnel, nick);
Expand Down
44 changes: 26 additions & 18 deletions others.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,30 @@ function mobileJudge(){
return false;
}
// 常量
const allow = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_".split("");
const allow = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789".split("");
const holders = [
"发送一条友善的消息~",
"按/可以快速聚焦哦",
"明明什么都没做,就已经hour点了..."
];
var frontpage = [
" _ _ _ _ ",
" | |_ ___ ___| |_ ___| |_ ___| |_ ",
" | |_ || _| '_| | _| |_ || _|",
" |_|_|__/|___|_,_|.|___|_|_|__/|_| ",
var frontpageH = [
"┏┓━━━━━━━━━━━┏┓━━━━━━━━┏┓━━━━━━━━┏┓━",
"┃┃━━━━━━━━━━━┃┃━━━━━━━━┃┃━━━━━━━┏┛┗┓",
"┃┗━┓┏━━┓━┏━━┓┃┃┏┓━━┏━━┓┃┗━┓┏━━┓━┗┓┏┛",
"┃┏┓┃┗━┓┃━┃┏━┛┃┗┛┛━━┃┏━┛┃┏┓┃┗━┓┃━━┃┃━",
"┃┃┃┃┃┗┛┗┓┃┗━┓┃┏┓┓┏┓┃┗━┓┃┃┃┃┃┗┛┗┓━┃┗┓",
"┗┛┗┛┗━━━┛┗━━┛┗┛┗┛┗┛┗━━┛┗┛┗┛┗━━━┛━┗━┛",
" ",
"欢迎来到——哪?一个基于[hack.chat](https://hack.chat/)改编,简洁(并不)、无干扰的聊天程序客户端。",
"频道通过网址创建、加入或分享,通过改变问号后面的文字来创建你自己的频道。",
"如果你想让你的频道叫做“your-channel”: " + location.href + "?your-channel",
"这里不会显示频道列表,因此你可以使用秘密频道名称进行私人讨论。",
" ",
"欢迎来到hack.chat,一个简洁、无干扰的聊天程序。",
"频道是通过网址创建、加入和分享的,通过改变问号后面的文字来创建你自己的频道。",
"如果你想让你的频道叫做“your-channel”: https://hack.chat/?your-channel",
"这里没有频道列表,因此你可以使用秘密频道名称进行私人讨论。",
" ",
"以下是一些你可以加入的预制频道:",
"以下是一些可供加入的预制频道:",
"|名称|人数|名称|人数|",
"|:-:|:-:|:-:|:-:|", // 13
"|:-:|:-:|:-:|:-:|"
];
var frontpageF = [
"| ?kt1j8rpc | \\ | ?your-channel | \\ |",
"并且这里有一个仅为你准备的秘密频道: ?" + Math.random().toString(36).substr(2, 8),
" ",
Expand All @@ -221,12 +224,15 @@ var frontpage = [
" ",
"当前的GitHub: https://github.com/hack-chat",
"过去的GitHub: https://github.com/AndrewBelt/hack.chat",
"此客户端的GitHub:https://github.com/Kroos372/whitechat",
" ",
"机器人、安卓客户端、桌面客户端、浏览器扩展、docker images、编程库、服务器模块等等:",
"https://github.com/hack-chat/3rd-party-software-list",
"此聊天室的历史与基本功能介绍:",
"https://hcwiki.netlify.app/",
" ",
"服务端和客户端在WTFPL和MIT开源许可下发布,",
"hack.chat服务器上不保留任何历史记录。"
"Hack.chat*服务器*上不保留任何历史记录。"
];
var help = [
"# 恭喜你发现这个隐藏的帮助⭐",
Expand All @@ -235,7 +241,8 @@ var help = [
"|-|-|",
"|/setbg|设置背景图|",
"|点击识别码(或名字左边的空格)|复制hash|",
"|双击消息|复制该消息的历史记录(如果有的话)|"
"|双击识别码|切换至该频道|",
"|双击消息|复制该消息的历史记录|"
].join("\n");
var imgWhites = [];
const isMobile = mobileJudge();
Expand Down Expand Up @@ -484,6 +491,7 @@ function userEle(channel, args) {
}
}
function usersPrint(channel) {
if (actAnnel == channel) return;
var onlines = channels[channel].onlines;
if (onlyRead) {
hideOthers(channel);
Expand Down Expand Up @@ -784,16 +792,16 @@ function randomColor() {
// 随机昵称
function randomNick() {
var nick = "";
for (var i = 0; i < 24; i++){
for (var i = 0; i < randint(1, 25); i++){
nick += choice(allow);
}
return nick;
}
// 随机costom id
function randomCustom() {
var result = "";
for (var i = 0; i < randint(1, 7); i++) {
result += String.fromCharCode(randint(32, 999999999999));
for (var i = 0; i < 6; i++) {
result += choice(allow);
}
return result;
}
Expand Down

0 comments on commit 8cc6f08

Please sign in to comment.