ueokande / vim-vixen

Accelerates your web browsing with Vim power!!
https://ueokande.github.io/vim-vixen/
MIT License
2.11k stars 137 forks source link

Use the browser search engine settings #99

Open dannycolin opened 6 years ago

dannycolin commented 6 years ago

I'm opening this issue because:

Description

Use the browser search engine settings instead of Google as the default search engine. If the user choose to use a different search engine or if he delete Google from the search engine list the plugin should respect the user choice.

Failure Information (for bugs)

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. step 1
  2. step 2
  3. you get it...

System configuration

Console logs

Any relevant log in developer tools:

ueokande commented 6 years ago

It might a limitation of WebExtensions API.

dannycolin commented 6 years ago

Oh yeah. I did'nt think about that new WebExtension thing :). Anyway, after a quick search I've found that there's a feature request on the Mozilla Bugzilla.

An other option, would be to create a page or a menu for the addon where we could choose the default search engine from the list that is present in the addon.

dannycolin commented 6 years ago

Oh I forgot that https://github.com/Smile4ever/webext-experiment-searchengines I've got that link from the #extdev channel on the Mozilla IRC.

reading123 commented 6 years ago

I'm using "Shortkeys (Custom Keyboard Shortcuts) for Firefox" addon and the builtin keyboard shortcut ctrl+l as suggested by the developer to get around this. Simply remap "t" in vim vixen settings to something random, then add a shortcut in the aforementioned addon to open a new tab. REgards,

jcaesar commented 6 years ago

You're probably aware of it, but just to mention it: Firefox already supports defining short commands for search engines (Right click some search field, ~"Add keyword for this search"). It would be nice if that list could be used as a fallback if no shortcut is defined in Vim Vixen.

jcaesar commented 6 years ago

Until there is a proper API for this, I found that

function mangle(bookmarks, se) {
    bookmarks.forEach(function(bookmark) {
        if (bookmark.type == 'bookmark' && bookmark.url.includes("%s")) {
            var shorty = new URL(bookmark.url).hostname.split('.').filter(function (l) { return l != "www" && !(l in se); })[0]; // Do not put in production, this may fail!
            se[shorty] = bookmark.url.replace(/%s/, '{}');
        }
        if (bookmark.children)
            mangle(bookmark.children, se);
    });
}

browser.bookmarks.getTree().then(
    function (bookmarks) {
        var se = {};
        mangle(bookmarks, se);
        console.log(JSON.stringify(se, undefined, 2));
    },
    function(error) {
        console.log(`An error: ${error}`);
    }
);

/* has to be placed in the background script of a web extension */

can provide a somewhat decent workaround for initially populating vim vixens search engine configuration. It can't, however, extract the correct search keywords.

retrohacker commented 5 years ago

Heya, came here to see if there was an open PR and found this issue. Looks like, as of Firefox 63, there is a new search API for WebExtensions.

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/search/get

This should allow us to grab the default search engine on Vim Vixen load.

Also, we should be able to offload the actual search functionality to the browser using

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/search/search

Which can open a search using either the default search engine or a user provided search engine.

chen-chao commented 4 years ago

@jcaesar Don't know why Firefox doesn't provide an api to access the bookmark's keyword field. I think It's quite useful. #206 and #656 are same issues on this.

@retrohacker search.search will open the page in a tab directly. This is not consistent with vim vixen's working flow now.

xeruf commented 3 years ago

Heyho, it seems this issue is stalling - I would love to see it implemented :)