admin管理员组文章数量:1379408
From what I understood, it is not possible to read files using Greasemonkey. I need to define lot of static configuration files, and it seems pletely messy to include those directly in the user script.
So, what is the best way to store and retrieve that data?
From what I understood, it is not possible to read files using Greasemonkey. I need to define lot of static configuration files, and it seems pletely messy to include those directly in the user script.
So, what is the best way to store and retrieve that data?
Share Improve this question edited May 9, 2011 at 12:57 Caleb 5,4482 gold badges50 silver badges68 bronze badges asked May 9, 2011 at 12:50 Michael LumbrosoMichael Lumbroso 4,9935 gold badges28 silver badges34 bronze badges3 Answers
Reset to default 5Yes, it is not possible, by design, to read local files.
If your files are all a page or so of text, and don't change that often, go ahead and use GM_getResourceText()
, per Dr.Molle's answer.
If your files are large, or change rapidly, then host them on a server and use GM_xmlhttpRequest()
to read back the file you need, at runtime. See item 2, below.
Using
GM_getResourceText()
is the easiest and fastest way to proceed. And, if the config files are reasonably sized (say less than 1K on average), this method will probably be faster than methods that rely on Ajax -- even with 150 (!!!) files.Drawback: You will have to bookmark an awkward path and remember it, when you want to edit a config file. (EG:
C:\Documents and Settings\<Windows login/user name>\Application Data\Mozilla\Firefox\Profiles\<profile folder>\gm_scripts\YOUR_SCRIPT_NAME\
)If you really can't -- or don't want to -- use a bunch of relatively static files, the best choice is to host the config files on your server and have
GM_xmlhttpRequest()
read the needed file when the script runs.If you do not have your own server, then you can host the files someplace like Google Docs.
Using
GM_getValue()
or using globalStorage or local storage can all be very fast and efficient about getting your config file data (and only the data you want). But, storing the data can be a major pain unless you write your own tools to do so (also a pain, but others have done it).Using
@require
offers no advantage overGM_getResourceText()
unless your config files are really valid JavaScript code. And, this method will require you to uninstall and then reinstall your script every time the name of an include file changes -- or if you add or delete files.
Not remended.
You can load a ressource: http://wiki.greasespot/GM_getResourceText
Or you can load it automatically using @require
本文标签: javascriptConfigurationfiles in a Greasemonkey scriptStack Overflow
版权声明:本文标题:javascript - Configuration-files in a Greasemonkey script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744450981a2606746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论