Last active
May 8, 2026 00:06
-
-
Save hgaibor/754fb2f37b046b88bfaa4d190b46cef6 to your computer and use it in GitHub Desktop.
Title observer shared code for Tampermonkey
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
| // ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** | |
| // * add-title-observer.js | |
| // * Created by: Hugo Gaibor | |
| // * Date: 2024-07-11 | |
| // * License: GNU/GPL3+ | |
| // * | |
| // * Latest version: | |
| // * https://gist.githubusercontent.com/hgaibor/754fb2f37b046b88bfaa4d190b46cef6/raw/add-title-observer.js | |
| // * | |
| // * Example TamperMonkey Script: | |
| // * https://gist.githubusercontent.com/hgaibor/754fb2f37b046b88bfaa4d190b46cef6/raw/example-tamper-monkey-UserScript | |
| // * | |
| // * History: | |
| // * 2024-09-29 Created script to modify browser windows title to be used alongside autoHotKey | |
| // * custom scripts | |
| // * 2026-05-07 Updated code and migrated to Gist in Github for centralized updates to local scripts | |
| // * | |
| // ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** | |
| function applyTitleSuffix(suffix) { | |
| function updateTitle() { | |
| if (!document.title.endsWith(suffix)) { | |
| document.title = document.title + suffix; | |
| } | |
| } | |
| updateTitle(); | |
| const titleElement = document.querySelector('title'); | |
| if (titleElement) { | |
| const observer = new MutationObserver(function() { | |
| observer.disconnect(); | |
| updateTitle(); | |
| observer.observe(titleElement, { childList: true }); | |
| }); | |
| observer.observe(titleElement, { childList: true }); | |
| } | |
| } |
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
| // ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** | |
| // * example-tamper-monkey-UserScript | |
| // * Created by: Hugo Gaibor | |
| // * Date: 2024-07-11 | |
| // * License: GNU/GPL3+ | |
| // * | |
| // * Latest version: | |
| // * https://gist.githubusercontent.com/hgaibor/754fb2f37b046b88bfaa4d190b46cef6/raw/add-title-observer.js | |
| // * | |
| // * Example TamperMonkey Script: | |
| // * https://gist.githubusercontent.com/hgaibor/754fb2f37b046b88bfaa4d190b46cef6/raw/example-tamper-monkey-UserScript | |
| // * | |
| // * History: | |
| // * 2024-09-29 Created script to modify browser windows title to be used alongside autoHotKey | |
| // * custom scripts | |
| // * 2026-05-07 Updated code and migrated to Gist in Github for centralized updates to local scripts | |
| // * | |
| // * Usage: Local script for TamperMonkey to use in the browser, if you need to use the GitHub file | |
| // * via the @require option | |
| // * | |
| // * Do NOT put Tampermonkey headers (==UserScript==) on the Script if you plan tu use @require | |
| // * 1. Download the official addon for your browser | |
| // * 2. Create a new TamperMonkey UserScript | |
| // * 2. Paste this code into your local TamperMonkey script | |
| // * 3. Save the script and test if it loads on your designated website | |
| // * 4. Alternatively, you can merge both files, this one first and then the add-title-observer.js | |
| // * to run everything locally without updating it | |
| // * | |
| // ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** | |
| // ==UserScript== | |
| // @name NAME_FOR_YOUR_SCRIPT | |
| // @namespace http://tampermonkey.net/ | |
| // @version VERSION_NUMBER_IF_NEEDED | |
| // @description DESCRIPTION_OPTIONAL | |
| // @author YOU?? | |
| // @match WEBSITES_YOU_NEED_SCRIPT_TO_BE_ACTIVATED | |
| // @icon URL_FOR_YOUR_ICON | |
| // @grant none | |
| // @require https://gist.githubusercontent.com/hgaibor/754fb2f37b046b88bfaa4d190b46cef6/raw/add-title-observer.js | |
| // ==/UserScript== | |
| // Initial page load script | |
| (function() { | |
| const PAGE_SUFFIX = "- MY PAGE SUFFIX"; | |
| 'use strict'; | |
| applyTitleSuffix(PAGE_SUFFIX); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment