Userscript App Core

Userscript App Core For Userscript Web Apps

Ekde 2024/05/17. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Aŭtoro
PYUDNG
Ratings
0 0 0
Versio
0.8
Kreita
2022/09/27
Ĝisdatigita
2024/05/17
Size
4,81 kb
Licenco
MIT
Aplikiĝas al
Ĉiuj retejoj

用户脚本网页APP核心

安装此脚本后,网页js可以通过脚本提供的window.UAC.grant获取GM_*函数,从而获得相当于用户脚本的权限,典型的用法就是可以用来开发一些需要跨域api的网页应用。
示例:去除了单次翻译5000字限制的百度翻译源码

使用前注意:尽管有部分安全措施,但是此脚本仍然是不安全的,请仅仅在信任的网站上使用!

Usage:
安全考虑,调用时需要提供调用密码。用户可以在Tampermonkey的菜单中设置密码(如图1),然后网页可以如下方法调用:

// Wait for userscript ready
window.UAC ? work() : window.addEventListener('uac-ready', work);

function work() {
    // Ask user for password
    // window.UAC.check checks whether password is correct, returns true or false
    // When using UAC, provide null as password if user didn't set any password
    var password=null;
    while (!window.UAC.check(password)) {
        password = prompt('Enter password to use Userscript App Core:');
    }

    // Get GM_* functions using window.UAC.grant(functionName, password)
    const GM_log = window.UAC.grant('GM_log', password);
    const GM_info = window.UAC.grant('GM_info', password);
    GM_log(GM_info);
}

效果如图2。
网站也可以一次性询问密码后储存在localstorage,然后以后直接从localstorage读取密码,除非用户更改密码,否则就可以一直使用。

使用本脚本及其修改或未修改后的再打包/再发布脚本的网站,禁止将用户的密码通过文件导出/网络上传等任何方式带离用户提供密码时使用的浏览器