Skip to content

Instantly share code, notes, and snippets.

@dance2die
Last active December 18, 2019 22:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/7c79a1e09b334da6d723bd07e2bb7682 to your computer and use it in GitHub Desktop.
Save dance2die/7c79a1e09b334da6d723bd07e2bb7682 to your computer and use it in GitHub Desktop.
const code = `(function getUrls(){
const forkUrl = document.querySelector('meta[name="octolytics-dimension-repository_parent_nwo"]')
? document.querySelector('meta[name="octolytics-dimension-repository_parent_nwo"]').content
: undefined;
const url = document.querySelector('meta[name="go-import"]')
? document.querySelector('meta[name="go-import"]').content.split(' ')[0]
: undefined;
const href = window.location.href;
return { forkUrl, url, href };
})()`;
chrome.tabs.executeScript(tabId, { code }, function(result) {
const { forkUrl, url, href } = result[0];
if (forkUrl) {
document.getElementById("url").innerText = `
git remote add upstream https://github.com/${forkUrl}
git fetch upstream
git branch --set-upstream-to=upstream/master master`;
} else if (url) {
document.getElementById("url").innerText = `
git remote add upstream https://${url}
git fetch upstream
git branch --set-upstream-to=upstream/master master`;
} else {
document.getElementById("url").innerText = `
git remote add upstream ${href}
git fetch upstream
git branch --set-upstream-to=upstream/master master`;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment