Surfingkeys icon indicating copy to clipboard operation
Surfingkeys copied to clipboard

[FR] Running JavaScript bookmarklet via hotkeys

Open Archie-2021 opened this issue 2 years ago • 6 comments

I have JS bookmarklets and I like to trigger them via hotkey, Is there a way to do that? Opening them like a bookmark don't work. Can I add them to settings as a function and run them from there? If the answer is yes how? Sorry but I am new to coding and don't know a lot of stuff still trying to learn.

And thank you for this awesome extension, it makes a lot of difference in my workflow.

Archie-2021 avatar Oct 24 '22 11:10 Archie-2021

It is technically possible to run arbitrary JS on the page with insertJS

Opening them like a bookmark don't work.

What have you tried? I tried before to run JS code from a custom omnibar, I even had that attempt still commented out in my code:

  var myUrls = [
      {
        title: "Home Page",
        url: "javascript:alert('home')",
      },
      {
        title: "wp admin",
        url: "javascript:alert('admin')",
      },
    ];
    Front.openOmnibar({ type: "UserURLs", extra: myUrls });

So I'm guessing that at least from the omnibar, it should be possible to trigger JS that starts with javascript:

Madd0g avatar Oct 25 '22 00:10 Madd0g

It is technically possible to run arbitrary JS on the page with insertJS

Opening them like a bookmark don't work.

What have you tried? I tried before to run JS code from a custom omnibar, I even had that attempt still commented out in my code:

  var myUrls = [
      {
        title: "Home Page",
        url: "javascript:alert('home')",
      },
      {
        title: "wp admin",
        url: "javascript:alert('admin')",
      },
    ];
    Front.openOmnibar({ type: "UserURLs", extra: myUrls });

So I'm guessing that at least from the omnibar, it should be possible to trigger JS that starts with javascript:

Interesting, I just tried to open JS bookmarklets from bookmarks (b mapping) omnibar. can you explain more how to trigger this custom omnibar? I like to give it a try. I should put this in settings put my JS code as url and then what should I map it to?

Archie-2021 avatar Oct 25 '22 05:10 Archie-2021

mapkey("co", "Custom omnibar", function () {
     var myUrls = [
      {
        title: "Home Page",
        url: "javascript:alert('home')",
      },
      {
        title: "wp admin",
        url: "javascript:alert('admin')",
      },
    ];
    Front.openOmnibar({ type: "UserURLs", extra: myUrls });
});

Madd0g avatar Oct 25 '22 19:10 Madd0g

mapkey("co", "Custom omnibar", function () {
     var myUrls = [
      {
        title: "Home Page",
        url: "javascript:alert('home')",
      },
      {
        title: "wp admin",
        url: "javascript:alert('admin')",
      },
    ];
    Front.openOmnibar({ type: "UserURLs", extra: myUrls });
});

I copied this to my setting, first it was giving me "mapkey undefined" error. I added api. before key map and know it shows custom omnibar option in the c menu but when I hit co nothing happens

Archie-2021 avatar Oct 26 '22 10:10 Archie-2021

api.mapkey("co", "Custom omnibar", function () {
     var myUrls = [
      {
        title: "Home Page",
        url: "javascript:alert('home')",
      },
      {
        title: "wp admin",
        url: "javascript:alert('admin')",
      },
    ];
    api.Front.openOmnibar({ type: "UserURLs", extra: myUrls });
});

Adding api. before those 2 lines work for me.

tmrony avatar Sep 21 '23 08:09 tmrony