Created
January 26, 2024 22:46
-
-
Save DeflateAwning/fcac3d314a19bd46e446c7b264b95739 to your computer and use it in GitHub Desktop.
When browsing a GitHub project, set the <title> to the filename (instead of the whole folder path)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Set GitHub Page Title to the Filename | |
// @namespace https://gist.github.com/DeflateAwning | |
// @version v0.1 | |
// @description When browsing a GitHub project, set the <title> to the filename and repo user/name. | |
// @author DeflateAwning | |
// @match https://github.com/*/*/blob/** | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Function to set page title to the filename | |
function setGitHubPageTitle() { | |
// Get the open file's filename from the URL | |
const file_name = window.location.pathname.split('/').pop(); | |
// Get the repo name (text after '·' in the <title>) | |
const parts = document.title.split('·'); | |
const repo_name = parts[1] ? parts[1].trim() : ''; // includes username and repo name | |
const folder_path_and_branch = parts[0] ? parts[0].trim() : ''; | |
document.title = file_name + ' @' + repo_name + ' | ' + folder_path_and_branch; | |
} | |
setGitHubPageTitle(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment