Last active
December 9, 2015 22:08
-
-
Save tatat/4335049 to your computer and use it in GitHub Desktop.
Googleの検索結果URLから余分なパラメータ削除するやつ - http://let.hatelabo.jp/uneco/let/gYC-yby_yIjbcQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var url = require('url'); | |
try { | |
process.stdout.write(ggtrim(process.argv[2])) | |
} catch (err) { | |
process.stderr.write(err.message + '\n'); | |
process.exit(1); | |
} | |
function ggtrim(href) { | |
var l = url.parse(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]); | |
return l.protocol + '//' + l.host.replace(/^www\./, '') + l.pathname + '?' + p.join('&'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment