GitHub Toggle to Raw Page

在 GitHub 文件页面添加一个按钮,点击可以跳转到对应的 raw 页面

目前为 2025-02-25 提交的版本。查看 最新版本

// ==UserScript==
// @name         GitHub Toggle to Raw Page
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  在 GitHub 文件页面添加一个按钮,点击可以跳转到对应的 raw 页面
// @author       Your Name
// @match        *://github.com/*/*/blob/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 在页面加载完成后执行
    window.addEventListener('load', function() {
        // 获取当前 URL
        const currentUrl = window.location.href;

        // 检查是否为 GitHub 文件页面(包含 /blob/)
        if (currentUrl.includes('/blob/')) {
            // 创建跳转按钮
            const toggleButton = document.createElement('button');
            toggleButton.textContent = 'View Raw';
            toggleButton.style.position = 'fixed';
            toggleButton.style.top = '10px';
            toggleButton.style.right = '10px';
            toggleButton.style.zIndex = '1000';
            toggleButton.style.padding = '5px 10px';
            toggleButton.style.backgroundColor = '#2ea44f';
            toggleButton.style.color = '#fff';
            toggleButton.style.border = 'none';
            toggleButton.style.borderRadius = '5px';
            toggleButton.style.cursor = 'pointer';

            // 按钮点击事件
            toggleButton.addEventListener('click', function() {
                const rawUrl = currentUrl.replace('github.com', 'raw.githubusercontent.com').replace('/blob/', '/');
                window.open(rawUrl, '_blank'); // 在新标签页中打开 raw 页面
            });

            // 将按钮添加到页面中
            document.body.appendChild(toggleButton);
        }
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址