How I use Surfingskeys to quickly copy a GitHub file content by hotkey

Jelly Tran
2 min readJul 27, 2021

--

I usually find myself in need of quick copying a single file content in a GitHub repo, for example, I have this URL

I could quickly copy this file content by the hotkey ctrl+c, look at this demo for better visualization

You can add the customed code as follows:

0. Install Surfingskey if you have not ^^

You can get it here: https://chrome.google.com/webstore/detail/surfingkeys/gfbliohnnapiefjpjlpjnehglfpaknnc

  1. Go to the Surfingkeys options file by using this direct URL:

chrome-extension://gfbliohnnapiefjpjlpjnehglfpaknnc/pages/options.html

2. Adding this function:

function copyToClipboard(message) {
var textArea = document.createElement("textarea");
textArea.value = message;
textArea.style.opacity = "0";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
alert('Copying text command was ' + msg);
} catch (err) {
alert('Unable to copy value , error : ' + err.message);
}
document.body.removeChild(textArea);
}

Note: you could remove the alert when you are sure it could successfully copy to the clipboard, I keep this here as a success notification.

3. Adding code to be executed when using your hotkey, here I use ctrl+c because I use macOS, please be careful so that your hotkey does not overwrite any default hotkey in your current machine

mapkey('<Ctrl-c>', 'copy github file content', function(){
const host = window.location.host
if( host !== "github.com"){
return
}
const htmlNodeContainsCode = "tbody"
const result = document.querySelector(htmlNodeContainsCode);
copyToClipboard(result.innerText)
});

My actual settings look like this:

--

--

Jelly Tran
Jelly Tran

Written by Jelly Tran

jelly, web developer, currently in Singapore

No responses yet