RCNB

Get highlighted when RCNB.

// ==UserScript==
// @name         RCNB
// @namespace    https://rcnb.app/
// @version      0.1.2
// @description  Get highlighted when RCNB.
// @author       Coxxs
// @match        https://github.com/*
// @match        https://*.github.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function addGlobalStyle(css) {
        let head, style
        head = document.getElementsByTagName('head')[0]
        if (!head) return
        style = document.createElement('style')
        style.type = 'text/css'
        style.innerHTML = css
        head.appendChild(style)
    }

    let rcnbCss = `
.rcnb {
    border: 5px solid #1565C0 !important;
    border-radius: 10px !important;
    position: relative !important;
}

.rcnb:before {
    content: "RCNB™";
    background: #1565c0;
    position: absolute;
    top: -5px;
    right: -5px;
    padding: 1px 7px;
    border-radius: 5px;
    color: white;
}

.rcnb-home {
    padding: 0 15px !important;
    margin-top: 5px !important;
    margin-bottom: 5px !important;
}

.rcnb-commit {
}

.rcnb-commit {
    border-top-right-radius: 7px !important;
}

.rcnb-commit:before {
    top: -23px;
    border-bottom-right-radius: 0;
}

.rcnb-commit li:first-child .table-list-cell:first-child {
    border-top-left-radius: 5px;
}
.rcnb-commit li:first-child .table-list-cell:last-child {
    border-top-right-radius: 5px;
}
.rcnb-commit li:last-child .table-list-cell:first-child {
    border-bottom-left-radius: 5px;
}
.rcnb-commit li:last-child .table-list-cell:last-child {
    border-bottom-right-radius: 5px;
}

.remove-border-bottom > div > .border-bottom { border-bottom: none!important; }
`
    addGlobalStyle(rcnbCss);

    function updateGithub() {
        let doms

        doms = document.querySelectorAll(".news .flex-items-baseline div a[href=\"/richardchien\"]")
        if (doms.length) {
            doms.forEach(function(dom) {
                let rcdom = dom.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement
                if (rcdom.classList.contains('rcnb')) return
                rcdom.classList.add('rcnb', 'rcnb-home', 'remove-border-bottom')
                let previousdom = rcdom.previousSibling.previousSibling
                if (previousdom && previousdom.classList) {
                    previousdom.classList.add('remove-border-bottom')
                }
            })
        }

        doms = document.querySelectorAll(".commits-listing a.commit-author[href$=\"=richardchien\"]")
        if (doms.length) {
            doms.forEach(function(dom) {
                let rcdom = dom.parentElement.parentElement.parentElement.parentElement.parentElement
                if (rcdom.classList.contains('rcnb')) return
                rcdom.classList.add('rcnb', 'rcnb-commit')
            })
        }
    }

    var mutationObserver = new MutationObserver(function(mutations) {
        updateGithub()
    })
    mutationObserver.observe(document.documentElement, {
        attributes: false,
        characterData: false,
        childList: true,
        subtree: true,
        attributeOldValue: false,
        characterDataOldValue: false
    });
    updateGithub()

})();