tuff_ghost: (Default)
tuff_ghost ([personal profile] tuff_ghost) wrote in [community profile] ao3some2013-04-04 02:51 pm

FYI for userscript authors

If your userscript @requires jQuery, and your users are on Firefox, it's going to break JS running on Ao3 since the latest deploy, particularly the JS which shows modal boxes and hides the Share code on works.

If you're like me you were @requiring jQuery because you wanted your script to run in Chrome on Tampermonkey (where your script is sandboxed away from the host jQuery instance), and you didn't want to maintain two different copies of your script for Greasemonkey and Tampermonkey.

So, @require jQuery breaks stuff in Firefox, but you still need jQuery in Chrome. The solution is to get your jQuery instance from unsafeWindow.jQuery - this will point to the host instance of jQuery.


(function($) {
// your code which uses jQuery normally as $
})(unsafeWindow.jQuery);
poulpette: cropped picture of an illustrated octopus (Default)

[personal profile] poulpette 2013-04-05 06:04 pm (UTC)(link)
It does, thank you very much. I wasn't sure that was what you meant. Does this also mean that I'd be using whatever version of jQuery the AO3 is currently using?

(Anonymous) 2013-04-05 06:42 pm (UTC)(link)
Yep. It's not just the same source, it's the same instance, so you should even have access to whatever jQuery plugins the host site is running. (which is actually the whole reason for this post; userscripts were replacing the host instance after a plugin had loaded, killing the plugin)
poulpette: Stick-figure of a smiling head, raising heart pompoms. Bottom half says YAY!!! (Misc - devs = awesome)

[personal profile] poulpette 2013-04-05 08:22 pm (UTC)(link)
So I suppose I no longer need the @require line? and the script will still run for Chrome users?

Thank you for you help :)