Last active
October 7, 2015 01:19
-
-
Save r007/9702cc0848e4bc75e9ae to your computer and use it in GitHub Desktop.
This file contains 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 Sheets SVG chart copier | |
// @namespace https://github.com/r007 | |
// @version 0.2 | |
// @description Auto copies SVG code when user clicks on chart | |
// @author Sergey Monin (https://github.com/r007) | |
// @match *://docs.google.com/spreadsheets/* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js | |
// @grant GM_setClipboard | |
// ==/UserScript== | |
setInterval(function() { | |
$("svg").off('click').on('click', function() { | |
var fixed_svg = remove_links($(this)[0].outerHTML); | |
GM_setClipboard(fixed_svg); | |
alert('SVG image was copied to clipboard!'); | |
}); | |
}, 1000); | |
function remove_links(text) { | |
var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; | |
return text.replace(urlRegex, function(url) { | |
return '#' + url.split("#")[1]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment