V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
VisualStudioCode
V2EX  ›  问与答

寻求浏览器插件:按一下快捷键就能执行一段 JavaScript 脚本,提前写好并专门针对这个网站的

  •  
  •   VisualStudioCode · 10 天前 · 838 次点击

    针对不同网站有不同的、提前写好的一段 JavaScript 脚本。

    快捷键是固定的,只要按下就能执行专门针对当前网站的那段 JavaScript 脚本。

    8 条回复    2025-05-06 09:34:20 +08:00
    fbzl
        1
    fbzl  
       10 天前 via iPhone
    Automa
    irrigate2554
        2
    irrigate2554  
       10 天前
    写个猴油脚本不就行了,插件的话我用的暴力猴,https://violentmonkey.github.io/
    VisualStudioCode
        4
    VisualStudioCode  
    OP
       9 天前
    @SayHelloHi 我安装了,也查了文档、问了 AI ,但是发现似乎不提供快捷键?
    kframe
        5
    kframe  
       9 天前
    chrome 的书签就行满足: https://juejin.cn/post/7496396598731833380
    VisualStudioCode
        6
    VisualStudioCode  
    OP
       9 天前
    @kframe 我知道 Bookmarklet——但是怎么给一个书签绑定快捷键呢?
    SayHelloHi
        7
    SayHelloHi  
       9 天前   ❤️ 1
    @VisualStudioCode #4

    刚刚测试了 按下 shift+j 控制台有打印信息和有弹出框

    function run() {
    console.log('Shift + J detected. Running the function...');
    // 在这里添加你希望执行的逻辑
    alert("Hi")
    }

    document.addEventListener('keydown', function(event) {
    if (event.shiftKey && event.key.toLowerCase() === 'j') {
    run();
    }
    });
    VisualStudioCode
        8
    VisualStudioCode  
    OP
       9 天前
    @SayHelloHi #7 哦!它是进入网页就自动执行哦!我还以为需要鼠标点右上角插件图标才能执行。那我懂了,谢谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1411 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:05 · PVG 01:05 · LAX 10:05 · JFK 13:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.