开发者

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

开发者 https://www.devze.com 2023-03-06 15:01 出处:网络
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 fille

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开发者_JAVA技巧: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 ;-)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消