Skip to main content
added 117 characters in body
Source Link
T.J. Crowder
  • 23k
  • 7
  • 55
  • 103
  1. Best to leave the actual console alone, not least because interfering with it can prevent asking and answering questions related to the console (such as when and how data is expanded on V8's console, which is a non-trivial thing).

  2. Snippets definitely need a built-in, simple means of generating output without promoting poor practices like document.write.

  3. Specific suggestion for what to provide below, including a version hosted on GitHub Pagesa version hosted on GitHub Pages (they've discontinued that URL, though the project is still there) for use until/unless Snippets have their own way.

I've made a version available here on GitHub Pageshere on GitHub Pages (they've discontinued that URL) for use until snippets have their own way of doing it. Feel free to insert that at the top of a snippet like this:

  1. Best to leave the actual console alone, not least because interfering with it can prevent asking and answering questions related to the console (such as when and how data is expanded on V8's console, which is a non-trivial thing).

  2. Snippets definitely need a built-in, simple means of generating output without promoting poor practices like document.write.

  3. Specific suggestion for what to provide below, including a version hosted on GitHub Pages for use until/unless Snippets have their own way.

I've made a version available here on GitHub Pages for use until snippets have their own way of doing it. Feel free to insert that at the top of a snippet like this:

  1. Best to leave the actual console alone, not least because interfering with it can prevent asking and answering questions related to the console (such as when and how data is expanded on V8's console, which is a non-trivial thing).

  2. Snippets definitely need a built-in, simple means of generating output without promoting poor practices like document.write.

  3. Specific suggestion for what to provide below, including a version hosted on GitHub Pages (they've discontinued that URL, though the project is still there) for use until/unless Snippets have their own way.

I've made a version available here on GitHub Pages (they've discontinued that URL) for use until snippets have their own way of doing it. Feel free to insert that at the top of a snippet like this:

Bounty Ended with 500 reputation awarded by Josh Crozier
Bounty Ended with 500 reputation awarded by canon
Bounty Ended with 500 reputation awarded by canon
Bounty Ended with 500 reputation awarded by canon
Fix stoopid bug in snippet.js, and use a text node, not string replacement
Source Link
T.J. Crowder
  • 23k
  • 7
  • 55
  • 103
// MIT license, see: https://github.com/tjcrowder/simple-snippets-console/blob/master/LICENSE
var snippet = {
    version: "1.1"3",

    // Writes out the given text in a monospaced paragraph tag, escaping
    // & and < so they aren't rendered as HTML.
    log: function(msg, tag) {
        var elm = document.createElement(tag || "p");
        elm.style.fontFamily = "monospace";
        elm.style.margin = "2px 0 2px 0";
        if (Object.prototype.toString.call(msg) === "[object Array]") {
            msg = msg.join();
        } else if (typeof objectmsg === "object") {
            msg = msg === null ? "null" : JSON.stringify(msg);
        } else {
            msg = String(msg);
        }
        elm.innerHTML = msg.replaceappendChild(/&/g, '&amp;')document.replacecreateTextNode(/</g, '&lt;'msg));
        document.body.appendChild(elm);
    },

    // Writes out the given HTML at the end of the body,
    // exactly as-is
    logHTML: function(html) {
        document.body.insertAdjacentHTML("beforeend", html);
    }
};
// MIT license, see: https://github.com/tjcrowder/simple-snippets-console/blob/master/LICENSE
var snippet = {
    version: "1.1",

    // Writes out the given text in a monospaced paragraph tag, escaping
    // & and < so they aren't rendered as HTML.
    log: function(msg, tag) {
        var elm = document.createElement(tag || "p");
        elm.style.fontFamily = "monospace";
        elm.style.margin = "2px 0 2px 0";
        if (Object.prototype.toString.call(msg) === "[object Array]") {
            msg = msg.join();
        } else if (typeof object === "object") {
            msg = msg === null ? "null" : JSON.stringify(msg);
        } else {
            msg = String(msg);
        }
        elm.innerHTML = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;');
        document.body.appendChild(elm);
    },

    // Writes out the given HTML at the end of the body,
    // exactly as-is
    logHTML: function(html) {
        document.body.insertAdjacentHTML("beforeend", html);
    }
};
// MIT license, see: https://github.com/tjcrowder/simple-snippets-console/blob/master/LICENSE
var snippet = {
    version: "1.3",

    // Writes out the given text in a monospaced paragraph tag, escaping
    // & and < so they aren't rendered as HTML.
    log: function(msg, tag) {
        var elm = document.createElement(tag || "p");
        elm.style.fontFamily = "monospace";
        elm.style.margin = "2px 0 2px 0";
        if (Object.prototype.toString.call(msg) === "[object Array]") {
            msg = msg.join();
        } else if (typeof msg === "object") {
            msg = msg === null ? "null" : JSON.stringify(msg);
        }
        elm.appendChild(document.createTextNode(msg));
        document.body.appendChild(elm);
    },

    // Writes out the given HTML at the end of the body,
    // exactly as-is
    logHTML: function(html) {
        document.body.insertAdjacentHTML("beforeend", html);
    }
};
Bounty Ended with 500 reputation awarded by canon
update to v1.1 of the temporary(??) script
Source Link
T.J. Crowder
  • 23k
  • 7
  • 55
  • 103
// MIT license, see: https://github.com/tjcrowder/simple-snippets-console/blob/master/LICENSE
var snippet = {
    version: "1.01"1",

    // Writes out the given text in a monospaced paragraph tag, escaping
    // & and < so they aren't rendered as HTML.
    log: function(msg, tag) {
        var elm = document.createElement(tag || "p");
        elm.style.fontFamily = "monospace";
        elm.style.margin = "2px 0 2px 0";
        if (Object.prototype.toString.call(msg) === "[object Array]") {
            msg = msg.join();
        } else if (typeof object === "object") {
            msg = msg === null ? "null" : JSON.stringify(msg);
        } else {
            msg = String(msg);
        }
        document.bodyelm.insertAdjacentHTML(
            'beforeend',
            '<p style="font-family: monospace; margin: 2px 0 2px 0">' +
          innerHTML = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;') +
            '</p>';
        document.body.appendChild(elm);
    },

    // Writes out the given HTML at the end of the body,
    // exactly as-is
    logHTML: function(html) {
        document.body.insertAdjacentHTML("beforeend", html);
    }
};
// MIT license, see: https://github.com/tjcrowder/simple-snippets-console/blob/master/LICENSE
var snippet = {
    version: "1.01",

    // Writes out the given text in a monospaced paragraph tag, escaping
    // & and < so they aren't rendered as HTML.
    log: function(msg) {
        if (Object.prototype.toString.call(msg) === "[object Array]") {
            msg = msg.join();
        } else if (typeof object === "object") {
            msg = msg === null ? "null" : JSON.stringify(msg);
        } else {
            msg = String(msg);
        }
        document.body.insertAdjacentHTML(
            'beforeend',
            '<p style="font-family: monospace; margin: 2px 0 2px 0">' +
            msg.replace(/&/g, '&amp;').replace(/</g, '&lt;') +
            '</p>'
        );
    },

    // Writes out the given HTML at the end of the body,
    // exactly as-is
    logHTML: function(html) {
        document.body.insertAdjacentHTML("beforeend", html);
    }
};
// MIT license, see: https://github.com/tjcrowder/simple-snippets-console/blob/master/LICENSE
var snippet = {
    version: "1.1",

    // Writes out the given text in a monospaced paragraph tag, escaping
    // & and < so they aren't rendered as HTML.
    log: function(msg, tag) {
        var elm = document.createElement(tag || "p");
        elm.style.fontFamily = "monospace";
        elm.style.margin = "2px 0 2px 0";
        if (Object.prototype.toString.call(msg) === "[object Array]") {
            msg = msg.join();
        } else if (typeof object === "object") {
            msg = msg === null ? "null" : JSON.stringify(msg);
        } else {
            msg = String(msg);
        }
        elm.innerHTML = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;');
        document.body.appendChild(elm);
    },

    // Writes out the given HTML at the end of the body,
    // exactly as-is
    logHTML: function(html) {
        document.body.insertAdjacentHTML("beforeend", html);
    }
};
Bounty Ended with 100 reputation awarded by KyleMitStaffMod
added 5 characters in body
Source Link
T.J. Crowder
  • 23k
  • 7
  • 55
  • 103
Loading
fix stoopid mistake in snippet.log
Source Link
T.J. Crowder
  • 23k
  • 7
  • 55
  • 103
Loading
add github pages snippet object
Source Link
T.J. Crowder
  • 23k
  • 7
  • 55
  • 103
Loading
Source Link
T.J. Crowder
  • 23k
  • 7
  • 55
  • 103
Loading