Github preivew Button

An userscript to add "Rawgit" button on github.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name		Github preivew Button
// @namespace	he
// @description	An userscript to add "Rawgit" button on github.
// @include		https://github.com/*
// @include		https://gist.github.com/*
// @version		8.9.5
// @grant 		none
// ==/UserScript==

/*
https://gist.github.com/eight04/186267c150a2dfc0580a/raw/812fd7b418e0a157f02caa144a15c55c06ced8ac/uao_decode.py
https://rawgit.com/eight04/186267c150a2dfc0580a/raw/812fd7b418e0a157f02caa144a15c55c06ced8ac/uao_decode.py

https://github.com/eight04/linky-square/raw/master/demo.html
https://rawgit.com/eight04/linky-square/master/demo.html
*/

"use strict";

var _BASEURL = 'https://htmlpreview.github.io/?';

function replace() {
    // Check if raw-url button exists
    var btns, i;
    btns = document.querySelectorAll(".file-actions a:not(.rawgit)");
    for (i = 0; i < btns.length; i++) {
        if (btns[i].textContent == "Raw") {
            createButton(btns[i]);
        }
    }
}

function createButton(btn) {
    var url = btn.href;
    if (url.indexOf("gist.github.com") >= 0) {
        url = url.replace(/github\.com/, "githubusercontent.com");
    } else {
        url = url.replace(/github\.com\/([^/]+\/[^/]+)\/raw/, "raw.githubusercontent.com/$1");
    }

    url = _BASEURL + url;

    var newBtn = btn.cloneNode(false);
    newBtn.href = url;
    newBtn.textContent = "Rawgit";
    newBtn.removeAttribute("id");

    btn.parentNode.insertBefore(newBtn, btn.nextSibling);
    btn.classList.add("rawgit");

    if (!btn.parentNode.classList.contains("btn-group")) {
        var parent = btn.parentNode,
            group = document.createElement("div");
        group.className = "btn-group";
        while (parent.childNodes.length) {
            group.appendChild(parent.childNodes[0]);
        }
        parent.appendChild(group);
    }
}

var container =
    document.querySelector("#js-repo-pjax-container") ||
    document.querySelector("#js-pjax-container");

if (container) {
    new MutationObserver(function () {
        replace();
    }).observe(container, { childList: true, subtree: true });
}

replace();