Skip to content

Commit 89329fc

Browse files
committed
snippet v1.0
1 parent 1b8dfd5 commit 89329fc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

snippet.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// MIT license, see: https://github.com/tjcrowder/simple-snippets-console/blob/master/LICENSE
2+
var snippet = {
3+
version: "1.0",
4+
5+
// Writes out the given text in a monospaced paragraph tag, escaping
6+
// & and < so they aren't rendered as HTML.
7+
log: function(msg) {
8+
if (Object.prototype.toString.call(msg) === "[object Array]") {
9+
msg = msg.join();
10+
} else if (typeof object === "object") {
11+
msg = msg === null ? "null" : JSON.stringify(msg);
12+
}
13+
document.body.insertAdjacentHTML(
14+
'beforeend',
15+
'<p style="font-family: monospace; margin: 2px 0 2px 0">' +
16+
msg.replace(/&/g, '&amp;').replace(/</g, '&lt;') +
17+
'</p>'
18+
);
19+
},
20+
21+
// Writes out the given HTML at the end of the body,
22+
// exactly as-is
23+
logHTML: function(html) {
24+
document.body.insertAdjacentHTML("beforeend", html);
25+
}
26+
};

0 commit comments

Comments
 (0)