11console . log ( "SLACTAC Content Script STARTING - Top of file" ) ;
22
3+ // --- Inject CSS for picker highlighting ---
4+ const pickerStyleSheet = document . createElement ( "style" ) ;
5+ pickerStyleSheet . textContent = `
6+ /* Renamed channels during picker mode - show with yellow/accent color */
7+ .slactac-picker-renamed-channel {
8+ background-color: rgba(215, 153, 33, 0.25) !important;
9+ border-left: 3px solid #d79921 !important;
10+ padding-left: 5px !important;
11+ transition: all 0.15s ease-out;
12+ }
13+ ` ;
14+ document . head . appendChild ( pickerStyleSheet ) ;
15+
316// --- SLACTAC Name Overriding Variables & Functions ---
417function overrideChatroomNames ( ) {
518 // Load saved overrides from storage
@@ -54,6 +67,7 @@ let channelPickerActive = false;
5467let originalCursor = null ;
5568const overlayContainerId = "slactac-overlay-container" ;
5669const highlightedElementClass = "slactac-picker-highlighted-target" ;
70+ const renamedChannelClass = "slactac-picker-renamed-channel" ;
5771let currentHighlightedElement = null ;
5872let currentHighlightedNameElement = null ;
5973let defaultHighlightedRegion = null ;
@@ -91,22 +105,24 @@ function storePickedChannelName(name) {
91105 return new Promise ( ( resolve , reject ) => {
92106 const sanitizedName = typeof name === "string" ? name . trim ( ) : "" ;
93107 if ( ! sanitizedName ) {
94- chrome . storage . local . remove ( LOCAL_PICK_KEY , ( ) => {
95- if ( chrome . runtime . lastError ) {
96- reject ( new Error ( chrome . runtime . lastError . message ) ) ;
97- } else {
108+ browser . storage . local . remove ( LOCAL_PICK_KEY ) . then (
109+ ( ) => {
98110 resolve ( ) ;
111+ } ,
112+ ( error ) => {
113+ reject ( new Error ( error . message || String ( error ) ) ) ;
99114 }
100- } ) ;
115+ ) ;
101116 return ;
102117 }
103- chrome . storage . local . set ( { [ LOCAL_PICK_KEY ] : sanitizedName } , ( ) => {
104- if ( chrome . runtime . lastError ) {
105- reject ( new Error ( chrome . runtime . lastError . message ) ) ;
106- } else {
118+ browser . storage . local . set ( { [ LOCAL_PICK_KEY ] : sanitizedName } ) . then (
119+ ( ) => {
107120 resolve ( ) ;
121+ } ,
122+ ( error ) => {
123+ reject ( new Error ( error . message || String ( error ) ) ) ;
108124 }
109- } ) ;
125+ ) ;
110126 } ) ;
111127}
112128
@@ -423,7 +439,50 @@ function isSlackPage() {
423439 return window . location . hostname . includes ( "app.slack.com" ) ;
424440}
425441
426- function activateChannelPicker ( ) {
442+ function markRenamedChannelsInPicker ( ) {
443+ // Get all overrides from storage
444+ storage . get ( ) . then ( ( overrides ) => {
445+ // overrides is a map of { originalChannelName: customName, ... }
446+ // We need to check if any displayed channel name matches a custom name (value) in overrides
447+ const allCustomNames = Object . values ( overrides ) ; // Get all custom names
448+
449+ console . log ( "SLACTAC Picker: Stored Tacks (overrides):" , overrides ) ;
450+ console . log ( "SLACTAC Picker: Custom names to look for:" , allCustomNames ) ;
451+
452+ // Find all channel items in the sidebar
453+ const sidebarSelector = ".p-channel_sidebar__list" ;
454+ const nameOverrideSelector = ".p-channel_sidebar__name" ;
455+ const listContainer = document . querySelector ( sidebarSelector ) ;
456+
457+ const nameElements = listContainer
458+ ? listContainer . querySelectorAll ( nameOverrideSelector )
459+ : document . querySelectorAll ( nameOverrideSelector ) ;
460+
461+ console . log ( `SLACTAC Picker: Found ${ nameElements . length } channel name elements` ) ;
462+
463+ // Mark channels that have been renamed
464+ let markedCount = 0 ;
465+ nameElements . forEach ( ( element ) => {
466+ const displayName = element . innerText . trim ( ) ;
467+
468+ // Check if this displayed name matches any custom name in Stored Tacks
469+ if ( allCustomNames . includes ( displayName ) ) {
470+ console . log ( `SLACTAC Picker: MATCH! "${ displayName } " found in Stored Tacks (custom name)` ) ;
471+ // Find the channel item that contains this name element
472+ const channelItem = element . closest ( CHANNEL_ITEM_SELECTORS . join ( ", " ) ) ;
473+ if ( channelItem ) {
474+ channelItem . classList . add ( renamedChannelClass ) ;
475+ channelItem . dataset . renamedBySlactac = "true" ;
476+ markedCount ++ ;
477+ console . log ( `SLACTAC Picker: Highlighted "${ displayName } " with yellow` ) ;
478+ }
479+ }
480+ } ) ;
481+ console . log ( `SLACTAC Picker: Marked ${ markedCount } channels with yellow highlight.` ) ;
482+ } ) . catch ( error => {
483+ console . error ( "SLACTAC: Failed to mark renamed channels in picker." , error ) ;
484+ } ) ;
485+ } function activateChannelPicker ( ) {
427486 if ( channelPickerActive ) {
428487 console . log ( "SLACTAC Picker: Already active." ) ;
429488 return true ;
@@ -438,6 +497,7 @@ function activateChannelPicker() {
438497 document . body . style . cursor = "crosshair" ;
439498 createPickerOverlays ( ) ;
440499 highlightDefaultChannelRegion ( ) ;
500+ markRenamedChannelsInPicker ( ) ; // Mark renamed channels with yellow
441501 document . addEventListener ( "mousemove" , channelPickerMouseMoveHandler , true ) ;
442502 document . addEventListener ( "click" , channelPickerClickHandler , true ) ;
443503 document . addEventListener ( "keydown" , handleKeyDown , true ) ;
@@ -464,6 +524,12 @@ function deactivateChannelPicker(force = false) {
464524 document . removeEventListener ( "click" , channelPickerClickHandler , true ) ;
465525 document . removeEventListener ( "keydown" , handleKeyDown , true ) ;
466526
527+ // Remove renamed channel markings
528+ document . querySelectorAll ( `.${ renamedChannelClass } ` ) . forEach ( ( element ) => {
529+ element . classList . remove ( renamedChannelClass ) ;
530+ element . removeAttribute ( "data-renamedBySlactac" ) ;
531+ } ) ;
532+
467533 // Clear the failsafe timer
468534 if ( pickerFailsafeTimer ) {
469535 clearTimeout ( pickerFailsafeTimer ) ;
@@ -527,7 +593,7 @@ observer.observe(targetNode, { childList: true, subtree: true });
527593
528594// --- Combined Message Listener ---
529595console . log ( "SLACTAC CONTENT SCRIPT: Setting up message listener..." ) ;
530- chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
596+ browser . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
531597 console . log ( "SLACTAC CONTENT SCRIPT: Message received -> " , request . action ) ;
532598 if ( request . action === "refreshNamesSLACTAC" ) {
533599 console . log ( "SLACTAC: Handling refreshNamesSLACTAC" ) ;
0 commit comments