自定义快捷键
收藏
安装脚本插件如Violent Monkey,然后添加如下脚本:
// ==UserScript== // @name AiStudio shortcut // @namespace Violentmonkey Scripts // @match https://aistudio.baidu.com/*/notebooks/* // @grant BienChen // ==/UserScript== // // (function () { function sleep(ms) { return new Promise(resolve = > setTimeout(resolve, ms)); } async function runAll(e) { // this would test for whichever key is 82 (r) and the meta key at the same time if (e.metaKey && e.keyCode == 82) { run_button = document.querySelectorAll('.notebook-header-menu-list.ant-dropdown-trigger') [2] if (run_button.textContent == '运行') { constevt = new MouseEvent('mouseover', { 'view': window, 'bubbles': true, 'cancelable': true }) run_button.dispatchEvent(evt); awaitsleep(500); button_list = document.querySelectorAll('div.h-m-i-btn') for (var i = button_list.length; i--; ) { if (button_list[i].textContent == '全部运行') { button_list[i].click(); } } } } } async function restartKernel(e) { // this would test for whichever key is 81 (q) and the meta key at the same time if (e.metaKey && e.keyCode == 81) { run_button = document.querySelectorAll('.notebook-header-menu-list.ant-dropdown-trigger') [3] if (run_button.textContent == '环境') { constevt = new MouseEvent('mouseover', { 'view': window, 'bubbles': true, 'cancelable': true }) run_button.dispatchEvent(evt); awaitsleep(500); button_list = document.querySelectorAll('div.h-m-i-btn') for (var i = button_list.length; i--; ) { if (button_list[i].textContent == '重启环境') { button_list[i].click(); } } } } } async function saveResult(e) { // this would test for whichever key is 83 (s) and the ctrl key at the same time if (e.metaKey && e.keyCode == 83) { button1 = document.querySelectorAll('.notebook-header-menu-list.ant-dropdown-trigger') [0] if (button1.textContent == '文件') { constevt = new MouseEvent('mouseover', { 'view': window, 'bubbles': true, 'cancelable': true }) button1.dispatchEvent(evt); awaitsleep(500); button_list = document.querySelectorAll('div.h-m-i-btn') for (var i = button_list.length; i--; ) { if (button_list[i].textContent == '保存') { button_list[i].click(); } } } } } window.addEventListener('keyup', restartKernel, false); window.addEventListener('keyup', runAll, false); window.addEventListener('keyup', saveResult, false); }) ()
其中Meta键(win键)+ r 是全部运行,Meta键+ s 是保存文件,Meta键+ q 是重启环境。
参考:
https://stackoverflow.com/questions/2228376/trigger-onmouseover-event-programmatically-in-javascript
1
收藏
请登录后评论
能用吗? 感觉很厉害的样子~~