显示 Github.dev 按钮

在 Github 网站顶部显示 Github.dev 按钮,Github.dev 是一个利用 VsCode Online 浏览代码的项目

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         显示 Github.dev 按钮
// @icon         https://github.com/favicons/favicon-codespaces.svg
// @namespace    https://github.com/akkuman
// @version      1.0.0
// @description  在 Github 网站顶部显示 Github.dev 按钮,Github.dev 是一个利用 VsCode Online 浏览代码的项目
// @author       Akkuman
// @match        https://github.com/*
// @grant        none
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.slim.min.js
// @reference    https://greasyfork.org/zh-CN/scripts/421631-%E6%98%BE%E7%A4%BA-github1s-%E6%8C%89%E9%92%AE
// ==/UserScript==

(function () {
    'use strict';
    createButton();
    $(document).on("pjax:end", ()=>{
        createButton();
    });
})();

/**
 * 创建 Github.dev 按钮
 */
function createButton() {
    const preSelectorButton = document
        .querySelector("#githubdevButton");

    if (preSelectorButton !== null) {
        return;
    }

    const githubdevUrl = `https://Github.dev${location.pathname}`;
    const element = '<li id="githubdevButton"> <a target="_blank" class="btn btn-sm" href="' + githubdevUrl + '"> <img class="icon octicon octicon-heart text-pink" src="https://github.com/favicons/favicon-codespaces.svg" /> Github.dev </a> </li>';
    const node = document.querySelector('.pagehead-actions.flex-shrink-0.d-none.d-md-inline');
    if(node !== null){
        node.insertAdjacentHTML('afterBegin', element);
    }
}