newLISP Documentation Search

Provide keyword search interface in newLISP documentation

Stan na 01-10-2014. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name      newLISP Documentation Search
// @namespace http://lambda.que.jp/
// @version   20141001
// @description  Provide keyword search interface in newLISP documentation
// @grant   GM_addStyle
// @grant   GM_getResourceText
// @match   http://www.newlisp.org/*/newlisp_manual.html
// @require http://code.jquery.com/jquery-2.1.1.js
// @require http://code.jquery.com/ui/1.11.1/jquery-ui.js
// @resource jquery-ui.css http://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css
// @author  KOBAYASHI Shigeru (kosh)
// @license Public Domain
// ==/UserScript==

GM_addStyle([
    GM_getResourceText("jquery-ui.css"),
    ".search-control {",
    "  position: fixed;",
    "  top: 10px;",
    "  right: 20px;",
    "}",
    ".ui-autocomplete {",
    "  max-height: 100px;",
    "  overflow-x: hidden;",
    "  overflow-y: auto;",
    "}",
].join("\n"));

$("body").prepend([
    "<div class='search-control ui-widget' role='search'>",
    " <label for='keyword' style='display:none;'>Search:</label>",
    " <input id='keyword' type='search' placeholder='Search keyword' autofocus>",
    "</div>",
].join("\n"));

function create_keywords() {
    var keywords = [],
        grep = function(obj, key, value) {
        return $.grep(obj, function(e) { return e[key] === value; });
    };

    $("a[href]").each(function(i, a) {
        var hash = a.hash.slice(1), // #hash -> hash
            href = a.href;
        if (hash.length == 0 || grep(keywords, "href", href).length > 0) {
            return;
        }
        keywords.push({ "label": hash, "href":  href });
    });

    return keywords;
}

$("#keyword").autocomplete({
    source: create_keywords(),
    select: function(event, ui) {
        window.location.replace(ui.item.href);
    }
});