Link between Github Pages and their repos

Adds a link to the DOM to quickly switch between github repos and their deployed Github Pages.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Link between Github Pages and their repos
// @namespace    https://jonas.ninja
// @version      1.0.0
// @description  Adds a link to the DOM to quickly switch between github repos and their deployed Github Pages.
// @author       @iv_njonas
// @match        https://*.github.io/*
// @match        https://*.github.com/*
// @grant        GM_addStyle
// ==/UserScript==
/* jshint asi: true, multistr: true */

(function() {
    var imgs = {
        small: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAqpJREFUSEuNlTtrVFEUha+DioKFoI0aER8pBMVCCwstxCKFIqI/wU7BKhCw1Eq0CGn0T2ihhSRVJJn3+/1OSpEYC4kiSSbj+m72nRwnk8ks2HDu3muts/c59854g1CrN44kU+nr8URyUvElHIl+X1gMbxKsyVGDA9dkw5EvFE/F4onXMmjIaEvR3SO24MBFY/LdqFRrB1PpzC2RcxLR3SCzQcEUObR4mN0O0pnsbRFKIg7rcq+g+xIeZrcNjXJahTyExXBkTeN91PNXrVfJKdbJE6yNtwoHruU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ku59ZAUAAAAASUVORK5CYII='
    }
    function insertLinks() {
        var username
        var appname
        var url
        // detect whether we're on github.io or github.com and insert the appropriate markup

        if ('io' === window.location.host.split('.')[2]) {
            username = window.location.origin.split(/[\.\/]/)[2]
            appname = window.location.pathname.split('/')[1]
            url = '//www.github.com/' + username + '/' + appname
            document.body.append(createLink(url, "Go to this project's repo", false, 'ijg-ghPagesToRepo'))
        } else {
            // ensure that this is a repo and not some other github page
            var repoHeadActions = document.querySelector('.repohead-details-container .pagehead-actions')
            if (!repoHeadActions) return

            username = window.location.pathname.split('/')[1]
            appname = window.location.pathname.split('/')[2]
            url = '//' + username + '.github.io/' + appname
            var li = document.createElement('li')
            li.append(createLink(url, "Go to Github Pages", true))
            repoHeadActions.prepend(li)
        }
    }

    function createLink(url, title, isSmall, optLinkClass) {
        var link = document.createElement('a')
        link.className = 'ijg-link ' + (optLinkClass || '')
        link.href = url

        var img = document.createElement('img')
        img.src = isSmall ? imgs.small : imgs.medium
        img.title = title

        link.append(img)
        return link
    }

    var styles = '\
a.ijg-link:hover {\
    background-color: gray;\
}\
a.ijg-link {\
    background-color: black;\
    padding: 3px;\
    line-height: 0;\
    border-radius: 4px;\
    display: inline-block;\
    text-decoration: none;\
    transition: background-color 150ms;\
}\
a.ijg-ghPagesToRepo {\
    top: 20px;\
    right: 20px;\
    border-radius: 6px;\
    position: absolute;\
}'

    GM_addStyle(styles)

    insertLinks()
    document.addEventListener('pjax:complete', insertLinks)
})();