Skip to content

Instantly share code, notes, and snippets.

@FH-Inway
Last active November 12, 2022 12:27
Show Gist options
  • Save FH-Inway/471eabdc3d859b7ca9b83ff24289c0a1 to your computer and use it in GitHub Desktop.
Save FH-Inway/471eabdc3d859b7ca9b83ff24289c0a1 to your computer and use it in GitHub Desktop.
Tampermonkey script to change page titles
// ==UserScript==
// @name Change Microsoft Learn page titles
// @namespace https://github.com/FH-Inway/tampermonkey
// @version 0.3
// @description Changes titles of Microsoft Learn pages to provide better friendly links in Edge browser
// @author FH-Inway
// @match https://learn.microsoft.com/en-us/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=microsoft.com
// @updateURL https://gist.github.com/FH-Inway/471eabdc3d859b7ca9b83ff24289c0a1/raw/Change%2520page%2520titles.user.js
// @downloadURL https://gist.github.com/FH-Inway/471eabdc3d859b7ca9b83ff24289c0a1/raw/Change%2520page%2520titles.user.js
// @grant window.onurlchange
// ==/UserScript==
(function() {
'use strict';
function changePageTitle() {
let title = document.title;
let segments = title.split(' - ');
let hash = window.location.hash.substr(1);
let newTitle;
if (hash != '') {
let anchor = document.getElementById(hash);
newTitle = anchor.textContent + ' - ' + segments[0];
} else {
newTitle = segments[0];
}
document.title = newTitle + ' - Microsoft';
}
if (window.onurlchange === null) {
window.addEventListener('urlchange', changePageTitle);
}
changePageTitle();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment