Git Product home page Git Product logo

search-extension-core's Introduction

Search Extension Core

license-mit license-apache

This is the core source code repository for search extensions, written in vanilla Javascript.

Overview

A list of search extensions based on this project:

Everyone can build their search extension with this project. Here are some awesome search extensions from the community:

API

Omnibox

constructor(defaultSuggestion, maxSuggestionSize)

let omnibox = new Omnibox(
    // The default suggestion title.
    defaultSuggestion="A handy search extension.",
    // Max suggestion size for per page.
    maxSuggestionSize=8,
);

bootstrap(config)

Bootstrap the omnibox.

  • config: The configuration object to bootstrap the Omnibox.
{
    // The default global search function
    onSearch: function(query){},
    onFormat: function(index, item){},
    onAppend: function(query){},
    onEmptyNavigate: function(content, disposition) {},
    beforeNavigate: function(content) {},
    afterNavigated: function(query, result) {},
}
  • config.onSearch: A hook function to perform the default search.
  • config.onFormat: A hook function to format the search result.
  • config.onAppend: A hook function append the custom item to the result list.
  • config.beforeNavigate: A hook function to before URL navigate. You have the last chance to modify the url before it navigated.
  • config.afterNavigate: A hook function to after URL navigated. You have the chance to record the history here.
  • config.onEmptyNavigate: If the content is a Non-URL which would navigate failed, then fallback to this hook function.

addPrefixQueryEvent(prefix, event)

Add prefix query event.

addRegexQueryEvent(regex, event)

Add regex query event.

addNoCacheQueries(...queries)

Add query keyword to prevent cache result.

QueryEvent

{
    onSearch,
    onFormat = undefined,
    onAppend = undefined,
    prefix = undefined,
    regex = undefined,
    // Whether enable the query as a default search.
    // Default search means user can perform search without any sigils.
    defaultSearch = false,
    // The hook method to enable default search dynamically.
    // This hook method is preferred over defaultSearch property.
    isDefaultSearch = undefined,
    // The default search priority. The smaller, the higher.
    searchPriority = 0
}

Command

An interface representing a command, you should extend this class to build a custom command.

constructor(name, description)

  • name: The command name, for example help.
  • description: The command description, for example Show the help messages.

onExecute(arg)

A hook method the subclass should implement to execute the command with the arg.

onBlankResult(arg)

A hook method when the command result is empty.

onEnter(content, disposition)

A hook method called when press enter on command directly.

CommandManager

constructor([prefix, ]commands)

Construct the CommandManager with default commands. The prefix for commands is configurable through prefix, which if not provided defaults to :.

execute(query)

Execute command according matched query.

handleCommandEnterEvent(content, disposition)

Handle command enter event.

Builtin commands

  • HistoryCommand - A command to record search histories.
  • SimpleCommand - A simple command to quick setup a list item of [name, url, description] data search.
  • OpenCommand - A command simply to quick open the specific url.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

search-extension-core's People

Contributors

folyd avatar pitkley avatar shwin0901 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.