ryoakg
5/31/2016 - 3:59 AM

github-search-cheatsheet.user.js

// ==UserScript==
// @name         github search cheatsheet
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  display example usage to github-search
// @author       ryo
// @match        *://github.com/*
// @match        *://gist.github.com/*
// @grant        none
// ==/UserScript==
// notation: https://wiki.greasespot.net/Metadata_Block

(function() {
    'use strict';

    var d = document;
    function tooltipElement () {
	var o = d.createElement('div');
	o.className = 'query-tooltip';
	o.style.display = 'none';
	o.style.zIndex = 9999;
	// color
	o.style.backgroundColor = '#666';
	o.style.color = '#f0f8ff';
	o.style.opacity = 0.95;
	// position & size
	o.style.position = 'absolute';
	o.style.top = '30px';
	o.style.left = '100px';
	o.style.width = '200px';
	o.style.padding = '20px';
	o.style.borderRadius = '15px';

	var ul = d.createElement('ul');
	ul.innerHTML = ['in:file,path',
		        'path:app/public',
		        'filename:.vimrc',
		        'language:xml',
		        'extension:pm',
		        '',
		        'user:mozilla',
		        'repo:mozilla/shumway',
		        '',
		        'size:100',
		        'size:>10000',
		       ].reduce(function(a,s){
			   return a + '<li>' + s + '</li>'; }, '');
	o.appendChild(ul);
	o.innerHTML += '<br /><a target="_blank" href="https://help.github.com/articles/searching-code/">for more info.</a>';
	return o;
    }

    // 検索する form の指定
    [d.querySelector('form[action$="/search"]'),]
        .filter(function (form) { return form; }) // 見付からなかったものをはじく
    	.forEach(function (form){
	    var tooltip = tooltipElement();
	    form.style.position = 'relative';
	    form.appendChild(tooltip);
	    var i = form.querySelector('input[type=text]');
	    i.addEventListener('focus',function(){
	        tooltip.style.display = 'block';
	    });
	    i.addEventListener('blur',function(){
	        setTimeout(function(){ tooltip.style.display = 'none';}, 1500);
	    });
	});

})();