// ==UserScript==
// @name DeepSeek Folder Organizer
// @namespace http://tampermonkey.net/
// @version 3.0
// @description Advanced folder organization for DeepSeek conversations - Organize, categorize, and manage your chats with custom folders, icons, and colors
// @author Gzyms69
// @match https://chat.deepseek.com/*
// @icon https://chat.deepseek.com/favicon.ico
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_listValues
// ==/UserScript==
(function() {
'use strict';
console.log('=== DeepSeek Folder Organizer Loading ===');
// Storage keys
const FOLDERS_KEY = 'deepseek_folders';
const ASSIGNMENTS_KEY = 'deepseek_assignments';
const SETTINGS_KEY = 'deepseek_settings';
// No default folders - start with empty array
const AVAILABLE_ICONS = [
// Folder icons
'',
'',
'',
// File/document icons
'',
'',
// Category icons
'',
'',
// Code/tech icons
'',
'',
'',
// Star/favorite icons
'',
'',
// Learning/education icons
'',
'',
// Personal icons
'',
'',
// Work icons
'',
'',
// Miscellaneous icons
'',
'',
''
];
// Available colors
const AVAILABLE_COLORS = ['#10a37f', '#4285f4', '#ea4335', '#fbbc04', '#34a853', '#7b7b7b', '#a142f4', '#f442d7', '#42f4e8', '#f4a142'];
// Global state
let isFolderSidebarVisible = false;
let selectedFolderId = null;
// Initialize storage
function initializeStorage() {
if (!GM_getValue(FOLDERS_KEY)) {
GM_setValue(FOLDERS_KEY, []); // Empty array, no default folders
}
if (!GM_getValue(ASSIGNMENTS_KEY)) {
GM_setValue(ASSIGNMENTS_KEY, {});
}
if (!GM_getValue(SETTINGS_KEY)) {
GM_setValue(SETTINGS_KEY, {
showFolderTags: true,
autoCategorize: false,
sidebarWidth: '220'
});
}
}
// Wait for page to fully load
setTimeout(init, 2000);
// Mutation observer for dynamic content
let observer;
function init() {
console.log('Initializing Folder Organizer...');
initializeStorage();
// Add the folder button to the sidebar
addFolderButton();
// Setup folder sidebar
setupFolderSidebar();
// Setup observer for conversation list changes
setupMutationObserver();
// Apply folder tags to existing conversations
applyFolderTags();
// Add global click listener to close context menus
document.addEventListener('click', () => {
hideContextMenu();
hideFolderMenu();
});
}
function setupMutationObserver() {
const targetNode = document.querySelector('div[class*="_5a8ac7a"]')?.parentElement;
if (!targetNode) {
console.log('Target node not found, retrying...');
setTimeout(setupMutationObserver, 1000);
return;
}
observer = new MutationObserver((mutations) => {
let shouldUpdate = false;
mutations.forEach((mutation) => {
if (mutation.addedNodes.length > 0) {
shouldUpdate = true;
}
});
if (shouldUpdate) {
setTimeout(applyFolderTags, 500);
setTimeout(updateFolderCounts, 500);
}
});
observer.observe(targetNode, { childList: true, subtree: true });
}
function addFolderButton() {
// Try to find the sidebar container where buttons are
const sidebarSelectors = [
'nav[class*="sidebar"]',
'div[class*="sidebar"]',
'div[class*="chat-sidebar"]',
'div[class*="conversations"]'
];
let sidebarContainer;
for (const selector of sidebarSelectors) {
sidebarContainer = document.querySelector(selector);
if (sidebarContainer) break;
}
if (!sidebarContainer) {
console.error('Could not find sidebar container, retrying...');
setTimeout(addFolderButton, 1000);
return;
}
// Check if button already exists
if (document.querySelector('.ds-folder-toggle-btn')) {
return;
}
// Find where to insert the button (look for the "New Chat" button)
const newChatBtn = document.querySelector('div._5a8ac7a, button:has(> svg)');
const insertAfter = newChatBtn || sidebarContainer.firstChild;
// Create folder toggle button
const folderBtn = document.createElement('button');
folderBtn.className = 'ds-folder-toggle-btn';
folderBtn.innerHTML = `
Folders
`;
folderBtn.style.cssText = `
width: calc(100% - 16px);
margin: 8px;
padding: 10px 12px;
background: ${isFolderSidebarVisible ? '#10a37f' : 'transparent'};
color: ${isFolderSidebarVisible ? 'white' : '#ececf1'};
border: 1px solid ${isFolderSidebarVisible ? '#10a37f' : '#565869'};
border-radius: 6px;
cursor: pointer;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-size: 14px;
font-weight: 500;
text-align: left;
display: flex;
align-items: center;
gap: 8px;
transition: all 0.2s ease;
`;
// Hover effect
folderBtn.addEventListener('mouseenter', () => {
if (!isFolderSidebarVisible) {
folderBtn.style.background = 'rgba(255,255,255,0.1)';
folderBtn.style.borderColor = '#8e8ea0';
}
});
folderBtn.addEventListener('mouseleave', () => {
if (!isFolderSidebarVisible) {
folderBtn.style.background = 'transparent';
folderBtn.style.borderColor = '#565869';
}
});
// Button click action - toggle folder sidebar
folderBtn.addEventListener('click', toggleFolderSidebar);
// Insert after New Chat button or at the top
insertAfter.parentNode.insertBefore(folderBtn, insertAfter.nextSibling);
console.log('✅ Folder button added to sidebar');
}
function setupFolderSidebar() {
// Remove existing folder sidebar if present
const existingSidebar = document.querySelector('.ds-folder-sidebar');
if (existingSidebar) existingSidebar.remove();
const folders = GM_getValue(FOLDERS_KEY, []);
const assignments = GM_getValue(ASSIGNMENTS_KEY, {});
const settings = GM_getValue(SETTINGS_KEY, {});
// Count conversations per folder
const folderCounts = {};
folders.forEach(folder => {
folderCounts[folder.id] = Object.values(assignments).filter(f => f === folder.id).length;
});
// Create sidebar container
const sidebar = document.createElement('div');
sidebar.className = 'ds-folder-sidebar';
sidebar.style.cssText = `
position: fixed;
right: 0;
top: 0;
bottom: 0;
width: ${settings.sidebarWidth || 220}px;
background: #202123;
border-left: 1px solid #565869;
padding: 16px 0;
overflow-y: auto;
z-index: 1000;
transform: translateX(${isFolderSidebarVisible ? '0' : '100%'});
transition: transform 0.3s ease;
display: flex;
flex-direction: column;
`;
// Create header
const header = document.createElement('div');
header.style.cssText = `
padding: 0 16px 16px;
border-bottom: 1px solid #565869;
margin-bottom: 16px;
`;
header.innerHTML = `
${Object.keys(assignments).length} conversations organized
`;
// Create folder list
const folderList = document.createElement('div');
folderList.className = 'ds-folder-list';
folderList.style.cssText = `
padding: 0 16px;
flex: 1;
overflow-y: auto;
`;
// Add All Conversations option
const allItem = createFolderItem('all', {
name: 'All Conversations',
icon: '',
color: '#ececf1'
}, Object.keys(assignments).length);
allItem.addEventListener('click', () => filterByFolder(null));
folderList.appendChild(allItem);
// Add each folder
folders.forEach(folder => {
const count = folderCounts[folder.id] || 0;
const item = createFolderItem(folder.id, folder, count);
folderList.appendChild(item);
});
// Assemble sidebar
sidebar.appendChild(header);
sidebar.appendChild(folderList);
// Add event listeners
sidebar.querySelector('.ds-add-folder-btn').addEventListener('click', (e) => {
e.stopPropagation();
showAddFolderModal();
});
document.body.appendChild(sidebar);
// Add overlay when sidebar is open
if (isFolderSidebarVisible) {
addSidebarOverlay();
}
}
function createFolderItem(folderId, folder, count) {
const item = document.createElement('div');
item.className = 'ds-folder-item';
item.setAttribute('data-folder-id', folderId);
item.style.cssText = `
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 12px;
margin: 4px 0;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s;
color: #ececf1;
font-size: 14px;
border: 1px solid transparent;
position: relative;
`;
// Apply background if selected
if (selectedFolderId === folderId) {
item.style.background = 'rgba(16, 163, 127, 0.1)';
item.style.borderColor = 'rgba(16, 163, 127, 0.3)';
}
item.innerHTML = `
${folder.icon}
${folder.name}
${count}
`;
// Left click to select/filter
item.addEventListener('click', (e) => {
e.stopPropagation();
selectedFolderId = folderId;
if (folderId === 'all') {
filterByFolder(null);
} else {
filterByFolder(folderId);
}
updateFolderSelection();
});
// Right click for context menu
item.addEventListener('contextmenu', (e) => {
e.preventDefault();
e.stopPropagation();
selectedFolderId = folderId;
updateFolderSelection();
if (folderId !== 'all') {
showFolderContextMenu(e, folder);
}
});
item.addEventListener('mouseenter', () => {
if (selectedFolderId !== folderId) {
item.style.background = 'rgba(255,255,255,0.05)';
item.style.borderColor = 'rgba(255,255,255,0.1)';
}
});
item.addEventListener('mouseleave', () => {
if (selectedFolderId !== folderId) {
item.style.background = '';
item.style.borderColor = 'transparent';
}
});
return item;
}
function updateFolderSelection() {
document.querySelectorAll('.ds-folder-item').forEach(item => {
const folderId = item.getAttribute('data-folder-id');
if (selectedFolderId === folderId) {
item.style.background = 'rgba(16, 163, 127, 0.1)';
item.style.borderColor = 'rgba(16, 163, 127, 0.3)';
} else {
item.style.background = '';
item.style.borderColor = 'transparent';
}
});
}
function updateFolderCounts() {
const folders = GM_getValue(FOLDERS_KEY, []);
const assignments = GM_getValue(ASSIGNMENTS_KEY, {});
// Update all conversations count
const allItem = document.querySelector('.ds-folder-item[data-folder-id="all"] .ds-folder-count');
if (allItem) {
allItem.textContent = Object.keys(assignments).length;
}
// Update each folder count
folders.forEach(folder => {
const count = Object.values(assignments).filter(f => f === folder.id).length;
const countElement = document.querySelector(`.ds-folder-item[data-folder-id="${folder.id}"] .ds-folder-count`);
if (countElement) {
countElement.textContent = count;
}
});
}
function showFolderContextMenu(e, folder) {
hideContextMenu();
hideFolderMenu();
const menu = document.createElement('div');
menu.className = 'ds-context-menu';
menu.style.cssText = `
position: fixed;
top: ${e.clientY}px;
left: ${e.clientX}px;
background: #343541;
border: 1px solid #565869;
border-radius: 6px;
padding: 8px 0;
z-index: 1002;
min-width: 180px;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
`;
const menuItems = [
{ icon: '', text: 'Rename', action: () => showRenameFolderModal(folder) },
{ icon: '', text: 'Customize', action: () => showCustomizeFolderModal(folder) },
{ icon: '', text: 'Manage Conversations', action: () => showManageFolderModal(folder) },
{ separator: true },
{ icon: '', text: 'Delete', action: () => deleteFolder(folder), danger: true }
];
menuItems.forEach(item => {
if (item.separator) {
const separator = document.createElement('div');
separator.style.cssText = 'height: 1px; background: #565869; margin: 4px 0;';
menu.appendChild(separator);
} else {
const menuItem = document.createElement('div');
menuItem.style.cssText = `
display: flex;
align-items: center;
gap: 10px;
padding: 8px 16px;
cursor: pointer;
font-size: 14px;
color: ${item.danger ? '#ef4444' : '#ececf1'};
transition: background 0.2s;
`;
menuItem.innerHTML = `
${item.icon}
${item.text}
`;
menuItem.addEventListener('mouseenter', () => {
menuItem.style.background = 'rgba(255,255,255,0.1)';
});
menuItem.addEventListener('mouseleave', () => {
menuItem.style.background = '';
});
menuItem.addEventListener('click', (e) => {
e.stopPropagation();
item.action();
menu.remove();
});
menu.appendChild(menuItem);
}
});
document.body.appendChild(menu);
// Close menu when clicking outside
setTimeout(() => {
const closeHandler = () => {
menu.remove();
document.removeEventListener('click', closeHandler);
};
document.addEventListener('click', closeHandler);
}, 0);
}
function showAddFolderModal() {
showFolderMenu(null, 'add');
}
function showRenameFolderModal(folder) {
showFolderMenu(folder, 'rename');
}
function showCustomizeFolderModal(folder) {
showFolderMenu(folder, 'customize');
}
function showManageFolderModal(folder) {
hideContextMenu();
hideFolderMenu();
const assignments = GM_getValue(ASSIGNMENTS_KEY, {});
const conversations = getConversations();
// Filter conversations in this folder vs others
const folderConversations = conversations.filter(conv => assignments[conv.id] === folder.id);
const otherConversations = conversations.filter(conv => !assignments[conv.id] || assignments[conv.id] !== folder.id);
// Create modal with search functionality
const modal = document.createElement('div');
modal.className = 'ds-folder-manager-modal';
modal.style.cssText = `
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #343541;
border: 1px solid #565869;
border-radius: 8px;
padding: 24px;
z-index: 1003;
width: 600px;
max-width: 90vw;
max-height: 80vh;
overflow-y: auto;
box-shadow: 0 8px 40px rgba(0,0,0,0.4);
`;
modal.innerHTML = `
${folder.icon}
${folder.name}
${folderConversations.length} conversations in this folder
Currently in this folder (${folderConversations.length})
${folderConversations.length > 0 ? folderConversations.map(conv => `
`).join('') : `
No conversations in this folder
`}
Other conversations (${otherConversations.length})
${otherConversations.length > 0 ? otherConversations.map(conv => `
`).join('') : `
No other conversations
`}
`;
// Add backdrop
const backdrop = document.createElement('div');
backdrop.className = 'ds-modal-backdrop';
backdrop.style.cssText = `
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.5);
z-index: 1002;
`;
document.body.appendChild(backdrop);
document.body.appendChild(modal);
// Initialize search functionality
setupSearchFunctionality(modal, folder);
// Event listeners
modal.querySelector('.ds-close-modal').addEventListener('click', closeModal);
modal.querySelector('.ds-cancel-btn').addEventListener('click', closeModal);
backdrop.addEventListener('click', closeModal);
modal.querySelector('.ds-save-btn').addEventListener('click', () => {
const assignments = GM_getValue(ASSIGNMENTS_KEY, {});
const checkboxes = modal.querySelectorAll('.ds-folder-checkbox');
checkboxes.forEach(checkbox => {
const convId = checkbox.getAttribute('data-id');
if (checkbox.checked) {
assignments[convId] = folder.id;
} else if (assignments[convId] === folder.id) {
delete assignments[convId];
}
});
GM_setValue(ASSIGNMENTS_KEY, assignments);
applyFolderTags();
updateFolderCounts();
filterByFolder(folder.id);
closeModal();
});
function closeModal() {
modal.remove();
backdrop.remove();
}
// Prevent clicks inside modal from closing
modal.addEventListener('click', (e) => e.stopPropagation());
}
function setupSearchFunctionality(modal, folder) {
const searchInput = modal.querySelector('#conversation-search');
const clearSearchBtn = modal.querySelector('#clear-search');
searchInput.addEventListener('input', function() {
const searchTerm = this.value.toLowerCase().trim();
const conversationItems = modal.querySelectorAll('.ds-conversation-checkbox');
let currentVisible = 0;
let otherVisible = 0;
if (searchTerm === '') {
// Show all when search is empty
conversationItems.forEach(item => {
item.style.display = '';
const isCurrent = item.querySelector('input').checked;
if (isCurrent) currentVisible++;
else otherVisible++;
});
clearSearchBtn.style.display = 'none';
} else {
// Filter by title
conversationItems.forEach(item => {
const titleElement = item.querySelector('.conversation-title');
const title = titleElement.textContent.toLowerCase();
const matches = title.includes(searchTerm);
item.style.display = matches ? '' : 'none';
if (matches) {
const isCurrent = item.querySelector('input').checked;
if (isCurrent) currentVisible++;
else otherVisible++;
// Highlight matching text
const originalText = titleElement.textContent;
const regex = new RegExp(`(${searchTerm})`, 'gi');
titleElement.innerHTML = originalText.replace(regex, '$1');
}
});
clearSearchBtn.style.display = 'flex';
}
// Update counts
modal.querySelector('#current-count').textContent = `(${currentVisible})`;
modal.querySelector('#other-count').textContent = `(${otherVisible})`;
});
// Clear search
clearSearchBtn.addEventListener('click', function() {
searchInput.value = '';
searchInput.dispatchEvent(new Event('input'));
});
// Remove highlights when search is cleared
searchInput.addEventListener('blur', function() {
if (this.value === '') {
const titles = modal.querySelectorAll('.conversation-title');
titles.forEach(title => {
if (title.innerHTML !== title.textContent) {
title.innerHTML = title.textContent;
}
});
}
});
}
function showFolderMenu(folder, mode) {
hideFolderMenu();
const isAddMode = mode === 'add';
const isRenameMode = mode === 'rename';
const isCustomizeMode = mode === 'customize';
const menu = document.createElement('div');
menu.className = 'ds-folder-menu';
menu.style.cssText = `
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #343541;
border: 1px solid #565869;
border-radius: 8px;
padding: 24px;
z-index: 1003;
width: 320px;
box-shadow: 0 8px 40px rgba(0,0,0,0.4);
`;
const title = isAddMode ? 'Create New Folder' : isRenameMode ? 'Rename Folder' : 'Customize Folder';
menu.innerHTML = `
${title}
${!isCustomizeMode ? `
` : ''}
${isCustomizeMode || isAddMode ? `
Select Icon
${AVAILABLE_ICONS.map((icon, index) => `
${icon}
`).join('')}
Select Color
${AVAILABLE_COLORS.map(color => `
`).join('')}
` : ''}
`;
// Set default selection for customize mode
if (isCustomizeMode) {
setTimeout(() => {
const folderIconIndex = AVAILABLE_ICONS.findIndex(icon =>
icon === folder.icon ||
icon.includes(folder.icon) ||
folder.icon.includes(icon)
);
if (folderIconIndex !== -1) {
const selectedIcon = menu.querySelector(`.ds-icon-option[data-icon-index="${folderIconIndex}"]`);
if (selectedIcon) {
selectedIcon.style.background = 'rgba(16, 163, 127, 0.2)';
selectedIcon.style.border = '1px solid #10a37f';
selectedIcon.style.color = folder.color;
}
}
const selectedColor = menu.querySelector(`.ds-color-option[data-color="${folder.color}"]`);
if (selectedColor) {
selectedColor.style.border = '2px solid white';
selectedColor.style.transform = 'scale(1.1)';
}
}, 10);
}
document.body.appendChild(menu);
// Add backdrop
const backdrop = document.createElement('div');
backdrop.className = 'ds-menu-backdrop';
backdrop.style.cssText = `
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.5);
z-index: 1002;
`;
document.body.appendChild(backdrop);
// Initialize selection
let selectedIconIndex = isCustomizeMode ?
(AVAILABLE_ICONS.findIndex(icon => icon === folder.icon || icon.includes(folder.icon) || folder.icon.includes(icon)) || 0) : 0;
let selectedColor = isCustomizeMode ? folder.color : '#10a37f';
// Icon selection
menu.querySelectorAll('.ds-icon-option').forEach(iconOption => {
iconOption.addEventListener('click', () => {
menu.querySelectorAll('.ds-icon-option').forEach(opt => {
opt.style.background = '';
opt.style.border = '';
opt.style.color = '#8e8ea0';
});
iconOption.style.background = 'rgba(16, 163, 127, 0.2)';
iconOption.style.border = '1px solid #10a37f';
iconOption.style.color = selectedColor;
selectedIconIndex = parseInt(iconOption.getAttribute('data-icon-index'));
});
});
// Color selection
menu.querySelectorAll('.ds-color-option').forEach(colorOption => {
colorOption.addEventListener('click', () => {
menu.querySelectorAll('.ds-color-option').forEach(opt => {
opt.style.border = '2px solid transparent';
opt.style.transform = '';
});
colorOption.style.border = '2px solid white';
colorOption.style.transform = 'scale(1.1)';
selectedColor = colorOption.getAttribute('data-color');
// Update selected icon color
const selectedIcon = menu.querySelector(`.ds-icon-option[data-icon-index="${selectedIconIndex}"]`);
if (selectedIcon && selectedIcon.style.background) {
selectedIcon.style.color = selectedColor;
}
});
});
// Event listeners
menu.querySelector('.ds-menu-cancel').addEventListener('click', closeMenu);
backdrop.addEventListener('click', closeMenu);
menu.querySelector('.ds-menu-save').addEventListener('click', () => {
if (isAddMode || isRenameMode) {
const nameInput = menu.querySelector('#folder-name-input');
const folderName = nameInput.value.trim();
if (!folderName) {
alert('Please enter a folder name');
return;
}
const folders = GM_getValue(FOLDERS_KEY, []);
if (isAddMode) {
const newFolder = {
id: 'folder_' + Date.now(),
name: folderName,
icon: AVAILABLE_ICONS[selectedIconIndex],
color: selectedColor
};
folders.push(newFolder);
} else if (isRenameMode) {
const folderIndex = folders.findIndex(f => f.id === folder.id);
if (folderIndex !== -1) {
folders[folderIndex].name = folderName;
}
}
GM_setValue(FOLDERS_KEY, folders);
} else if (isCustomizeMode) {
const folders = GM_getValue(FOLDERS_KEY, []);
const folderIndex = folders.findIndex(f => f.id === folder.id);
if (folderIndex !== -1) {
folders[folderIndex].icon = AVAILABLE_ICONS[selectedIconIndex];
folders[folderIndex].color = selectedColor;
}
GM_setValue(FOLDERS_KEY, folders);
}
setupFolderSidebar();
closeMenu();
});
function closeMenu() {
menu.remove();
backdrop.remove();
}
// Prevent clicks inside menu from closing
menu.addEventListener('click', (e) => e.stopPropagation());
// Focus input for rename mode
if (isRenameMode || isAddMode) {
setTimeout(() => {
const input = menu.querySelector('#folder-name-input');
input.focus();
if (isRenameMode) input.select();
}, 10);
}
}
function toggleFolderSidebar() {
isFolderSidebarVisible = !isFolderSidebarVisible;
// Update button appearance
const folderBtn = document.querySelector('.ds-folder-toggle-btn');
if (folderBtn) {
folderBtn.style.background = isFolderSidebarVisible ? '#10a37f' : 'transparent';
folderBtn.style.color = isFolderSidebarVisible ? 'white' : '#ececf1';
folderBtn.style.borderColor = isFolderSidebarVisible ? '#10a37f' : '#565869';
}
// Toggle sidebar
const sidebar = document.querySelector('.ds-folder-sidebar');
if (sidebar) {
sidebar.style.transform = isFolderSidebarVisible ? 'translateX(0)' : 'translateX(100%)';
}
// Toggle overlay
if (isFolderSidebarVisible) {
addSidebarOverlay();
} else {
removeSidebarOverlay();
}
}
function addSidebarOverlay() {
removeSidebarOverlay();
const overlay = document.createElement('div');
overlay.className = 'ds-sidebar-overlay';
overlay.style.cssText = `
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.3);
z-index: 999;
`;
overlay.addEventListener('click', toggleFolderSidebar);
document.body.appendChild(overlay);
}
function removeSidebarOverlay() {
const overlay = document.querySelector('.ds-sidebar-overlay');
if (overlay) {
overlay.remove();
}
}
function hideContextMenu() {
document.querySelectorAll('.ds-context-menu').forEach(menu => menu.remove());
}
function hideFolderMenu() {
document.querySelectorAll('.ds-folder-menu').forEach(menu => menu.remove());
document.querySelectorAll('.ds-menu-backdrop').forEach(backdrop => backdrop.remove());
}
function deleteFolder(folder) {
if (confirm(`Delete folder "${folder.name}"? All conversations in this folder will become unassigned.`)) {
const folders = GM_getValue(FOLDERS_KEY, []);
const updatedFolders = folders.filter(f => f.id !== folder.id);
GM_setValue(FOLDERS_KEY, updatedFolders);
// Remove assignments for deleted folder
const assignments = GM_getValue(ASSIGNMENTS_KEY, {});
Object.keys(assignments).forEach(id => {
if (assignments[id] === folder.id) {
delete assignments[id];
}
});
GM_setValue(ASSIGNMENTS_KEY, assignments);
// Reset selection
selectedFolderId = null;
setupFolderSidebar();
applyFolderTags();
updateFolderCounts();
filterByFolder(null);
}
}
function getConversations() {
const convLinks = document.querySelectorAll('a[class*="_546d736"]');
const conversations = [];
convLinks.forEach((conv, index) => {
const titleElement = conv.querySelector('.c08e6e93');
const title = titleElement ? titleElement.textContent.trim() : `Conversation ${index + 1}`;
const href = conv.getAttribute('href');
const convId = href ? href.split('/').pop() : `conv_${Date.now()}_${index}`;
conversations.push({
id: convId,
title: title,
element: conv,
url: href
});
});
return conversations;
}
function applyFolderTags() {
const settings = GM_getValue(SETTINGS_KEY);
if (!settings.showFolderTags) return;
const folders = GM_getValue(FOLDERS_KEY, []);
const assignments = GM_getValue(ASSIGNMENTS_KEY, {});
const conversations = getConversations();
conversations.forEach(conv => {
const folderId = assignments[conv.id];
const folder = folders.find(f => f.id === folderId);
// Remove existing tag
const existingTag = conv.element.querySelector('.ds-folder-tag');
if (existingTag) existingTag.remove();
if (folder) {
// Create folder tag
const tag = document.createElement('span');
tag.className = 'ds-folder-tag';
tag.innerHTML = `
${folder.icon}
${folder.name}
`;
tag.style.cssText = `
display: inline-flex;
align-items: center;
background: ${folder.color}15;
color: ${folder.color};
padding: 2px 6px;
border-radius: 4px;
font-size: 10px;
margin-left: 6px;
vertical-align: middle;
border: 1px solid ${folder.color}30;
max-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;
// Style the SVG icon inside the tag
const tagIcon = tag.querySelector('.ds-folder-tag-icon svg');
if (tagIcon) {
tagIcon.setAttribute('width', '10');
tagIcon.setAttribute('height', '10');
tagIcon.setAttribute('stroke', folder.color);
}
// Find title element
const titleElement = conv.element.querySelector('.c08e6e93');
if (titleElement) {
titleElement.appendChild(tag);
}
}
});
}
function filterByFolder(folderId) {
const folders = GM_getValue(FOLDERS_KEY, []);
const assignments = GM_getValue(ASSIGNMENTS_KEY, {});
const conversations = getConversations();
conversations.forEach(conv => {
const shouldShow = !folderId || assignments[conv.id] === folderId;
conv.element.style.display = shouldShow ? 'flex' : 'none';
// Highlight if filtered and has folder
if (folderId && assignments[conv.id] === folderId) {
const folder = folders.find(f => f.id === folderId);
conv.element.style.background = folder ? `${folder.color}10` : '';
conv.element.style.borderRadius = '6px';
conv.element.style.margin = '2px 0';
} else {
conv.element.style.background = '';
}
});
}
console.log('✅ DeepSeek Folder Organizer v3.0 loaded successfully');
})();