Skip to content

Instantly share code, notes, and snippets.

@mohno007
Last active August 29, 2022 04:39
Show Gist options
  • Save mohno007/50a234f3b401e386583274f47f4e12aa to your computer and use it in GitHub Desktop.
Save mohno007/50a234f3b401e386583274f47f4e12aa to your computer and use it in GitHub Desktop.
🔍 Java Search ☕ : Search Java SE API Documents from Chrome / Firefox Adress Bar

🔍 Java Search ☕ : Search Java SE API Documents from Adress Bar

This UserScript allow you to search Java API documents from address bar.

image

Chrome / Edge

  1. Install UserScript extension
  2. Click this link to install UserScript: https://gist.githubusercontent.com/mohno007/50a234f3b401e386583274f47f4e12aa/raw/java_search.user.js
  3. Register search engines
    1. Open search engines settings
      • Chrome: chrome://settings/searchEngines
      • Edge: edge://settings/searchEngines)
    2. Register search engine (see below)
  4. Now, you can search Java API by type ja keyword or j9 keyword in location bar.

Firefox

  1. Install UserScript extension
  2. Click this link to install UserScript: https://gist.githubusercontent.com/mohno007/50a234f3b401e386583274f47f4e12aa/raw/java_search.user.js
  3. Create a new bookmark
    • Open "Browsing Library Window" (Ctrl + Shift + O , ⌘⇧O)
    • Create a bookmark (Gear Button -> New bookmark)
    • Fill fields (see below)
  4. Now, you can search Java API by type ja keyword or j9 keyword in location bar.

English

//
// |Engine or Name    | Keyword | URL
// |------------------|---------|----------
// |Java API (JDK 9)  | j9      | https://docs.oracle.com/javase/9/docs/api/overview-summary.html?search=%s
// |Java API (JDK 10) | j10     | https://docs.oracle.com/javase/10/docs/api/overview-summary.html?search=%s
// |Java API (JDK 11) | ja      | https://docs.oracle.com/en/java/javase/11/docs/api/index.html?search=%s
// |Java API (JDK 12) | j12     | https://docs.oracle.com/en/java/javase/12/docs/api/index.html?search=%s
// |Java API (JDK 13) | j13     | https://docs.oracle.com/en/java/javase/13/docs/api/index.html?search=%s
// |Java API (JDK 14) | j14     | https://docs.oracle.com/en/java/javase/14/docs/api/index.html?search=%s
// |Java API (JDK 15) | j15     | https://docs.oracle.com/en/java/javase/15/docs/api/index.html?search=%s
// -- FYI
// |Java API (JDK 8)  | j8      | {google:baseURL}search?q=site:https://docs.oracle.com/javase/8/docs/api/+%s

日本語

//
// |Engine or Name    | Keyword | URL
// |------------------|---------|----------
// |Java API (JDK 9)  | j9      | https://docs.oracle.com/javase/jp/9/docs/api/overview-summary.html?search=%s
// |Java API (JDK 10) | j10     | https://docs.oracle.com/javase/jp/10/docs/api/overview-summary.html?search=%s
// |Java API (JDK 11) | ja      | https://docs.oracle.com/javase/jp/11/docs/api/index.html?search=%s
// |Java API (JDK 12) | j12     | https://docs.oracle.com/javase/jp/12/docs/api/index.html?search=%s
// |Java API (JDK 13) | j13     | https://docs.oracle.com/javase/jp/13/docs/api/index.html?search=%s
// |Java API (JDK 14) | j14     | https://docs.oracle.com/javase/jp/14/docs/api/index.html?search=%s
// |Java API (JDK 15) | j15     | https://docs.oracle.com/javase/jp/15/docs/api/index.html?search=%s
// |Java API (JDK 16) | j16     | https://docs.oracle.com/javase/jp/16/docs/api/index.html?search=%s
// |Java API (JDK 17) | j17     | https://docs.oracle.com/javase/jp/17/docs/api/index.html?search=%s
// |Java API (JDK 18) | j18     | https://docs.oracle.com/javase/jp/18/docs/api/index.html?search=%s
// -- FYI
// |Java API (JDK 8)  | j8      | {google:baseURL}search?q=site:https://docs.oracle.com/javase/jp/8/+%s
// ==UserScript==
// @name Java Search
// @namespace https://gist.github.com/mohno007/50a234f3b401e386583274f47f4e12aa/raw/java_search.user.js
// @version 1.0.10
// @description Chromeの検索欄でサクッとJava APIを検索するためのUserscript
// @author Motohiro OHNO
// @match https://docs.oracle.com/javase/*/*/docs/api/*
// @match https://docs.oracle.com/javase/*/docs/api/*
// @downloadURL https://gist.github.com/mohno007/50a234f3b401e386583274f47f4e12aa/raw/java_search.user.js
// @updateURL https://gist.github.com/mohno007/50a234f3b401e386583274f47f4e12aa/raw/java_search.user.js
// @grant none
// @license CC0-1.0
// ==/UserScript==
window.addEventListener('load', function() {
'use strict';
const url = new URL(location.href);
const query = url.searchParams.get('search');
if (!query) return;
const searchField = document.querySelector('#search') ?? document.querySelector('#search-input');
const id = setInterval(() =>{
if (searchField.value === query) clearInterval(id);
searchField.value = query;
searchField.dispatchEvent(new Event('input'));
}, 100); // Java 11のドキュメントはすぐに入れると、クリアされてしまうので何度か入れ直す
// 最初の項目を選択(jQuery UIがある想定)
const menu = document.querySelector('#ui-id-1');
$(menu).menu("focus", null, menu.querySelector(".ui-menu-item:first"));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment