Right now it's a Chrome extension, but I'd love to serve it as plain JS. Anybody know if you can give a web app privileges to open and close tabs without making it a browser extension?
(Don't worry, btw; if we ever publish this it will be entirely opt-in.)
Only thing is users must disable popup blocking for HN, in the unlikely case that you want to open more than 2 links at once, or open links when the user doesn't click something (like onload).
Forgive me for hijacking this thread into technical support territory, but I've found documentation on this stuff hard to come by.
You'd have to synchronize things yourself to prevent tripping over yourself. Ditto for firing off functions in response to events (i.e. Poll loop and fire handler).
Save objects to local storage:
localStorage.name = "dang";
alert(localStorage.name);
You save stuff to localstorage in one tab, and in other tab you listen to "storage" event:
window.addEventListener('storage', function() {..})
[0] https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage...[1] https://developer.mozilla.org/en-US/docs/Web/Events/storage
Another option is shared web workers, though I never used it.
[2] http://stackoverflow.com/questions/12107424/communication-be...
[3] https://developer.mozilla.org/en-US/docs/Web/API/SharedWorke...
I confused things in my other comment (I deleted it)
Edit:
Yep
w2 = window.open('/');
w2.document.click()
Is fine if complying with the sameOrigin policyhttps://developer.mozilla.org/en-US/docs/Web/API/Window/open
It's OK, I'm sure the mods will take care of it.
EDIT: I know this isn't reddit but I couldn't resist. Dan it's admirable how nice and down-to-earth you are in spite of all the stuff you see here everyday...huge thanks for all your work in making HN what it is.
It's all done by keyboard shortcuts, which means the mapping to keys is pretty complicated and not as consistent as I'd like.
Edit: It's also written in a Lisp we made that only three of you have ever heard of :)
And you can compile that Lisp to JavaScript to build the Chrome extension?
Dan and Scott, though, and in this case mostly Scott.
It's very easy to check for localStorage support (some people disable it just like cookies) and it works, I think, everywhere except Opera, in almost every mainstream version.
(I use it a bunch).
https://developer.mozilla.org/en-US/docs/Web/API/Window/clos...
Thanks everyone for all the help!
I haven't tested, but you might be able to kind of fake it by having the tab immediately before the one you want to open do the opening. That wouldn't work for tabs that have opened external sites (the stories themselves), but you could at least send a message to one of the other HN tabs telling it to open your new tab, which should give you some control.
While I'm at it, is there a way to give a regular web app the kind of permissions that a Chrome extension manifest can give? It isn't just tab mechanics I need, but clipboard access and cross-domain privileges. Obviously this would still require client consent (and might still be Chrome-only) but it would be easier than an extension with all its deployment headaches.
Regarding cross-domain, what do you want to do exactly? In general there's no built-in support at least in Firefox to override default same-origin policy, but there are Chrome/Firefox extensions that for instance inject CORS headers to each response.
Edit: In Chrome, it seems you can disable same-origin policy with command line flag [2]
I'd be scared to show it as is because we get in trouble when admin-specific stuff shows up in screenshots. There once was a controversy because 'kill', 'blast', and 'nuke' links showed up in a screen shot, despite the fact that they were all defined in the version of the HN source code that pg published years ago.
A Show HN will certainly be in order if we ever publish it, though.
> opening and closing those tabs when desired
will only work with window.open if the moderation tool's window owns the tabs in question. So if you open a HN tab randomly or from another site or wherever, the moderation tool won't have opened it, and so it won't be able to close it.
reddit has RES. People are used to browser extensions, and this doesn't sound like it'd cooperate too well on a phone or similar device, so I say just release the extension.
As for fun-sounding feature names, just make a help page in the extension describing how everything works. Maybe call the help page "spoilers" or something. :D
Oh and can I be the fourth person to know what Lisp you wrote this in? :D
Thanks for the info. :)
I'm mildly curious how Lumen and Arc differ.
We also wanted it to be self-hosted, and to compile (transpile) to Lua as well as JS, in as straightforward a way as possible. JS and Lua are very close semantically, so our approach with Lumen was to take the semantic intersection of those two and then build the simplest thing we could on top of it. As a result, it's quite different from Arc, which is semantically a classical Lisp.
Here are a couple of old comments I posted about this idea, before Scott implemented it:
The nice thing about user scripts is that there is no packaging or bundling. The advantage of Greasemonkey over Tampermonkey is it uses files rather than storing scripts in a database.