mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
Update for #14
This commit is contained in:
parent
b42c93a7a7
commit
669e4b5d99
11
client/README.md
Normal file
11
client/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
## Development
|
||||||
|
A quick way to start a server is to use Node.js `http-server`:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install http-server -g
|
||||||
|
cd client
|
||||||
|
http-server
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
(TODO)
|
@ -18,6 +18,7 @@ var frontpage = [
|
|||||||
"Formatting:",
|
"Formatting:",
|
||||||
"Whitespace is preserved, so source code can be pasted verbatim.",
|
"Whitespace is preserved, so source code can be pasted verbatim.",
|
||||||
"Surround LaTeX with a dollar sign for inline style $\\zeta(2) = \\pi^2/6$, and two dollars for display. $$\\int_0^1 \\int_0^1 \\frac{1}{1-xy} dx dy = \\frac{\\pi^2}{6}$$",
|
"Surround LaTeX with a dollar sign for inline style $\\zeta(2) = \\pi^2/6$, and two dollars for display. $$\\int_0^1 \\int_0^1 \\frac{1}{1-xy} dx dy = \\frac{\\pi^2}{6}$$",
|
||||||
|
"For syntax highlight, the first line of the code block must begin with #<format> where <format> can be html, js or any known format",
|
||||||
"",
|
"",
|
||||||
"Current Github: https://github.com/hack-chat includes server and client source along with other resources",
|
"Current Github: https://github.com/hack-chat includes server and client source along with other resources",
|
||||||
"",
|
"",
|
||||||
@ -35,13 +36,13 @@ function $(query) {
|
|||||||
function localStorageGet(key) {
|
function localStorageGet(key) {
|
||||||
try {
|
try {
|
||||||
return window.localStorage[key]
|
return window.localStorage[key]
|
||||||
} catch(e) {}
|
} catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
function localStorageSet(key, val) {
|
function localStorageSet(key, val) {
|
||||||
try {
|
try {
|
||||||
window.localStorage[key] = val
|
window.localStorage[key] = val
|
||||||
} catch(e) {}
|
} catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
var ws;
|
var ws;
|
||||||
@ -157,13 +158,13 @@ function pushMessage(args) {
|
|||||||
|
|
||||||
if (args.nick == myNick) {
|
if (args.nick == myNick) {
|
||||||
messageEl.classList.add('me');
|
messageEl.classList.add('me');
|
||||||
} else if (args.nick == '!') {
|
} else if (args.nick == '!') {
|
||||||
messageEl.classList.add('warn');
|
messageEl.classList.add('warn');
|
||||||
} else if (args.nick == '*') {
|
} else if (args.nick == '*') {
|
||||||
messageEl.classList.add('info');
|
messageEl.classList.add('info');
|
||||||
} else if (args.admin) {
|
} else if (args.admin) {
|
||||||
messageEl.classList.add('admin');
|
messageEl.classList.add('admin');
|
||||||
} else if (args.mod) {
|
} else if (args.mod) {
|
||||||
messageEl.classList.add('mod');
|
messageEl.classList.add('mod');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,15 +201,28 @@ function pushMessage(args) {
|
|||||||
textEl.textContent = args.text || '';
|
textEl.textContent = args.text || '';
|
||||||
textEl.innerHTML = textEl.innerHTML.replace(/(\?|https?:\/\/)\S+?(?=[,.!?:)]?\s|$)/g, parseLinks);
|
textEl.innerHTML = textEl.innerHTML.replace(/(\?|https?:\/\/)\S+?(?=[,.!?:)]?\s|$)/g, parseLinks);
|
||||||
|
|
||||||
if ($('#parse-latex').checked) {
|
if ($('#syntax-highlight').checked) {
|
||||||
|
if (textEl.textContent.indexOf('#') == 0) {
|
||||||
|
var lang = textEl.textContent.split(/\s+/g)[0].replace('#', '');
|
||||||
|
var codeEl = document.createElement('code');
|
||||||
|
codeEl.classList.add(lang);
|
||||||
|
var content = textEl.textContent.replace('#' + lang, '');
|
||||||
|
codeEl.textContent = content.trim();
|
||||||
|
hljs.highlightBlock(codeEl);
|
||||||
|
textEl.innerHTML = '';
|
||||||
|
textEl.appendChild(codeEl);
|
||||||
|
}
|
||||||
|
} else if ($('#parse-latex').checked) {
|
||||||
// Temporary hotfix for \rule spamming, see https://github.com/Khan/KaTeX/issues/109
|
// Temporary hotfix for \rule spamming, see https://github.com/Khan/KaTeX/issues/109
|
||||||
textEl.innerHTML = textEl.innerHTML.replace(/\\rule|\\\\\s*\[.*?\]/g, '');
|
textEl.innerHTML = textEl.innerHTML.replace(/\\rule|\\\\\s*\[.*?\]/g, '');
|
||||||
try {
|
try {
|
||||||
renderMathInElement(textEl, {delimiters: [
|
renderMathInElement(textEl, {
|
||||||
{ left: "$$", right: "$$", display: true },
|
delimiters: [
|
||||||
{ left: "$", right: "$", display: false },
|
{ left: "$$", right: "$$", display: true },
|
||||||
]})
|
{ left: "$", right: "$", display: false },
|
||||||
} catch (e) {
|
]
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,7 +303,7 @@ function updateTitle() {
|
|||||||
var title;
|
var title;
|
||||||
if (myChannel) {
|
if (myChannel) {
|
||||||
title = "?" + myChannel;
|
title = "?" + myChannel;
|
||||||
} else {
|
} else {
|
||||||
title = "hack.chat";
|
title = "hack.chat";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +335,7 @@ $('#chatinput').onkeydown = function (e) {
|
|||||||
|
|
||||||
updateInputSize();
|
updateInputSize();
|
||||||
}
|
}
|
||||||
} else if (e.keyCode == 38 /* UP */) {
|
} else if (e.keyCode == 38 /* UP */) {
|
||||||
// Restore previous sent messages
|
// Restore previous sent messages
|
||||||
if (e.target.selectionStart === 0 && lastSentPos < lastSent.length - 1) {
|
if (e.target.selectionStart === 0 && lastSentPos < lastSent.length - 1) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -355,7 +369,7 @@ $('#chatinput').onkeydown = function (e) {
|
|||||||
lastSent[lastSentPos] = "";
|
lastSent[lastSentPos] = "";
|
||||||
|
|
||||||
updateInputSize();
|
updateInputSize();
|
||||||
} else if (e.keyCode == 9 /* TAB */) {
|
} else if (e.keyCode == 9 /* TAB */) {
|
||||||
// Tab complete nicknames starting with @
|
// Tab complete nicknames starting with @
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -522,7 +536,19 @@ var schemes = [
|
|||||||
'tomorrow'
|
'tomorrow'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var highlights = [
|
||||||
|
'agate',
|
||||||
|
'androidstudio',
|
||||||
|
'darcula',
|
||||||
|
'github',
|
||||||
|
'rainbow',
|
||||||
|
'tomorrow',
|
||||||
|
'xcode',
|
||||||
|
'zenburn'
|
||||||
|
]
|
||||||
|
|
||||||
var currentScheme = 'atelier-dune';
|
var currentScheme = 'atelier-dune';
|
||||||
|
var currentHighlight = 'darcula';
|
||||||
|
|
||||||
function setScheme(scheme) {
|
function setScheme(scheme) {
|
||||||
currentScheme = scheme;
|
currentScheme = scheme;
|
||||||
@ -530,6 +556,12 @@ function setScheme(scheme) {
|
|||||||
localStorageSet('scheme', scheme);
|
localStorageSet('scheme', scheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setHighlight(scheme) {
|
||||||
|
currentHighlight = scheme;
|
||||||
|
$('#highlight-link').href = "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/" + scheme + ".min.css";
|
||||||
|
localStorageSet('highlight', scheme);
|
||||||
|
}
|
||||||
|
|
||||||
// Add scheme options to dropdown selector
|
// Add scheme options to dropdown selector
|
||||||
schemes.forEach(function (scheme) {
|
schemes.forEach(function (scheme) {
|
||||||
var option = document.createElement('option');
|
var option = document.createElement('option');
|
||||||
@ -538,16 +570,32 @@ schemes.forEach(function (scheme) {
|
|||||||
$('#scheme-selector').appendChild(option);
|
$('#scheme-selector').appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
highlights.forEach(function (scheme) {
|
||||||
|
var option = document.createElement('option');
|
||||||
|
option.textContent = scheme;
|
||||||
|
option.value = scheme;
|
||||||
|
$('#highlight-selector').appendChild(option);
|
||||||
|
});
|
||||||
|
|
||||||
$('#scheme-selector').onchange = function (e) {
|
$('#scheme-selector').onchange = function (e) {
|
||||||
setScheme(e.target.value);
|
setScheme(e.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#highlight-selector').onchange = function (e) {
|
||||||
|
setHighlight(e.target.value);
|
||||||
|
}
|
||||||
|
|
||||||
// Load sidebar configaration values from local storage if available
|
// Load sidebar configaration values from local storage if available
|
||||||
if (localStorageGet('scheme')) {
|
if (localStorageGet('scheme')) {
|
||||||
setScheme(localStorageGet('scheme'));
|
setScheme(localStorageGet('scheme'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (localStorageGet('highlight')) {
|
||||||
|
setHighlight(localStorageGet('highlight'));
|
||||||
|
}
|
||||||
|
|
||||||
$('#scheme-selector').value = currentScheme;
|
$('#scheme-selector').value = currentScheme;
|
||||||
|
$('#highlight-selector').value = currentHighlight;
|
||||||
|
|
||||||
/* main */
|
/* main */
|
||||||
|
|
||||||
@ -557,4 +605,4 @@ if (myChannel == '') {
|
|||||||
$('#sidebar').classList.add('hidden');
|
$('#sidebar').classList.add('hidden');
|
||||||
} else {
|
} else {
|
||||||
join(myChannel);
|
join(myChannel);
|
||||||
}
|
}
|
@ -1 +1,62 @@
|
|||||||
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1"><meta charset="utf-8"><title>hack.chat</title><link rel="stylesheet" href="style.css"><link rel="stylesheet" href="katex/katex.min.css"><link id="scheme-link" rel="stylesheet" href="schemes/atelier-dune.css"><script src="katex/katex.min.js"></script><script src="katex/contrib/auto-render.min.js"></script></head><body><article class="container"><div id="messages" class="messages"></div></article><footer id="footer"><div class="container"><form id="chatform" class="messages"><textarea id="chatinput" type="text" autocomplete="off" autofocus></textarea></form></div></footer><nav id="sidebar"><div id="sidebar-content" class="hidden"><p><input id="pin-sidebar" type="checkbox"><label for="pin-sidebar">Pin sidebar</label></p><h4>Settings</h4><p><input id="joined-left" type="checkbox" checked><label for="joined-left">Join/left notify</label></p><p><input id="parse-latex" type="checkbox" checked><label for="parse-latex">Parse LaTeX</label></p><p><button id="clear-messages">Clear messages</button></p><h4>Color scheme</h4><select id="scheme-selector"></select><h4>Users online</h4><p>(Click user to invite)</p><ul id="users"></ul></div></nav><script src="client.js"></script></body></html>
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>hack.chat</title>
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
<link rel="stylesheet" href="katex/katex.min.css">
|
||||||
|
<link id="scheme-link" rel="stylesheet" href="schemes/atelier-dune.css">
|
||||||
|
<script src="katex/katex.min.js"></script>
|
||||||
|
<script src="katex/contrib/auto-render.min.js"></script>
|
||||||
|
<link id="highlight-link" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/hybrid.min.css">
|
||||||
|
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<article class="container">
|
||||||
|
<div id="messages" class="messages"></div>
|
||||||
|
</article>
|
||||||
|
<footer id="footer">
|
||||||
|
<div class="container">
|
||||||
|
<form id="chatform" class="messages">
|
||||||
|
<textarea id="chatinput" type="text" autocomplete="off" autofocus></textarea>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
<nav id="sidebar">
|
||||||
|
<div id="sidebar-content" class="hidden">
|
||||||
|
<p>
|
||||||
|
<input id="pin-sidebar" type="checkbox">
|
||||||
|
<label for="pin-sidebar">Pin sidebar</label>
|
||||||
|
</p>
|
||||||
|
<h4>Settings</h4>
|
||||||
|
<p>
|
||||||
|
<input id="joined-left" type="checkbox" checked>
|
||||||
|
<label for="joined-left">Join/left notify</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input id="parse-latex" type="checkbox" checked>
|
||||||
|
<label for="parse-latex">Parse LaTeX</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<button id="clear-messages">Clear messages</button>
|
||||||
|
</p>
|
||||||
|
<h4>Color scheme</h4>
|
||||||
|
<select id="scheme-selector"></select>
|
||||||
|
<p>
|
||||||
|
<input id="syntax-highlight" type="checkbox" checked>
|
||||||
|
<label for="syntax-highlight">Syntax Highlight</label>
|
||||||
|
</p>
|
||||||
|
<h4>Highlight scheme</h4>
|
||||||
|
<select id="highlight-selector"></select>
|
||||||
|
<h4>Users online</h4>
|
||||||
|
<p>(Click user to invite)</p>
|
||||||
|
<ul id="users"></ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<script src="client.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user