×
Falcon
2024-09-06 16:15
#daily tips# v2ex AI 回答问题 油猴脚本:
实现 AI 回答 v2ex 帖子中的问题,结合回复高赞赏回答给出更有帮助性建议。
https://greasyfork.org/zh-CN/scripts/506898-v2ex-ai-%E5%9B%9E%E7%AD%94%E9%97%AE%E9%A2%98
-----------------
btw, 我刚发现v2ex由于同时使用www和非www,这两者是不共享localstorage的,需要重复设置,不能依赖localstorage,但可以使用油猴提供的函数,在多个域名之间共享数据:
// 保存 API Key

GM_setValue('apikey', 'your_api_key_here');

// 获取 API Key
const apikey = GM_getValue('apikey');
console.log(apikey);
// 删除 API Key
GM_deleteValue('apikey');
-----------------
处理 安全问题




虽然油猴脚本存储的数据是以纯文本形式保存的,但你可以通过简单的加密来增加一层保护。加密 API key 后存储,并在需要时解密,这样即便数据被泄露,它也是不可直接使用的。
例如,使用 CryptoJS 库进行简单加密:
// 加密和保存 API Key

const encryptedKey = CryptoJS.AES.encrypt('your_api_key_here', 'secret_passphrase').toString();

GM_setValue('apikey', encryptedKey);
// 获取和解密 API Key
const storedKey = GM_getValue('apikey');
const decryptedKey = CryptoJS.AES.decrypt(storedKey, 'secret_passphrase').toString(CryptoJS.enc.Utf8);
console.log(decryptedKey);
 
更多:https://d.cellmean.com/p/c3e2a3e936b4
 
0

暂无评论