GitHub 便捷按钮

为Github仓库添加一键打开github1s和vscode dev的按钮

当前为 2025-04-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         GitHub 便捷按钮
// @version      1.0.0
// @description  为Github仓库添加一键打开github1s和vscode dev的按钮
// @author       Liao Brant
// @license      MIT
// @noframes
// @grant        window.onurlchange
// @match        https://github.com/*
// @namespace https://greasyfork.org/users/286362
// ==/UserScript==

(() => {
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);

function insertButton() {
  const actions = $('.pagehead-actions');
  if (actions == null || $('#github1s-button')) return;
  const btnHTML = `
    <li>
      <a id="github1s-button" class="btn btn-sm" target="_blank">
        <svg style="vertical-align: sub;" width="16" height="16" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg"><g><path stroke="none" fill="#13227a" d="M35.587 25.574 C 26.887 34.274,22.366 85.319,28.408 106.640 C 29.808 111.581,30.362 115.990,29.639 116.436 C 22.375 120.926,6.586 153.361,2.311 172.577 C -1.702 190.614,-0.380 242.019,4.623 262.483 C 23.337 339.024,75.772 372.234,183.814 375.971 C 333.315 381.142,400.042 329.514,399.989 208.709 C 399.973 171.788,393.448 148.895,375.953 124.378 L 369.021 114.663 371.179 105.378 C 378.038 75.873,372.074 26.678,361.310 23.977 C 349.211 20.940,315.376 33.668,289.736 50.901 L 277.128 59.375 269.292 57.047 C 230.073 45.401,175.046 45.086,133.396 56.269 L 122.262 59.259 109.633 50.951 C 77.787 29.999,43.062 18.098,35.587 25.574 M199.219 174.024 C 215.547 173.970,243.672 173.640,261.719 173.291 C 297.764 172.594,302.347 173.496,314.439 183.671 C 360.164 222.146,353.423 307.996,302.675 333.490 C 257.998 355.934,129.596 354.142,90.730 330.533 C 37.291 298.070,45.173 192.813,102.426 174.343 C 108.963 172.234,114.738 172.025,139.844 172.986 C 156.172 173.611,182.891 174.078,199.219 174.024 M115.787 201.123 C 100.709 208.550,93.908 238.122,102.705 258.007 C 117.257 290.906,150.790 276.028,150.686 236.719 C 150.615 210.124,133.322 192.485,115.787 201.123 M265.858 201.088 C 262.979 202.507,258.887 206.290,256.767 209.495 C 233.925 244.011,263.236 295.935,289.886 268.166 C 314.409 242.614,294.482 186.985,265.858 201.088 M176.563 301.563 C 164.758 313.367,192.597 331.661,210.156 323.639 C 224.183 317.230,229.788 307.913,223.438 301.563 C 219.132 297.257,215.495 297.640,208.594 303.125 C 205.350 305.703,201.482 307.813,200.000 307.813 C 198.518 307.813,194.650 305.703,191.406 303.125 C 184.505 297.640,180.868 297.257,176.563 301.563"></path></g></svg>
        <span>Github1s</span>
      </a>
    </li>
    <li>
      <a id="vscodedev-button" class="btn btn-sm" target="_blank">
        <svg style="vertical-align: sub;" t="1744903232958" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1746" width="18" height="18"><path d="M123.648 399.9232s-12.4928-12.288-11.264-19.968c1.024-7.7824 5.632-11.9296 5.632-11.9296l72.5504-61.7472s5.0176-2.4576 10.4448-1.8432c5.4272 0.6144 11.6736 4.608 11.6736 4.608l504.576 382.976 1.8944 200.6016-19.4048 13.1584-13.7728-2.7136L123.648 399.9232z" fill="#008BD1" p-id="1747"></path><path d="M227.072 698.9312l-15.0016 11.6736s-5.632 4.4032-12.7488 4.608c-7.0656 0.2048-13.312-5.632-13.312-5.632l-67.7888-62.5664s-2.304-3.7376-1.024-9.3696c1.2288-5.632 2.7136-7.3216 2.7136-7.3216l553.5744-502.9376 6.2464-3.7376 28.5696-5.8368 42.5472 65.8944 3.7376 115.712-527.5136 399.5136z" fill="#0079BF" p-id="1748"></path><path d="M673.4848 127.3856s31.488-10.5984 38.6048 21.504l0.2048 723.3024s-3.9936 15.4624-12.9536 21.0944c-8.96 5.632-22.9376 1.8432-22.9376 1.8432s11.264 13.7728 23.9616 13.312c6.2976 0 16.0768-6.8608 16.0768-6.8608l176.1792-86.9376s10.4448-7.4752 14.3872-14.592c3.9936-6.8608 4.608-12.4928 4.608-12.4928V235.008s1.8944-11.4688-5.632-19.6096-10.8544-9.3696-10.8544-9.3696L709.632 117.1968s-3.9936-1.4848-12.1344-1.024c-8.2944 0.1536-23.9616 11.264-23.9616 11.264z" fill="#009BD9" p-id="1749"></path></svg>
        <span>VS Code</span>
      </a>
    </li>
  `;
  actions.insertAdjacentHTML('afterBegin', btnHTML);

  $('#github1s-button').onmouseenter = function () {
    const github1sURL = new URL(location);
    github1sURL.host = 'github1s.com';
    this.href = github1sURL.href;
  };
  $('#vscodedev-button').onmouseenter = function () {
    const newUrl = new URL(location);
    newUrl.host = 'vscode.dev';
    newUrl.pathname = `/github${newUrl.pathname}`;
    console.log(newUrl.href)
    this.href = newUrl.href;
  };
}

insertButton();
window.addEventListener('urlchange', info => {
  setTimeout(insertButton, 200);
});
})();