Skip to content

Instantly share code, notes, and snippets.

@dipsywong98
Created August 6, 2022 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dipsywong98/5a951db953f07194cc1827bb91b5532f to your computer and use it in GitHub Desktop.
Save dipsywong98/5a951db953f07194cc1827bb91b5532f to your computer and use it in GitHub Desktop.
Inject github page link tampermonkey script

Effect: (click it will go to the page)

// ==UserScript==
// @name Inject github page link
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Dipsy Wong
// @match https://github.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const el = document.querySelector('a[data-pjax="#repo-content-pjax-container"]')
const [_,username,repoName] = el.href.match(/^https:\/\/github.com\/(.*)\/(.*)$/)
let url = `${username}.github.io`
url = `https://${url}/` + (repoName === url ? '' : repoName)
const a = document.createElement('a')
a.className+=' Label Label--secondary v-align-middle mr-1'
a.href = url
a.innerHTML = 'gh-page'
el.parentNode.parentNode.append(a)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment