├── manifest.json ├── content.js ├── options.js ├── README.md └── options.html /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "Title Shortener", 4 | "version": "1.0", 5 | "description": "Shortens the web page title for specified domains.", 6 | "permissions": [ 7 | "storage" 8 | ], 9 | "content_scripts": [ 10 | { 11 | "matches": [""], 12 | "js": ["content.js"] 13 | } 14 | ], 15 | "options_page": "options.html" 16 | } -------------------------------------------------------------------------------- /content.js: -------------------------------------------------------------------------------- 1 | // Function to process the title 2 | function processTitle(title) { 3 | // 1. Remove the substring within () including the parentheses 4 | title = title.replace(/\([^)]*\)/g, ""); 5 | // 2. Remove the substring within [] including the brackets 6 | title = title.replace(/\[[^\]]*\]/g, ""); 7 | // 3. Remove the substring within full-width parentheses () including the parentheses 8 | title = title.replace(/([^)]*)/g, ""); 9 | // 4. Remove the substring within full-width brackets 【】 including the brackets 10 | title = title.replace(/【[^】]*】/g, ""); 11 | return title.trim(); 12 | } 13 | 14 | // Retrieve target domain settings from chrome.storage and check the current page's hostname 15 | chrome.storage.sync.get("domains", function(data) { 16 | const domains = data.domains || []; 17 | const currentDomain = window.location.hostname; 18 | // If any of the configured domains is included in the current hostname, execute the title processing 19 | if (domains.some(d => currentDomain.includes(d))) { 20 | const newTitle = processTitle(document.title); 21 | document.title = newTitle; 22 | } 23 | }); -------------------------------------------------------------------------------- /options.js: -------------------------------------------------------------------------------- 1 | // Function to save the list of domains to chrome.storage 2 | function saveDomains(domains) { 3 | chrome.storage.sync.set({ domains: domains }); 4 | } 5 | 6 | // Function to load and display the currently registered domains 7 | function loadDomains() { 8 | chrome.storage.sync.get("domains", function (data) { 9 | const domains = data.domains || []; 10 | const ul = document.getElementById("domainList"); 11 | ul.innerHTML = ""; 12 | domains.forEach((domain, index) => { 13 | const li = document.createElement("li"); 14 | li.textContent = domain; 15 | // Create a delete button 16 | const deleteButton = document.createElement("button"); 17 | deleteButton.textContent = "Delete"; 18 | deleteButton.addEventListener("click", function () { 19 | domains.splice(index, 1); 20 | saveDomains(domains); 21 | loadDomains(); 22 | }); 23 | li.appendChild(deleteButton); 24 | ul.appendChild(li); 25 | }); 26 | }); 27 | } 28 | 29 | // Handler for adding a new domain 30 | document.getElementById("addDomain").addEventListener("click", function () { 31 | const input = document.getElementById("domainInput"); 32 | const domain = input.value.trim(); 33 | if (domain !== "") { 34 | chrome.storage.sync.get("domains", function (data) { 35 | const domains = data.domains || []; 36 | domains.push(domain); 37 | saveDomains(domains); 38 | loadDomains(); 39 | input.value = ""; 40 | }); 41 | } 42 | }); 43 | 44 | // Display the list of domains when the page loads 45 | document.addEventListener("DOMContentLoaded", loadDomains); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Title Shorter Extension 2 | 3 | ## Overview 4 | 5 | **Title Shorter** is a lightweight Chrome extension that shortens webpage titles by removing unnecessary text. It focuses on cleaning up titles by eliminating substrings enclosed in various types of brackets, making your browser tabs tidier and more informative. 6 | 7 | ## Key Features 8 | 9 | - **Automatic Title Processing:** 10 | The extension processes webpage titles by removing substrings enclosed in: 11 | - `()` (half-width parentheses) 12 | - `[]` (half-width brackets) 13 | - `()` (full-width parentheses) 14 | - `【】` (full-width brackets) 15 | 16 | - **Domain-Specific Operation:** 17 | The extension only processes titles on domains that you specify. This means you can tailor its behavior to only work on websites where you want cleaner titles. 18 | 19 | - **Easy Configuration:** 20 | Through the options page, users can easily add or remove domain names. The extension uses Chrome’s storage API to save your settings, ensuring your preferences persist between sessions. 21 | 22 | ## How It Works 23 | 24 | 1. **Retrieve Domains:** 25 | The extension retrieves a list of target domains from Chrome's storage. 26 | 2. **Domain Check:** 27 | It then checks if the current page’s hostname contains any of the specified domains. 28 | 3. **Process Title:** 29 | If there’s a match, the extension processes the title by: 30 | - Removing text within `()`, `[]`, `()`, and `【】` along with the brackets themselves. 31 | - Trimming the title and updating the browser tab with the new, shortened title. 32 | 33 | ## Installation 34 | 35 | 1. **Download or Clone:** 36 | Get the extension's source code from the repository. 37 | 2. **Open Extensions Page:** 38 | In Chrome, navigate to `chrome://extensions/`. 39 | 3. **Enable Developer Mode:** 40 | Turn on Developer Mode by toggling the switch at the top-right corner. 41 | 4. **Load Unpacked Extension:** 42 | Click "Load unpacked" and select the extension folder. 43 | 44 | ## Use Cases 45 | 46 | - **Cleaner Tabs:** 47 | By removing extraneous text, your browser tabs display only the essential part of the title, helping you focus on what matters. 48 | - **Customizable Experience:** 49 | Tailor the extension to work only on specific domains, ensuring that only the desired pages are affected. 50 | 51 | ## Conclusion 52 | 53 | **Title Shorter** is designed to improve your browsing experience by decluttering your tab titles. With its easy configuration and smart processing, you can enjoy a more streamlined interface, keeping your workflow efficient and your desktop organized. 54 | -------------------------------------------------------------------------------- /options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Extension Settings 7 | 92 | 93 | 94 | 95 |
96 |

Domain Settings

97 |
98 | 99 | 100 |
101 | 102 |
103 | 104 | 105 | 106 | --------------------------------------------------------------------------------