使用Greasemonkey脚本跨域本地存储 [英] Local storage across domains using a Greasemonkey script

查看:69
本文介绍了使用Greasemonkey脚本跨域本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Greasemonkey脚本跨域存储数据?我想允许从使用相同Greasemonkey脚本的多个网站访问Javascript对象.

Is it possible to store data across domains using a Greasemonkey script? I want to allow a Javascript object to be accessed from multiple websites that are using the same Greasemonkey script.

推荐答案

是的,这是 GM_setvalue() ,它可以按域每个脚本存储数据.

Yes, that is one of the purposes of GM_setvalue(), it stores data, per script, and across domains.

请注意,沼泽标准GM_setValue()有点问题.它可能会使用大量的全局资源或导致脚本实例崩溃.

Beware that the bog-standard GM_setValue() is somewhat problematic. It can use lots of global resources or cause a script instance to crash.

以下是一些准则:

  1. 请勿使用GM_setValue()来存储字符串以外的任何内容.除此之外,请使用诸如 GM_SuperValue 之类的序列化程序.甚至看起来无辜的整数也可能导致默认的GM_setValue()崩溃.

  1. Do not use GM_setValue() to store anything but strings. For anything else, use a serializer such as GM_SuperValue. Even innocent looking integers can cause the default GM_setValue() to crash.

与其存储许多小变量相比,不如将它们包装在一个对象中并用一个序列化器存储起来更好.

Rather than store lots of small variables, it may be better to wrap them in an object and store that with one of the serializers.


最后请注意, localStorage 在javascript中具有特定含义,而localStorage 特定于域的.


Finally note that localStorage has a specific meaning in javascript, and localStorage is domain specific.

这篇关于使用Greasemonkey脚本跨域本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆