Skip to content

Instantly share code, notes, and snippets.

Created June 17, 2013 00:30
Show Gist options
  • Save anonymous/5794002 to your computer and use it in GitHub Desktop.
Save anonymous/5794002 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jun 17, 2013.
    50 changes: 50 additions & 0 deletions Twilightify.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    var hasStartedEpisode = false;
    window.onerror = function(e){
    // credits roll
    if(!hasStartedEpisode){
    if(Math.random() > 0.5){
    console.warn("You're traveling through another dimension.\nA dimension not only of sight and sound, but of mind.\nA journey into a wondrous land whose boundaries are that of imagination.\n--Your next stop: The Twilight Zone");
    }
    else{
    console.warn("There is a fifth dimension, beyond that which is known to man.\nIt is a dimension as vast as space, and as timeless as infinity.\nIt is the middle ground between light and shadow - between science and superstition - and it lies between the pit of man's fears and the summit of his knowledge.\nThis is the dimension of imagination.\nIt is an area which we call: The Twilight Zone.\n");
    }
    hasStartedEpisode = true;
    }

    // personalize message based on error type
    if(e.indexOf("ReferenceError") > -1){
    console.error("This is a story of mistaken identity - one where a name is given, but not found in memory. A small typo has made all the difference in - The Twilight Zone.");
    }
    else if(e.indexOf("EvalError") > -1){
    console.error("Absolute power corrupts absolutely, or so they say. Today this user has been given unimaginable power");
    }
    else if(e.indexOf("RangeError") > -1){
    console.error("Many great discoveries of science are by accident. Accidents in mathematics, on the other hand, are a fast track beyond our dimension and science into - The Twilight Zone.");
    }
    else if(e.indexOf("SyntaxError") > -1){
    console.error("The language of man is one of beauty and emotion - concepts unknown to cruel, unthinking machines. At the other end of their super-fast calculations are a confused jumble otherwise known as: The Twilight Zone.");
    }
    else if(e.indexOf("TypeError") > -1){
    console.error("Every day the wheels of progress move forward, but they can still be jammed by a determined man moving in the opposite direction. Here is one variable which refused to be defined as String or Number or Object, but as an independent entity in - The Twilight Zone.");
    }
    else if(e.indexOf("FileError") > -1){
    console.error("Pity the bureaucrat - buried in a mountain of paperwork. He has until the end of the day to retrieve one form, yet has found nothing. Consumed by his own system, he races to find a file lost in - The Twilight Zone.");
    }
    else if(e.indexOf("DOMException") > -1){
    console.error("A structure pervades our universe, one beyond description and understanding.\nThe best-laid plans of mice and men are disrupted in an instant by a flaw in the Document Object Model, the DOM. Welcome to The Twilight Zone.");
    }
    else{
    // unknown error
    console.error("Today a web developer has met his match - an unknown and uncategorized error. One from another dimension, with good or evil in mind? No one knows. We are bound to discover the answer in - the Twilight Zone.");
    }

    // suppress regular error message
    return true;
    };
    /*
    Unhandled:
    AutocompleteErrorEvent
    MediaError
    MediaKeyError
    URIError
    */