views:

53

answers:

2

A friend of mine uses a web-app for work related purposes. The app's built using PHP/MySQL , and while it has some JavaScript to make it easier to work with, it's not user friendly enough, and with a bit of extra JS, a lot of stuff could be automated.

I would like to enhance that app, but I'd like to not have to modify the original server-side code. To do this, all I could think of was Greasemonkey. Is this the only way to do it, or am I missing out something? I'd also like to be able to use a modern JS framework, like jQuery.

EDIT: I should tell you what improvements I want to make. There are a lot of fields on the page, so autocompletion would really help a lot. This will be used for data entering, so AJAX may be used for some error checking as well.

+3  A: 

Greasemonkey is certainly an option. Another idea is to code up your improvements, and then make bookmarklets out of them. Your friend can use the bookmarks (probably in a bookmark bar) to do the things you've improved. Bookmarklets have access to the page as though they were a part of the page.

Edit 1 In fact, now I think about it, a bookmarklet should be able to load a script file (from a different origin) into a document by adding a script tag to the head section (well, or anywhere, really). Since the SOP is based on where the document came from, not the script, ... That way, he'd just have to press the button once (for any given page he goes to) to load your improvements.

Edit 2 Yup, a bookmarklet can be used to bootstrap any script file into the page; here's an example:

javascript:(function(){var%20d=document,db=d.body||d.documentElement,elm;elm=d.createElement('script');elm.src="http://example.com/yourscript.js";db.appendChild(elm);db.removeChild(elm);})();

That adds a script element for the file http://example.com/yourscript.js to the body of the current document, which executes it. (The bookmarklet then removes the script element; just adding it is enough, it doesn't have to stick around; details.) Your script can then do things like add other scripts (jQuery, in your example) in the same sort of way, fire up auto-completers, etc. Tested the above (which probably needs tuning) with Chrome and Firefox; IE isn't liking it but I think that's an issue with my encoding of the bookmarklet or something rather than a fundamental problem. (I'm relatively new to bookmarklets.)

T.J. Crowder
Yeah, but what if I'd like autocompletion support? I don't think they will help.
Geo
Yeah. See my edit just now.
T.J. Crowder
Thanks! It's good to know options exist :)
Geo
A: 

I think Javascript can manipulate across frames, can't it?

Can't you just make a page that loads the original site in one frame and your js interface improvements in another?

(Getting the permission of the employer is also a good idea, if thats not been addressed)

Paul
Not if they aren't from the same origin, no: http://en.wikipedia.org/wiki/Same_origin_policy
T.J. Crowder
If he has the permission of the employer and the improvements are compelling, then he might be able to get the framed page served from the same server without modifying any original source.
Paul