从脚本中访问Greasemonkey元数据? [英] Accessing Greasemonkey metadata from within your script?

查看:120
本文介绍了从脚本中访问Greasemonkey元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本有没有办法检索在自己的标头中声明的元数据值?除了 GM_getValue()之外,我在API中看不到任何有希望的东西。那当然会涉及一个特殊的名称语法。我试过,例如: GM_getValue(@ name)

Is there any way that my script can retrieve metadata values that are declared in its own header? I don't see anything promising in the API, except perhaps GM_getValue(). That would of course involve a special name syntax. I have tried, for example: GM_getValue("@name").

这里的动机是避免多余的规范。

The motivation here is to avoid redundant specification.

如果无法直接访问GM元数据,也许有一种方法可以读取脚本本身。它肯定在某个地方的内存中,并且解析// @并不是太难。 (在我的情况下,这可能是必要的,因为我真正感兴趣的值是 @version ,这是 userscripts.org 。)

If GM metadata is not directly accessible, perhaps there's a way to read the body of the script itself. It's certainly in memory somewhere, and it wouldn't be too awfully hard to parse for "// @". (That may be necessary in my case any way, since the value I'm really interested in is @version, which is an extended value read by userscripts.org.)

推荐答案

这个答案已经过时了:从Greasemonkey 0。0。16(2012年2月)开始,请参阅 Brock的答案关于 GM_info

This answer is out of date : As of Greasemonkey 0.9.16 (Feb 2012) please see Brock's answer regarding GM_info

是。一个非常简单的例子是:

Yes. A very simple example is:

var metadata=<> 
// ==UserScript==
// @name           Reading metadata
// @namespace      http://www.afunamatata.com/greasemonkey/
// @description    Read in metadata from the header
// @version        0.9
// @include        https://stackoverflow.com/questions/104568/accessing-greasemonkey-metadata-from-within-your-script
// ==/UserScript==
</>.toString();

GM_log(metadata); 

参见这个主题在greasemonkey-users组上获取更多信息。最近可以找到更强大的实现。

See this thread on the greasemonkey-users group for more information. A more robust implementation can be found near the end.

这篇关于从脚本中访问Greasemonkey元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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