What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 128 Stack Exchange communities.

I've been playing with some Google Chrome user scripts (just like Greasemonkey scripts for Firefox) to add enhancements to my Stack Exchange sites.

Sometimes I find it's difficult to scrape what I need from the site's HTML but it could be made a lot easier just by minor tweaks such as adding HTML IDs and classes.

On Wikipedia we can submit bug reports and feature requests of this nature because MediaWiki has built in support for user JavaScript and CSS.

Stack Exchange has a lot of wiki-like features but is proprietary and doesn't seem to officially support extensions but also doesn't seem to discourage them.

Should I request new HTML classes and IDs to make it easier for myself and others to make site enhancements?


Also, are questions like this question and/or questions of the type addressed here better suited to meta.stackoverflow or to stackapps?

share|improve this question
1  
If you use jQuery, you don't need to go through all of this. You can target any element on the page just using CSS selectors. –  jmort253 Sep 26 '12 at 6:47
1  
I do use jQuery but there's two issues. 1. I also use mutation observers and I don't know if I can use jQuery selectors on the DOM fragments returned by those. 2. Selectors work much better with good ID and class structure. jQuery is not a replacement for IDs and classes. You can much more deterministically access elements by ID/class than by knowing its position in the DOM tree or what text a node contains etc, all of that kind of thing is much more subject to change so relying on them makes your code more brittle. –  hippietrail Sep 26 '12 at 6:51
    
I've asked a question on SO about my point 1.: Can jQuery selectors be used with DOM mutation observers? –  hippietrail Sep 26 '12 at 7:01
    
Take a look at stackapps.com; it's part of the SE network and part of it's stated goal is to promote browser scripts. Now tell us again scripts aren't officially supported? –  Martijn Pieters Sep 26 '12 at 7:04
4  
@MartijnPieters - I think what he means is that, because there's no API for the HTML, there's less guarantee that scripts won't break, not like when using the official, frozen API. With a frontend browser script, you're more dependent on the whims of Stack Exchange developers and designers. –  jmort253 Sep 26 '12 at 7:08
1  
I love the API. I'm active on StackApps. I've submitted bug reports and feature requests there and had them accepted. But none of those were directly for interaction with the site's pages, HTML, DOM, etc. –  hippietrail Sep 26 '12 at 7:11
1  
I +1'd this. I'd actually like to hear the "official" response from a developer on your request, as it's actually not a bad idea... The API can't make changes to the web page itself. –  jmort253 Sep 26 '12 at 7:16
    
@MartijnPieters: You may think it's officially supported but jmort253 in his comments below is saying it's definitely not. –  hippietrail Sep 26 '12 at 7:22
    
I've gone ahead and asked the first question of this kind, it's quite bulky to include enough explanation to cover the sort of points brought up here about why HTML changes might not be needed: Add a class to the tag popups to reflect whether the tag has a wiki and/or wiki excerpt –  hippietrail Sep 26 '12 at 7:51

2 Answers 2

Check out:

  1. StackApps
  2. Stack Exchange API

The Stack Exchange engine might be proprietary, but I see a lot of support and encouragement for user extensions of (almost) every kind. There was even a contest for extensions build around the new version of the API, and a blog post by Jeff that specifically discusses and encourages user scripts:

We’re making user scripts a first class citizen on Stack Apps by …

  • giving them their very own script tab on the homepage powered by the [script] tag.
  • updating the /faq and introductory messages to emphasize that browser scripts which enhance the Stack Exchange experience are welcome, even if they don’t technically use the API.
  • continuing to publicize the cool and useful scripts our community is creating from within our own community.

There's absolutely no reason why you shouldn't request new HTML classes and/or IDs. Whether you'll get them though is a whole different discussion. To maximize your chances you should make sure that your script absolutely needs the extra classes/IDs/anything and that the script would be useful to a few people, not just you.

share|improve this answer
    
Yes I've been using the API and I'm active on StackApps. I've found the enhancement I'm working on can make too many requests and I'll be able to do much more efficient caching if I can get as much information out of the HTML before resorting to API calls. –  hippietrail Sep 26 '12 at 7:03
    
@hippietrail If you've already seen them, I don't really get your point that Stack Exchange doesn't seem to officially support extensions, what could be more official? –  Yannis Sep 26 '12 at 7:04
    
Well I've never seen anybody ask for HTML changes to help their extensions be less hacky, and yes I did search for such questions. I would consider that kind of thing more what I would call "support" than "encouragement". The API can be used for many more things than changing the actual site's pages. Normally you use them to make native webapps or smart phone apps. So I know those are supported and now I want to know if site extension scripts are as supported or less so. –  hippietrail Sep 26 '12 at 7:10
    
@hippietrail, Yannis does have a point. You're just using non-official means to accomplish your goal instead of the official means, the API..... I understand why you're doing what you're doing, but it's just not the supported means. As I mention in my answer, scripts that manipulate the DOM are hacks. –  jmort253 Sep 26 '12 at 7:10
    
@hippietrail Well, I'd guess most of these discussions happen in StackApps comments or in chat, devs lurk in several chat rooms and it's not that hard to spot them. That said, I don't see any reason why you shouldn't ask on Meta, it's a valid feature request. –  Yannis Sep 26 '12 at 7:13
    
Actually I am using the API. I found that I'm quickly running into the throttle limit despite being as economical with calls as I could. I now wish to implement the smartest caching scheme I can by monitoring changes to the page and only making API calls for the remainder. –  hippietrail Sep 26 '12 at 7:19
    
Hmm @jmort253 seems to be saying they're definitely not supported whereas @MartijnPieters seems to be saying they definitely are supported. Now I really want an official answer (-: –  hippietrail Sep 26 '12 at 7:21
    
StackApps chat is barely ever active. In fact nobody's ever been there when I've gone in with ideas and questions that I can recall. –  hippietrail Sep 26 '12 at 7:23
    
@hippietrail There's absolutely no reason you should care for an "official" answer, if your feature request is deemed useful, it will get build, if not, it won't, same as with all feature requests. Your extension might feel like a hack, but I don't really see why that would be important if it's actually useful to a lot of people. Everything I ever coded is a hack ;) –  Yannis Sep 26 '12 at 7:24
    
@hippietrail The StackApps chat might feel deserted, but that doesn't mean you can't ask what you want there at any time, it only means that it might take a while before you get a response. Just post a message, someone will eventually see it. –  Yannis Sep 26 '12 at 7:25
1  
@hippietrail, generally the Tavern is fairly well frequented. Have your memes to hand... ;) –  Benjol Sep 27 '12 at 7:04

If you use jQuery, or a similar toolkit, you don't need to worry about every element having a class or an id attribute. With CSS selectors that jQuery provides, you can target any element on the page. See the jQuery Docs for more information.

Aside from the toolkits and JavaScript libraries, if you really really are a JavaScript purist at heart, HTML5 offers similar functionality. See the Mozilla Developer Center docs on Document.querySelectorAll.

In short, you don't need to make the Stack Exchange development team drop everything they're doing to go update the HTML with a few classes and id's. :)

Keep in mind that browser add-ons and Greasemonkey scripts are at their very core hacks. They're not officially supported, and forcing the Stack Exchange team to worry about whether they're going to break your script if they make an update to the HTML is not something that is in their best interests or the best interests of Stack Exchange. Part of what makes Stack Exchange successful is the razor-sharp focus on developing only what's necessary, and carefully picking and choosing what will and will not be supported.

If it helps, I know how you feel! I'm working on a Greasemonkey script right now that involves parsing the DOM. We need to be prepared to support our scripts when they break. I'll go out on a limb here and say that supporting our scripts is out of scope for the Stack Exchange developers; their focus is on the core engine.

As an aside, I think a good feature request could possibly be a frontend SDK for browser add-ons and scripts. This would give the team more control over what they "officially" support and what they won't support because it would take too much work. It would also add a layer of abstraction between our scripts/add-ons and the actual SE frontend HTML.

share|improve this answer
    
Don't worry I don't want anybody to "drop everything" or "force the team to worry". I just want to quietly ask in case they also think the changes are sensible and useful. I know such extensions are hacks but still want to make the most stable hacks I can and where possible suggest improvements that will also help other peoples' hacks. –  hippietrail Sep 26 '12 at 7:06
    
Stack Exchange sites are very dynamic, they use lots of Web 2.0 to keep the pages changing smoothly. I want to interact with this. So far I don't know how well I can use CSS selectors to interact with modern features such as mutation observers. –  hippietrail Sep 26 '12 at 7:07
2  
@hippietrail Sometimes hacks may make it into the core (more or less), the most recent example is the canned comments in /review that started out as a StackApp. Hack or not, a useful script will get noticed, and if it can be made more useful with some work from the devs, I don't see why they wouldn't. –  Yannis Sep 26 '12 at 7:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .