I'm looking at various options I have to enhance my browsing experience. I found a ton of userscripts available at userscripts.org. But, I also was reading up on Google Chrome extensions (which seem very similar to userscripts).
I'm wondering if there is any advantages to using a userscript vs. an extension? The one thing I can't seem to get working is using either of these techniques to inject scripts into the DOM so that I can have my javascript code access the pages' javascript methods. It works fine as a single userscript install, but when I attempted to convert that userscript into an extension, it did not seem to work. Though, I wasn't sure if I did something wrong or if it can't work at all.
The main reason I ask is because after I started working on my own userscript I ran into the issue that the script file grew very large and repetitive to other scripts. Chrome doesn't support the "@require" option so I can't organize my "common" code that way, which is what lead me to think I should be looking at extensions instead.
So, is it possible to use "Script Injection" or "Location Hack" in an extension so that my javascript can execute on the DOM and access the other javascript?
To answer your first question: UserScripts are single files which can not request access to Chrome API's, such as bookmarks, cross-domain XMLHttpRequest etc. Chrome extensions are multiple zipped-up files which do not have these limitations.
As for your second question, I suggest you to read How can I mimic Greasemonkey/Firefox's unsafeWindow functionality in Chrome?.