Writing files with GreaseMonkey + JavaScript + PHP
Recently, I’m involved in a project where I have to test the ads banner by putting it on several websites. Of course I don’t have the money to buy ads slots on all of those sites, so I have to write several scripts to replace the banners on those websites with my banner on my browser.
GreaseMonkey is a really good add-on for FireFox to do the job. It take in a javascript file and execute it on browser and on the website you want.
In the project, I need to save some information such as the position of the banner when the mouse scroll at a specific time. However, javascript does not support writting files to local disk duel to security issues.
I though of cookie, however, it is more likely to be a hack than a good approach. GreaseMonkey API has some function to save the data but it is not really suitable.
At the end, I decided to build a local webserver to run some php script which handles the file writing task. The information is passed using GET method. From the GreaseMonkey script, I made a $.ajax call to this file and pass the data that I want to save.
It works!
leave a comment