javascript - Modify GM_setValue and GM_getValue for cross-tab communication : How to access Firefox Preferences variables? - Sta

I have a new problem related to my GM user script.The purpose of this script is to retrieve data from e

I have a new problem related to my GM user script.

The purpose of this script is to retrieve data from external domain. My first attempts on Firefox lead me to design a page, with my form to be filled and an iframe embedding the external page. By using setInterval and identify wether it's the top window or if we are in the iframe, I successfully used GM_setValue and GM_getValue to get the data.

But with IE (IE7PRO), I found out I was able to separate my script into 2 scripts : one only dealing with the form, and the other dealing with the external domain. IE7PRO provides equivalent functions (PRO_getValue and PRO_setValue) that can be retrieved on any tab/page of the product. The only difference is that it works cross-tab/page, so I don't have to include the iframe on my own page, and I can open its own tab for the external domain which is about a million times better (at least...)!

I tried the same on Firefox and it obviously didn't work. I've been through the documentation of those functions, and it appears that in Firefox, data are stored in Preferences (about:config to access).

So, is there a way I can modify GM_getValue, add it parameters, because values are stored with this model : greasemonkey.scriptvals.namespace/script_name.value_name

Is there a way to access the value of a preference in Firefox, in a Greasemonkey user script/in Javascript and what is the syntax?

Thanks ;-)

I have a new problem related to my GM user script.

The purpose of this script is to retrieve data from external domain. My first attempts on Firefox lead me to design a page, with my form to be filled and an iframe embedding the external page. By using setInterval and identify wether it's the top window or if we are in the iframe, I successfully used GM_setValue and GM_getValue to get the data.

But with IE (IE7PRO), I found out I was able to separate my script into 2 scripts : one only dealing with the form, and the other dealing with the external domain. IE7PRO provides equivalent functions (PRO_getValue and PRO_setValue) that can be retrieved on any tab/page of the product. The only difference is that it works cross-tab/page, so I don't have to include the iframe on my own page, and I can open its own tab for the external domain which is about a million times better (at least...)!

I tried the same on Firefox and it obviously didn't work. I've been through the documentation of those functions, and it appears that in Firefox, data are stored in Preferences (about:config to access).

So, is there a way I can modify GM_getValue, add it parameters, because values are stored with this model : greasemonkey.scriptvals.namespace/script_name.value_name

Is there a way to access the value of a preference in Firefox, in a Greasemonkey user script/in Javascript and what is the syntax?

Thanks ;-)

Share Improve this question asked May 18, 2011 at 14:18 Michael LumbrosoMichael Lumbroso 4,9935 gold badges28 silver badges34 bronze badges 1
  • 3 Maybe you can use a single GM script which runs on both pages with a big if-statement deciding which part of the script to run depending on the url. – wimh Commented May 18, 2011 at 20:03
Add a ment  | 

2 Answers 2

Reset to default 7

If I'm understanding your question right, you'd pretty much do the same thing you're already doing in IE: have a userscript running in each tab.

GM_[gs]etValue do work cross-tab and cross-page. Values are stored per userscript.

So all you need to do is have the same userscript run in both tabs, and simply have it do different things based on a check to window.location.href.

Currently, the only way is to make one script that runs on both pages.
You can differentiate them by adding an if-statement as mentioned before by Wimmel.

You may however consider adding your data in global scope using unsafeWindow and separating the code into 2 scripts, but order which both scripts are executed would affect the result.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745132697a4613048.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信