Last active
February 29, 2020 08:23
-
-
Save ronekko/8ab04ff329ea9804e2df03847a4f07eb to your computer and use it in GitHub Desktop.
Google Search - "Quote" link
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
// ==UserScript== | |
// @name Google Search - "Quote" link | |
// @namespace http://d.hatena.ne.jp/blooo/ | |
// @description Add a "Quote/Dequote" link to Google search | |
// @include https://*.google.tld/search?* | |
// @version 1.02.20170222 | |
// @grant GM_addStyle | |
// ==/UserScript== | |
(function() { | |
var baseurl = document.location.href; | |
baseurl = baseurl.replace(/&$/, ''); | |
console.log(baseurl); | |
var quoted_url = baseurl.replace(/([&|?])q=([^&]+)&?/, '$1'); | |
var current_query = (RegExp.$2) ? RegExp.$2 : ''; | |
var word; | |
if(current_query.match(/^%22(.*)%22$/)) | |
{ | |
//already quoted | |
current_query = RegExp.$1; | |
quoted_url = quoted_url.replace(/&/g, '&') + '&q=' + current_query; | |
word = "Dequote"; | |
} | |
else | |
{ | |
quoted_url = quoted_url.replace(/&/g, '&') + '&q="' + current_query + '"'; | |
word="Quote"; | |
} | |
var quoted_link = '<a href="' + quoted_url + '">' + word + '</a>'; | |
var html = '<span id="links">' + quoted_link + '</span>'; | |
GM_addStyle("div[id=links] { margin:2px 10px 0 0px; display:block; }"); | |
var node = document.getElementById('resultStats') || document.querySelectorAll('#subform_ctrl > div')[2] || | |
document.querySelector('#mBMHK') || document.querySelector('#result-stats'); | |
node.innerHTML = node.innerHTML + html; | |
// with(document.getElementById('ssb').firstChild) { innerHTML = innerHTML + html.toXMLString() }; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment