News for hackers. Stuff that matters.
Re:Turn your browser into a notepad with one line by Cushman on Tuesday January 29, 2013 @02:18PM (#5135684)
For even more fun, turn your notepad into an interactive JavaScript environment:

  data:text/html, <html contenteditable onkeyup="eval(this.innerText)">
Then you can upgrade it by pasting in something like this:

  this.onkeyup = function () {
    this.style.backgroundColor = 'white';
    try {
      eval(this.innerText);
    } catch (e) {
     this.style.backgroundColor = '#FFAAAA';
    } 
  }
Re:Turn your browser into a notepad with one line by christiangenco on Tuesday January 29, 2013 @02:48PM (#5135833)
Typing `alert("hi")` was a bad choice.
Re:Turn your browser into a notepad with one line by Cushman on Tuesday January 29, 2013 @03:05PM (#5135923)
It took me a few goes to figure out I could just click OK.
Re:Turn your browser into a notepad with one line by dbh937 on Tuesday January 29, 2013 @07:02PM (#5137245)
Thank you. Thank you so much.
Re:Turn your browser into a notepad with one line by shurcooL on Tuesday January 29, 2013 @03:37PM (#5136096)
That's exactly what I did.
Re:Turn your browser into a notepad with one line by pestaa on Tuesday January 29, 2013 @02:44PM (#5135815)
This is clearly awesome. First thing I did? Got into infinite loop. This is not exactly a good interactive console for JavaScript, but still very fun.
Re:Turn your browser into a notepad with one line by Cushman on Tuesday January 29, 2013 @03:06PM (#5135936)
I think I like it because of how weirdly constrained it is. Especially when you're writing something that will overwrite the handler itself, it's easy to get yourself stuck in a loop or a strange dead end.
Re:Turn your browser into a notepad with one line by seliopou on Tuesday January 29, 2013 @08:01PM (#5137466)
This is a much easier way to customize its appearance:

    data:text/html, <html><style> body { font-family: sans-serif }</style><body contenteditable>
Re:Turn your browser into a notepad with one line by Davertron on Wednesday January 30, 2013 @08:23AM (#5139318)
I forked minikomi's gist above that does something like this, except you use ctrl+j to execute what's in the buffer:

https://gist.github.com/4673043

Re:Turn your browser into a notepad with one line by shurcooL on Tuesday January 29, 2013 @05:12PM (#5136697)
Is there an equivalent to `this.onkeyup` for touch devices that don't generate onkeyup events? Trying to make this work on an iPad, but I only have surface knowledge of JS.
Re:Turn your browser into a notepad with one line by infinity on Tuesday January 29, 2013 @05:38PM (#5136854)
Maybe this helps you, there is a W3 document about touch events: http://www.w3.org/TR/touch-events/

A list of TouchEvent types is here: http://www.w3.org/TR/touch-events/#list-of-touchevent-types

Here is a document from Apple about touch events:

http://developer.apple.com/library/safari/#documentation/app...

And a list of events supported by the Safari browser: http://developer.apple.com/library/safari/#documentation/app...

I don't have an iPad, but I would love to know, if you could successfully use one of these events in this context.

Edit: For example, orientationchange looks promising. Type something, then change orientation.

Re:Turn your browser into a notepad with one line by Cushman on Tuesday January 29, 2013 @05:38PM (#5136851)
Hmm... I only have an iPad simulator with me, but it works just pasting in what I wrote above. Maybe something in your data URI is getting munged?

Keyup is used here rather than keypress (which fires only once for each down-up event) since backspace won't fire keypress events, which is a nice thing to have in a live environment. But I can't think of any environment which would implement keypress and not keyup, or how one might work around not having key events at all.

I did, however, discover that if you alert in mobile Safari (in simulation and on my iPhone) on a backspace keydown, the keyup never gets through and it will happily erase everything before the cursor.

Re:Turn your browser into a notepad with one line by shurcooL on Tuesday January 29, 2013 @07:21PM (#5137314)
You're right, it works fine with onkeyup. I tried pasting the URL directly instead of opening from "other devices" and it worked. Thanks.
Re:Turn your browser into a notepad with one line by Deestan on Wednesday January 30, 2013 @04:22AM (#5138719)
It's pretty brutal and stupid, but:

    window.setInterval(function(){eval(this.innerText)},1000);
Re:Turn your browser into a notepad with one line by ssfermoy on Wednesday January 30, 2013 @02:08PM (#5141110)
For me Firefox seems not to work with this.innerText . Instead you can use this.textContent to get it to work.