Skip to content

Instantly share code, notes, and snippets.

@sosloow
Created April 16, 2014 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sosloow/10836523 to your computer and use it in GitHub Desktop.
Save sosloow/10836523 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name iichan.hk search
// @description iichan.hk search
// @author :^)
// @version 0.1
// @include http://iichan.hk/*
// ==/UserScript==
(function() {
'use strict';
var searchbox = document.createElement('gcse:searchbox'),
searchresults = document.createElement('gcse:searchresults'),
searchlink = document.createElement('a'),
searchbar = document.createElement('div'),
resultsContainer = document.createElement('div'),
adminbar = document.getElementsByClassName('adminbar')[0],
logo = document.getElementsByClassName('logo')[0],
boardname = document.location.pathname.split('/')[1];
if (!(adminbar || logo)) return;
searchlink.href = '#';
searchlink.textContent = 'Поиск';
searchlink.id = 'search-link';
adminbar.innerHTML += ' [' + searchlink.outerHTML + ']';
searchbar.id = 'search-bar';
searchbar.appendChild(searchbox);
searchbar.style.display = 'none';
searchbar.style.width = '300px';
searchbar.style.margin = '5px';
searchbar.style.cssFloat = 'right';
adminbar.innerHTML += '<br>';
adminbar.appendChild(searchbar);
resultsContainer.style.display = 'none';
resultsContainer.id = 'results-container';
resultsContainer.appendChild(searchresults);
document.body.insertBefore(resultsContainer, logo);
searchbox.setAttribute('defaultToRefinement', boardname);
document.getElementById('search-link')
.addEventListener('click', function(e) {
e.preventDefault();
var searchbar = document.getElementById('search-bar');
if (searchbar.style.display=='none')
searchbar.style.display = 'block';
else
searchbar.style.display = 'none';
var resultsContainer = document.getElementById('results-container');
if (resultsContainer.style.display=='none')
resultsContainer.style.display = 'block';
else
resultsContainer.style.display = 'none';
});
var cx = '016509237818063101895:p522qbpqjui';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment