Live data from Hacker News

Turn your browser into a notepad with one line

coderwall.com

81–90 of 186 posts

Re: Turn your browser into a notepad with one line

#82

Ah shoot. If Chrome allowed localStorage to be accessible from file:/// then we could add save (CTRL+S) and automatic load using this: data:text/html, window.onload=function(){var a=document.body;a.innerText=localStorage.mydoc;a.addEventListener("keydown",function(b){b.ctrlKey&&83==b.which&&(localStorage.mydoc=a.innerHTML,b.preventDefault())},!1)}; Firefox will save it to localStorage but clear the local storage afte…

That is so cool :). I just slapped together a (really) simple chrome ext for opening up a new tab in "contenteditable" mode. It saves the contents into localStorage, thats it for now :) Here it is if anyones interested https://github.com/jwaterfaucett/textpad

ok - and how do I retrieve the saved contents?

Re: Turn your browser into a notepad with one line

#83
post #19

For even more fun, turn your notepad into an interactive JavaScript environment: data:text/html, 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'; } }

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.

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

#84
post #19

For even more fun, turn your notepad into an interactive JavaScript environment: data:text/html, 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'; } }

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.

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

#85
post #27

Very clever! I set this as the default URL for new tabs.. Now, everytime I open a new tab, I have a quick scratchpad for pasting/testing/etc.

That's a great idea, did you do it for Chrome? Seems like with Chrome it's non-trivial to set the page for new tabs...

You can set it as the homepage (enableable in Settings). It adds an extra step after opening a new page (either clicking on the home icon or shift-cmd-h) but I prefer that to replacing the default Chrome page (with its Most visited and Recently closed menus).

Re: Turn your browser into a notepad with one line

#86

Personally I'm more interested in the concept of typing gibberish to clear your mind. What particular kind of gibberish? Doggerel verse? Blind keyboard mashing?

I often do an exercise that I've started referring to as a "brain dump". Sometimes when I feel overwhelmed, for whatever reason, it helps to just simply start typing. I start by just saying whatever is most present on my mind, and each new thought starts on a new line. More often than not I end up drilling down to some kind of inner conflict buried pretty deep in my mind. What's really amazing is when seemingly unrel…

Just tried this, very relaxing, quite amazing how many different things you have spinning around your head at any one time...

Re: Turn your browser into a notepad with one line

#87
post #82

Earlier quoted context omitted.

That is so cool :). I just slapped together a (really) simple chrome ext for opening up a new tab in "contenteditable" mode. It saves the contents into localStorage, thats it for now :) Here it is if anyones interested https://github.com/jwaterfaucett/textpad

ok - and how do I retrieve the saved contents?

They are loaded when you re-open the extension by the looks of it.

Re: Turn your browser into a notepad with one line

#89
post #34

This is what the scratch (EDIT: read scratch as * scratch * without the spaces--is there any way to escape that properly on HN?) buffer is for in Emacs, and I find it extremely useful. Also, unlike using a different tool, it allows me to use all the Emacs-specific features I usually rely on. (For example, I can easily type special characters like r₁ × r₂ ≈ r₃ using the TeX mode.) If you want more than one scratch buf…

[deleted]

Re: Turn your browser into a notepad with one line

#90

Nifty trick. To build on this, if you use chrome, add it as a search engine with a special keyword so you can type in your URL bar something like "note + + " then you're in typing mode.

In fact, if you add the `%s` variable inside the HTML tag: data:text/html, %s This way, you can enter: note [tab] "foo bar baz" [enter] And whatever you enter as the search query ends up in the note to start with. Edit: Just saw the other response to this comment saying basically the same thing. Nevermind.

data:text/html, %s

More like it.

Post reply on HN