YAKIUDON

    @@ -1,25 +1,47 @@ /* * @title YAKIUDON - * @description Googleの検索結果URLから余分なパラメータ削除するやつ https://gist.github.com/1977606 + * @description Googleの検索結果URLから余分なパラメータ削除するやつ https://gist.github.com/4335049 * @include http://www.google.co.jp/search* * @include https://www.google.co.jp/search* * @license MIT License * @require */ -var script = document.createElement('script'); -script.textContent = '(' + (function () { - var u = location.href.split('?'); - var q = u[1].split('&'), n = []; - for (var i = 0; i < q.length; i++) - if (q[i].match(/^(?:q|tbm|tbs)=/)) - n.push(q[i]); - var url = u[0].replace('www.', '') + '?' + n.join('&'); - var input = document.createElement('input'); - input.setAttribute('type', 'text'); - input.setAttribute('size', 60); - input.setAttribute('value', url); - document.getElementById('resultStats').appendChild(input); -}).toString() + ')();'; -document.body.appendChild(script); -document.body.removeChild(script); +(function(d) { + var script = d.createElement('script'); + + script.textContent = '(' + function(d, l) { + var href = l.href + , hash_index = href.indexOf('#') + , query_index = href.indexOf('?') + , hash = hash_index < 0 ? '' : href.substring(hash_index + 1) + , query = query_index < 0 ? '' : href.substring(query_index + 1, hash_index < 0 ? href.length : hash_index) + , params = {} + , p = []; + + [query, hash].forEach(function(item) { + item.split('&').forEach(function(item) { + var param = item.split('='); + params[param[0]] = param[1]; + }); + }); + + for (var n in params) + /^(?:q|tbm|tbs)$/.test(n) && p.push(n + '=' + params[n]); + + var url = l.protocol + '//' + l.host.replace(/^www\./, '') + l.pathname + '?' + p.join('&') + , input = d.createElement('input') + , to = d.getElementById('gbx3') || d.getElementById('gbx1'); + + input.setAttribute('type', 'text'); + input.setAttribute('size', 60); + input.setAttribute('value', url); + input.style.position = 'absolute'; + input.style.right = '0'; + + to.appendChild(input); + } + ')(document, location);'; + + d.body.appendChild(script); + d.body.removeChild(script); +})(document);
  • /*
     * @title YAKIUDON
     * @description Googleの検索結果URLから余分なパラメータ削除するやつ https://gist.github.com/4335049
     * @include http://www.google.co.jp/search*
     * @include https://www.google.co.jp/search*
     * @license MIT License
     * @require 
     */
    
    (function(d) {
      var script = d.createElement('script');
     
    	script.textContent = '(' + function(d, l) {
    		var   href = l.href
    			, hash_index = href.indexOf('#')
    			, query_index = href.indexOf('?')
    			, hash = hash_index < 0 ? '' : href.substring(hash_index + 1)
    			, query = query_index < 0 ? '' : href.substring(query_index + 1, hash_index < 0 ? href.length : hash_index)
    			, params = {}
    			, p = [];
    		
    		[query, hash].forEach(function(item) {
    			item.split('&').forEach(function(item) {
    				var param = item.split('=');
    				params[param[0]] = param[1];
    			});
    		});
     
    		for (var n in params)
    			/^(?:q|tbm|tbs)$/.test(n) && p.push(n + '=' + params[n]);
     
    		var   url = l.protocol + '//' + l.host.replace(/^www\./, '') + l.pathname + '?' + p.join('&')
    			, input = d.createElement('input')
    			, to = d.getElementById('gbx3') || d.getElementById('gbx1');
     
    		input.setAttribute('type', 'text');
    		input.setAttribute('size', 60);
    		input.setAttribute('value', url);
    		input.style.position = 'absolute';
    		input.style.right = '0';
     
    		to.appendChild(input);
    	} + ')(document, location);';
     
    	d.body.appendChild(script);
    	d.body.removeChild(script);
    })(document);
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2012/12/19 16:32:04 - 2012-12-19
  2. 2012/03/06 02:47:21 - 2012-03-06