7 changed files with 198 additions and 187 deletions
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
{ |
||||
"plugins": { |
||||
"es_modules": {} |
||||
}, |
||||
"libs": [ |
||||
"ecma5", |
||||
"ecma6" |
||||
], |
||||
"ecmaVersion": 6 |
||||
} |
||||
@ -1,73 +1,73 @@
@@ -1,73 +1,73 @@
|
||||
var $ = function(id) { |
||||
return document.getElementById(id); |
||||
} |
||||
var iosDetected = navigator.userAgent.match("(iPad|iPod|iPhone)"); |
||||
return document.getElementById(id); |
||||
}; |
||||
var iosDetected = navigator.userAgent.match('(iPad|iPod|iPhone)'); |
||||
var timer = null; |
||||
var timerDelay = iosDetected ? 800 : 400; |
||||
var $note, $action, $preview, $plain_password, $tableau; |
||||
var backendTimer; |
||||
|
||||
document.addEventListener('DOMContentLoaded', function () { |
||||
marked.setOptions({ |
||||
langPrefix: 'hljs lang-', |
||||
highlight: function (code) { |
||||
return hljs.highlightAuto(code).value; |
||||
}, |
||||
}); |
||||
marked.setOptions({ |
||||
langPrefix: 'hljs lang-', |
||||
highlight: function (code) { |
||||
return hljs.highlightAuto(code).value; |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
function md2html(input) { |
||||
return marked(input); |
||||
return marked(input); |
||||
} |
||||
|
||||
function saveDraft() { |
||||
if ($action == "UPDATE") return; |
||||
console.log("draft autosave..."); |
||||
$tableau.innerHTML = "Draft autosaved." |
||||
localStorage.setItem("draft", $note.value); |
||||
if ($action == 'UPDATE') return; |
||||
console.log('draft autosave...'); |
||||
$tableau.innerHTML = 'Draft autosaved.'; |
||||
localStorage.setItem('draft', $note.value); |
||||
} |
||||
|
||||
function enableButton() { |
||||
var checkbox = $('tos'); |
||||
var button = $('publish-button'); |
||||
button.disabled = !checkbox.checked; |
||||
var checkbox = $('tos'); |
||||
var button = $('publish-button'); |
||||
button.disabled = !checkbox.checked; |
||||
} |
||||
|
||||
function onLoad() { |
||||
$note = $("note"); |
||||
$action = $("action").value; |
||||
$preview = $("draft"); |
||||
$tableau = $("tableau"); |
||||
$plain_password = $("plain-password"); |
||||
var updatePreview = function() { |
||||
clearTimeout(timer); |
||||
var content = $note.value; |
||||
var delay = Math.min(timerDelay, timerDelay * (content.length / 400)); |
||||
timer = setTimeout(function() { |
||||
$preview.innerHTML = md2html(content); |
||||
$tableau.innerHTML = content.split(/\s+/).length + " words"; |
||||
}, delay); |
||||
}; |
||||
if ($action == "UPDATE") updatePreview(); |
||||
else { |
||||
$("delete-button").style.display = "none"; |
||||
$note.value = ""; |
||||
var draft = localStorage.getItem("draft"); |
||||
if (draft) { |
||||
$note.value = draft; |
||||
updatePreview(); |
||||
$note = $('note'); |
||||
$action = $('action').value; |
||||
$preview = $('draft'); |
||||
$tableau = $('tableau'); |
||||
$plain_password = $('plain-password'); |
||||
var updatePreview = function() { |
||||
clearTimeout(timer); |
||||
var content = $note.value; |
||||
var delay = Math.min(timerDelay, timerDelay * (content.length / 400)); |
||||
timer = setTimeout(function() { |
||||
$preview.innerHTML = md2html(content); |
||||
$tableau.innerHTML = content.split(/\s+/).length + ' words'; |
||||
}, delay); |
||||
}; |
||||
if ($action == 'UPDATE') updatePreview(); |
||||
else { |
||||
$('delete-button').style.display = 'none'; |
||||
$note.value = ''; |
||||
var draft = localStorage.getItem('draft'); |
||||
if (draft) { |
||||
$note.value = draft; |
||||
updatePreview(); |
||||
} |
||||
} |
||||
} |
||||
$note.onkeyup = updatePreview; |
||||
$("delete-button").onclick = $("publish-button").onclick = function(e) { |
||||
localStorage.removeItem("draft"); |
||||
self.onbeforeunload = null; |
||||
if ($plain_password.value != "") $("password").value = md5($plain_password.value); |
||||
$plain_password.value = null; |
||||
$("signature").value = md5($("session").value + $note.value.replace(/[\n\r]/g, "")); |
||||
}; |
||||
if (iosDetected) $note.className += " ui-border"; |
||||
else $note.focus(); |
||||
self.onbeforeunload = saveDraft; |
||||
setInterval(saveDraft, 60 * 1000) |
||||
$note.onkeyup = updatePreview; |
||||
$('delete-button').onclick = $('publish-button').onclick = function(e) { |
||||
localStorage.removeItem('draft'); |
||||
self.onbeforeunload = null; |
||||
if ($plain_password.value !== '') $('password').value = md5($plain_password.value); |
||||
$plain_password.value = null; |
||||
$('signature').value = md5($('session').value + $note.value.replace(/[\n\r]/g, '')); |
||||
}; |
||||
if (iosDetected) $note.className += ' ui-border'; |
||||
else $note.focus(); |
||||
self.onbeforeunload = saveDraft; |
||||
setInterval(saveDraft, 60 * 1000); |
||||
} |
||||
|
||||
@ -1,55 +1,55 @@
@@ -1,55 +1,55 @@
|
||||
var marked = require("marked"); |
||||
var fs = require("fs"); |
||||
var hljs = require("highlight.js"); |
||||
var marked = require('marked'); |
||||
var fs = require('fs'); |
||||
var hljs = require('highlight.js'); |
||||
|
||||
var TOS = fs.readFileSync("resources/TOS.md", "utf-8"); |
||||
var pageTemplate = fs.readFileSync("resources/template.html", "utf-8"); |
||||
var footerTemplate = fs.readFileSync("resources/footer.html", "utf-8"); |
||||
var editTemplate = fs.readFileSync("resources/edit.html", "utf-8"); |
||||
var header = fs.readFileSync(process.env.HEADER || "/dev/null", "utf-8"); |
||||
var TOS = fs.readFileSync('resources/TOS.md', 'utf-8'); |
||||
var pageTemplate = fs.readFileSync('resources/template.html', 'utf-8'); |
||||
var footerTemplate = fs.readFileSync('resources/footer.html', 'utf-8'); |
||||
var editTemplate = fs.readFileSync('resources/edit.html', 'utf-8'); |
||||
var header = fs.readFileSync(process.env.HEADER || '/dev/null', 'utf-8'); |
||||
|
||||
var deriveTitle = text => text |
||||
.split(/[\n\r]/)[0].slice(0,25) |
||||
.replace(/[`~!@#\$%^&\*_|\+=\?;:'",.<>\{\}\\\/]/g, ""); |
||||
.split(/[\n\r]/)[0].slice(0,25) |
||||
.replace(/[`~!@#\$%^&\*_|\+=\?;:'",.<>\{\}\\\/]/g, ''); |
||||
|
||||
var renderPage = (id, title, content, footer, blackList) => pageTemplate |
||||
.replace("%HEADER%", blackList && blackList.has(id) ? header : "") |
||||
.replace("%TITLE%", title) |
||||
.replace("%CONTENT%", content.replace(/<meta.*?>/gi, "").replace(/<script[\s\S.]*?\/script>/gi, "")) |
||||
.replace("%FOOTER%", footer || ""); |
||||
.replace('%HEADER%', blackList && blackList.has(id) ? header : '') |
||||
.replace('%TITLE%', title) |
||||
.replace('%CONTENT%', content.replace(/<meta.*?>/gi, '').replace(/<script[\s\S.]*?\/script>/gi, '')) |
||||
.replace('%FOOTER%', footer || ''); |
||||
|
||||
marked.setOptions({ |
||||
langPrefix: "hljs lang-", |
||||
highlight: code => hljs.highlightAuto(code).value, |
||||
langPrefix: 'hljs lang-', |
||||
highlight: code => hljs.highlightAuto(code).value, |
||||
}); |
||||
|
||||
module.exports.renderPage = renderPage; |
||||
|
||||
module.exports.renderStats = note => renderPage(note.id, deriveTitle(note.text), |
||||
`<h2>Statistics</h2>
|
||||
`<h2>Statistics</h2>
|
||||
<table> |
||||
<tr><td>Published</td><td>${note.published}</td></tr> |
||||
<tr><td>Edited</td><td>${note.edited || "N/A"}</td></tr> |
||||
<tr><td>Edited</td><td>${note.edited || 'N/A'}</td></tr> |
||||
<tr><td>Views</td><td>${note.views}</td></tr> |
||||
</table>`); |
||||
|
||||
module.exports.renderTOS = () => renderPage("tos", "Terms of Service", marked(TOS)); |
||||
module.exports.renderTOS = () => renderPage('tos', 'Terms of Service', marked(TOS)); |
||||
|
||||
module.exports.renderNote = (note, blackList) => renderPage(note.id, |
||||
deriveTitle(note.text), |
||||
marked(note.text), |
||||
footerTemplate.replace(/%LINK%/g, note.id), |
||||
blackList); |
||||
deriveTitle(note.text), |
||||
marked(note.text), |
||||
footerTemplate.replace(/%LINK%/g, note.id), |
||||
blackList); |
||||
|
||||
module.exports.newNotePage = session => editTemplate |
||||
.replace("%ACTION%", "POST") |
||||
.replace("%SESSION%", session) |
||||
.replace("%CONTENT%", "Loading..."); |
||||
.replace('%ACTION%', 'POST') |
||||
.replace('%SESSION%', session) |
||||
.replace('%CONTENT%', 'Loading...'); |
||||
|
||||
module.exports.editNotePage = (session, note) => editTemplate |
||||
.replace("%ACTION%", "UPDATE") |
||||
.replace("%SESSION%", session) |
||||
.replace("%ID%", note.id) |
||||
.replace("%CONTENT%", escape$(note.text)); |
||||
.replace('%ACTION%', 'UPDATE') |
||||
.replace('%SESSION%', session) |
||||
.replace('%ID%', note.id) |
||||
.replace('%CONTENT%', escape$(note.text)); |
||||
|
||||
var escape$ = s => s.split("").map(chr => chr == "$" ? "$$" : chr).join(""); |
||||
var escape$ = s => s.split('').map(chr => chr == '$' ? '$$' : chr).join(''); |
||||
|
||||
Loading…
Reference in new issue