Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do this for my Chrome extension <a href="https://chrome.google.com/webstore/detail/npgcapmdmghagoiccaojjmpgbccicikj" rel="nofollow"><em>Lil’ Launch</em></a> which has no use for the default suggestion (it only searches your bookmarks).</p> <p>The full source is <a href="https://github.com/icelab/lil-launch/blob/master/background.js" rel="nofollow">on Github</a>, but the general idea is this. The callback for <code>chrome.omnibox.onInputEntered</code> gets passed either the <code>content</code> property of your selection <em>or</em> the value of the user input if the suggestion is the default one. So I append a known string to the front of all the <code>content</code> properties and check for that same string when <code>chrome.omnibox.onInputEntered</code> fires. It needs to be something that the use is unlikely to type, otherwise the matching will break.</p> <pre><code>var resultsList = [], // Accessible from the callback scope unlikely = "GOSHDARNYOUCHROME"; // Our unlikely to be typed String chrome.omnibox.onInputChanged.addListener( function(text, suggest) { var searchResults = chrome.bookmarks.search(text, function(searchResults) { resultsList = []; for (var i = 0; i &lt; searchResults.length; i++) { resultsList.push({ content: unlikely + item.url, // Prepend our unlikely string to the URL description: "bar" }); }; // Chrome adds a completely useless default suggestion in our case // So set the default and slice it off the suggestions chrome.omnibox.setDefaultSuggestion({ description: resultsList[0].description }); suggest(resultsList.slice(1, -1)); }) } ); chrome.omnibox.onInputEntered.addListener( function(text) { // If text doesn't have unlikely prepended its the stupid default if(text.substring(0, unlikely.length) !== unlikely) { text = resultsList[0].content; } text = text.substring(unlikely.length); // Trim the unlikely string // Do something with text } ); </code></pre> <p>Stupid, but effective.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload