有一个需求,在浏览器中点击收藏栏的按钮,加载一段JS代码,并执行返回结果,经测试有效。
javascript:function loadScript(src, callback) {let script = document.createElement('script');script.src = src;script.onload = () => callback(script);document.head.append(script);}loadScript('https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/crypto-js/4.1.1/crypto-js.js', script => {var b64 = CryptoJS.AES.encrypt(location.href, 'kaixing.wang', {mode: CryptoJS.mode.ECB}).toString();var e64 = CryptoJS.enc.Base64.parse(b64);var eHex = e64.toString(CryptoJS.enc.Hex); window.open('https://www.kaixing.wang/#'+encodeURIComponent(eHex));});void(0);
因为浏览器收藏栏只能一行写入,下面是格式化的代码,以方便理解。
javascript: function loadScript(src, callback) {
let script = document.createElement('script');
script.src = src;
script.onload = () = > callback(script);
document.head.append(script);
}
loadScript('https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/crypto-js/4.1.1/crypto-js.js', script = > {
var b64 = CryptoJS.AES.encrypt(location.href, 'kaixing.wang', {
mode: CryptoJS.mode.ECB
}).toString();
var e64 = CryptoJS.enc.Base64.parse(b64);
var eHex = e64.toString(CryptoJS.enc.Hex);
window.open('https://www.kaixing.wang/#' + encodeURIComponent(eHex));
});
void(0);