I recently made a Greasemonkey Script which I intended to use in some project of mine. It took me quite a while to write and debug ( damn css developers who use “!important” anywhere they do not know how to make things work correctly
).
My script contained a couple of configuration variables, that needed to be reconfigured depending on the machine the script would be used on. Considering the specific network’s users as potential idiots, I decided that it would be better if each machine’s administrator could just log-in, submit a simple form and receive the script ready for use. It would also be much more simple in case there was need for an update (no re-configuration needed separately on each machine).
I though that instead of creating a different file each time a user requested the script it would be better to try sending the output of the PHP script directly, by adding the correct headers. No luck.
What I leant after asking the kind user’s of #greasemonkey :
Greasemonkey doesn’t read a file’s headers or contents in order to identify a script. So even if you change the output headers to a different content-type or content-disposition, greasemonkey won’t open the file for you.
All it reads is the file’s extension “.user.js”
Conclusion:
add
-
header( 'Content-Type: text/javascript' );
-
header( 'Content-Disposition: inline; filename="filename.user.js"' );
-
//change "filename.user.js" to the desired filename
-
echo $file_contents; //your output here</strong>
to your php script
and make sure that the link to the script is something similar to
gm_script.php?.user.js
alternatively you can use mod_rewrite to rewrite .user.js to .php (a much cleaner solution if you have the time to do that).

Thanks a heap, you saved my day. That’s the solution i was looking for the last days…
Does not work in google chrome.
@Kano
I’m glad this finally helped someone
@darasion
Chrome might be trying to do the same work as Greasemonkey, but it most likely has differences in the way it treats the scripts. I’d be interested to know why it doesn’t work, and will most certainly update this post if I have to time to look into it.
I hope you find the solution.