Over the years, a number of community members have developed unofficial browser userscripts to add or supplement functionality on our platform. While we do have an official API, these scripts sometimes use the global JavaScript object StackExchange
to get information or perform actions on the page. That said, the StackExchange
object is an undocumented way to interact with a page on our platform on the client-side and was just an artifact of the way we were structuring our code internally.
This StackExchange
object has been the main namespace that we have used for making global functions available on the client-side across the site. However, we're currently migrating our JavaScript to ES modules. A direct repercussion of this is that we'll stop using the global StackExchange
object and will instead import the properties and methods we need directly onto each page based on the functionality that is hosted there.
This leaves us with the question of how to handle the global StackExchange
object once we stop using it internally. We know that userscripts depend on this object existing and that removing the properties and functions that it makes accessible will prevent many scripts from continuing to work. Breaking changes are frustrating and we don't want to irreparably break userscripts.
We're reaching out to the userscripting community here in order to better understand your needs. Our objective will be to provide a stable set of client-site properties and functions that can be relied on by userscript authors. To that effect, we are interested in knowing:
- What are the most important userscripts that you use today? What properties or methods of
window.StackExchange
(or any of our platform's other global objects) do those userscripts currently depend on? - If we provided a more stable interface for this information, what would you like to see from it? For example, would officially published TypeScript definitions be helpful?
- If we tried to make userscript development better, what improvements could we make for you?
We are going to make an effort to avoid breaking functions and properties in the window.StackExchange
namespace that are used by userscripts in the near term, however at this point we cannot commit to supporting every specific function or property. That said, we believe that having documented and stable client-side resources available will be very good for the health of the userscript community in the long run and we are exploring our options for providing a stable, official scripting API.
#mainbar-full div > ul:nth-child(2)
is a selector for the user profile stats - if the container could be selected viadocument.getElementById("user-stats")
, it would be immensely helpful (of course, this is not to say you should not be free to change whatever on the page - just having a sane way to access such "blocks" when present would be cool)CHAT
global object [ducks and covers under the nearest pile of dishes]?window.StackExchange = ...
, it would mean making code purposefully to support backwards capabilities but I would say don't update the bootstrap to get people to stop using it and move over to the Correct API's for any new functionality