Last active
July 28, 2026 08:31
-
-
Save thfrei/4c323ae8998fd7757e97aa1636e493d9 to your computer and use it in GitHub Desktop.
Remove the ([0-9]+) message count prefix of every notion page!
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 Remove the ([0-9]+) prefix of every notion page! | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2025-04-15 | |
| // @description try to make the world cleaner | |
| // @author You | |
| // @match https://*.notion.so/* | |
| // @match https://app.notion.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=notion.so | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| // Get reference to the title element | |
| const titleElement = document.querySelector('title'); | |
| // If there's no title element yet, create one | |
| if (!titleElement) { | |
| console.warn("TM: No title element found in document, creating one"); | |
| const newTitle = document.createElement('title'); | |
| newTitle.textContent = document.title; | |
| document.head.appendChild(newTitle); | |
| } | |
| // Function to handle title changes | |
| function handleTitleChange(newTitle) { | |
| console.log('TM: Title changed to:', newTitle); | |
| // Define the regex for any number (or number+) in parentheses at the start | |
| // ^ - start of the string | |
| // \( - literal opening parenthesis | |
| // \d+ - one or more digits (0-9) | |
| // \+? - optional literal plus sign (the '?' makes the preceding '+' optional) | |
| // \) - literal closing parenthesis | |
| // \s* - zero or more whitespace characters | |
| const notificationPrefixRegex = /^\(\d+\+?\)\s*/; | |
| // Check if the new title matches the pattern | |
| if (notificationPrefixRegex.test(newTitle)) { | |
| console.log('TM: Title starts with a number/notification prefix, removing it.'); | |
| // We need to set it without the prefix, but we don't want to trigger our observer again | |
| // so we temporarily disconnect it | |
| titleObserver.disconnect(); | |
| // Remove the matched prefix | |
| const cleanTitle = newTitle.replace(notificationPrefixRegex, ''); | |
| document.title = cleanTitle; | |
| // Reconnect observer | |
| titleObserver.observe( | |
| document.querySelector('title'), | |
| { subtree: true, characterData: true, childList: true } | |
| ); | |
| } | |
| } | |
| // Set up the observer | |
| const titleObserver = new MutationObserver(function(mutations) { | |
| // We're only interested in the final state after all mutations | |
| // and we'll check the current document.title which is the most reliable | |
| handleTitleChange(document.title); | |
| }); | |
| // Start observing the title element for changes | |
| // It's important to select the title element *after* it's ensured to exist. | |
| const actualTitleElement = document.querySelector('title'); | |
| if (actualTitleElement) { | |
| titleObserver.observe( | |
| actualTitleElement, | |
| { subtree: true, characterData: true, childList: true } | |
| ); | |
| } else { | |
| console.error("TM: Failed to find title element for observation after attempting to create it."); | |
| } | |
| // Log initial setup | |
| console.log('TM: Notion - Remove notification prefix - Title monitor initialized. Current title:', document.title); | |
| console.log('TM: Will remove any (Number) or (Number+) prefix from the title.'); | |
| // Also run it once on load, in case the title is already prefixed | |
| handleTitleChange(document.title); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment