Skip to content

Instantly share code, notes, and snippets.

@FlatMapIO
Last active March 31, 2023 04:17
Show Gist options
  • Select an option

  • Save FlatMapIO/aa086305fcc9155f6b71f6b793966e80 to your computer and use it in GitHub Desktop.

Select an option

Save FlatMapIO/aa086305fcc9155f6b71f6b793966e80 to your computer and use it in GitHub Desktop.
Add a Button for the Github page to open in https://blocks.githubnext.com
// ==UserScript==
// @name Gitbub Blocks
// @namespace https://github.com/
// @version 1.0
// @description Add a button to replace github.com with blocks.githubnext.com in the URL bar on GitHub repositories page
// @author @stackobserve
// @match https://github.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const repo_url = document.location.href;
const url_segments = repo_url.split('/');
if(url_segments.length < 4) return;
const container = document.querySelector('ul.pagehead-actions')
if(container === null) return console.warn('[GithubBlocks] query is invalid: ul.pagehead-actions is not found')
const [user, repo, , ...paths] = url_segments.slice(3);
const next_url = `https://blocks.githubnext.com/${user}/${repo}/blob/${paths.join('/')}`
const blocks_view = `<li> <a class="btn-sm btn BtnGroup-item" href="${next_url}">Blocks</a> </li>`
container.innerHTML = blocks_view + container.innerHTML
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment