Created
November 16, 2025 03:02
-
-
Save pjpscriv/c697bc2dc405364cc99c2459512130eb to your computer and use it in GitHub Desktop.
A userscript for https://github.com/pjpscriv/gmail-label-colorizer/issues/6
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 Gmail Row Colorizer | |
| // @namespace http://pjpscriv.co.nz/ | |
| // @version 2025-11-15 | |
| // @description For emails with colored labels in Gmail, color the entire email row to match the label colors. | |
| // @author @pjpscriv | |
| // @match https://mail.google.com/mail/* | |
| // @icon https://raw.githubusercontent.com/pjpscriv/gmail-label-colorizer/refs/heads/main/src/icons/icon_128.png | |
| // @grant none | |
| // ==/UserScript== | |
| const DEBUG = false; | |
| (function() { | |
| 'use strict'; | |
| function log(msg) { | |
| if (DEBUG) { | |
| console.log(`[Gmail ROW Colorizer] ${msg}`); | |
| } | |
| } | |
| function colorRows() { | |
| // Get labels | |
| let labels = document.querySelectorAll('.av') | |
| log(`Iterating over ${labels.length} labels`); | |
| // Iterate over each label | |
| labels.forEach(label => { | |
| if (label.innerText.trim() === 'Inbox') { | |
| return; // Skip Inbox labels | |
| } | |
| // Get the label colors | |
| let textColor = label.style.color; | |
| let bgColor = label.parentElement.parentElement.style.backgroundColor; | |
| log(`Found: ${textColor}, ${bgColor}`); | |
| // Find the parent row | |
| let parent = label.parentNode; | |
| while (parent && parent.tagName.toLowerCase() !== 'tr') { | |
| parent = parent.parentNode; | |
| } | |
| // Apply colors to the parent row | |
| if (parent) { | |
| log(`Found parent`); | |
| parent.style.color = textColor; | |
| parent.style.backgroundColor = bgColor; | |
| } | |
| }); | |
| } | |
| // Set up mutation observer to watch for changes in the email list | |
| const observer = new MutationObserver((mutationsList, observer) => { | |
| for (let mutation of mutationsList) { | |
| if (mutation.type === 'childList') { | |
| colorRows(); | |
| } | |
| } | |
| }); | |
| observer.observe(document.body, { childList: true, subtree: true }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment