Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeflateAwning/fcac3d314a19bd46e446c7b264b95739 to your computer and use it in GitHub Desktop.
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)
// ==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