Greasy Fork is available in English.
脚本高级统计
Dette script bør ikke installeres direkte. Det er et bibliotek, som andre scripts kan inkludere med metadirektivet // @require https://update.greasyfork.org/scripts/461573/1162621/script-statistics.js
这是一个内测中的功能
这是一个类似网站统计工具的库,引入后可以统计你脚本用户的使用情况,例如:脚本版本分布、运行设备分析、用户数等等
演示脚本: 高级统计测试
该库需要你在脚本中引入,并执行代码,key可以从脚本统计/高级统计中获取,另外必须设置白名单,非白名单内数据不会收集,库引入方式推荐为指定版本号,否则脚本管理器无法更新库的缓存。
// @require https://scriptcat.org/lib/881/1.2.0/script-statistics.js// @grant GM_setValue// @grant GM_getValue// @antifeature trackingtry {new SC_Statistic({key: "高级统计key",});} catch (e) {console.warn("statistic failed: ", e);}
// @require https://scriptcat.org/lib/881/1.2.0/script-statistics.js// @antifeature trackingtry {new SC_Statistic({key: "高级统计key",});} catch (e) {console.warn("statistic failed: ", e);}
如果不设置请求方式参数,会默认按照xhr、GM_xhr的方式进行请求,可能有以下几种情况:
这种方式在某些网站下运行可能会因为CSP策略无法提交数据,但是无需声明GM权限
当ajax方式错误时,会使用此方式,此方式需要声明GM权限,但是可以无视网站的CSP策略,如果都不支持数据将无法收集
// @connect scriptcat.org// @require https://test.scriptcat.org/lib/881/1.2.0/script-statistics.js// @grant GM_setValue// @grant GM_getValue// @grant GM_xmlhttpRequest// @antifeature tracking
在脚本头信息中声明GM_get/setValue权限,能够获取更加准确的用户识别
// @grant GM_setValue// @grant GM_getValue
无需声明GM权限,但是也无法准确识别用户,每一个域将会产生一个用户
可以自定义使用以下方式,由脚本来确定唯一用户
try {new SC_Statistic({key: "高级统计key",customHash(){return "customHash";}});} catch (e) {console.warn("statistic failed: ", e);}
退出时数据收集使用navigator.sendBeacon
实现,效果欠佳,类似于ajax方式受CSP限制,并且无法准确收集,后续可能更新替换其它更好的方法
new SC_Statistic({key: "高级统计key",// 必须,统计keywhitelist: ["scriptcat.org"],// 在白名单内的域名才会统计,为空将会自动拉取后端配置banFrame: false,// 不收集iframe中的数据enableGM: true,// 开启GM请求enableXML: true,// 开启ajax请求customHash: undefind,// 自定义哈希});