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