油猴脚本如何使用 GM_getResourceUrl

查看 44|回复 2
作者:炎火焱   
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @AuThor       You
// @match        http://*/*
// @resource icon2       /images/icon.png
// @grant        unsafeWindow
// @grant        GM_addStyle
// @grant        GM_getResourceUrl
// ==/UserScript==
(function() {
    'use strict';
    // 获取本地路径
    const iconPath = GM_getResourceUrl('images/icon.png');
   
    // Your code here...
})();
请问在油猴脚本中如何使用 GM_getResourceUrl ?
上面的代码,在4.11.0版本中,    const iconPath = GM_getResourceUrl('images/icon.png')    这句提示   is not defined
在4.18.1版本中, // @grant        GM_getResourceUrl   这句提示   is not a valid,  const iconPath = GM_getResourceUrl('images/icon.png')    这句提示   is not defined
不明白原因出在哪里,求解决方法,引用的完整代码

这句, 如何使用

finillusion   

你好
GM_getResourceUrl
需要配合
@resource属性使用
下面是一个例子
[JavaScript] 纯文本查看 复制代码
// ==UserScript==

@resource  icon  images/icon.png
(function() {
    'use strict';
const iconPath = GM_getResourceUrl(icon');
})();
finillusion   


finillusion 发表于 2023-4-28 17:23
你好
GM_getResourceUrl
需要配合

[Java] 纯文本查看 复制代码// ==UserScript==
@resource  icon  images/icon.png
(function() {
    'use strict';
const iconPath = GM_getResourceUrl('icon');
})();
您需要登录后才可以回帖 登录 | 立即注册

返回顶部