// ==UserScript== // @name DeepSeek Markdown to Plain Text Popup (Draggable & Improved Colors) // @namespace http://tampermonkey.net/ // @version 1.2 // @description Press Alt+Shift+M to open a draggable popup, paste Markdown, convert to plain text, and copy. Improved text visibility. // @author Your Name (or AI Assistant) // @match https://*.deepseek.com/* // @match https://deepseek.com/* // @require https://cdn.bootcdn.net/ajax/libs/marked/15.0.7/marked.min.js // @grant GM_setClipboard // @grant GM_addStyle // @grant GM_notification // ==/UserScript== (function() { 'use strict'; let popupVisible = false; let markdownInput, popupDialog, headerElement; let dragState = { isDragging: false, startX: 0, startY: 0, initialPopupLeft: 0, initialPopupTop: 0 }; function markdownToPlainText(markdown) { if (typeof marked === 'undefined') { console.error('Marked.js library is not loaded.'); GM_notification({ text: 'Marked.js library failed to load. Cannot convert Markdown.', title: 'Markdown Converter Error', timeout: 5000 }); return markdown; } try { const html = marked.parse(markdown, { breaks: true, gfm: true, sanitize: false }); const tempDiv = document.createElement('div'); tempDiv.innerHTML = html; tempDiv.querySelectorAll('p, br, li, h1, h2, h3, h4, h5, h6, blockquote, pre').forEach(el => { if (el.tagName === 'LI') { const parent = el.parentElement; if (parent && parent.tagName === 'OL') { const index = Array.from(parent.children).indexOf(el) + 1; if (!el.textContent.trim().startsWith(index + '.')) { el.prepend(document.createTextNode(index + '. ')); } } else if (parent && parent.tagName === 'UL') { if (!el.textContent.trim().startsWith('* ') && !el.textContent.trim().startsWith('- ')) { el.prepend(document.createTextNode('* ')); } } } if (!el.innerHTML.endsWith('\n')) { el.appendChild(document.createTextNode('\n')); } }); let plainText = (tempDiv.textContent || tempDiv.innerText || "").replace(/\n\s*\n/g, '\n\n').trim(); return plainText; } catch (e) { console.error('Error converting Markdown to plain text:', e); GM_notification({ text: 'Error during Markdown conversion.', title: 'Markdown Converter Error', timeout: 5000 }); return markdown; } } function dragMouseDownHandler(e) { if (e.button !== 0) return; e.preventDefault(); dragState.isDragging = true; if (popupDialog.style.transform !== 'none' || !popupDialog.style.left.endsWith('px')) { const rect = popupDialog.getBoundingClientRect(); popupDialog.style.left = rect.left + 'px'; popupDialog.style.top = rect.top + 'px'; popupDialog.style.transform = 'none'; popupDialog.style.margin = '0'; } dragState.startX = e.clientX; dragState.startY = e.clientY; dragState.initialPopupLeft = parseFloat(popupDialog.style.left); dragState.initialPopupTop = parseFloat(popupDialog.style.top); headerElement.style.cursor = 'grabbing'; document.addEventListener('mousemove', dragMoveHandler); document.addEventListener('mouseup', dragEndHandler); } function dragMoveHandler(e) { if (!dragState.isDragging) return; e.preventDefault(); const dx = e.clientX - dragState.startX; const dy = e.clientY - dragState.startY; popupDialog.style.left = (dragState.initialPopupLeft + dx) + 'px'; popupDialog.style.top = (dragState.initialPopupTop + dy) + 'px'; } function dragEndHandler(e) { if (!dragState.isDragging) return; dragState.isDragging = false; headerElement.style.cursor = 'grab'; document.removeEventListener('mousemove', dragMoveHandler); document.removeEventListener('mouseup', dragEndHandler); } function createPopup() { if (document.getElementById('markdown-converter-popup-draggable')) { return; } popupDialog = document.createElement('div'); popupDialog.id = 'markdown-converter-popup-draggable'; popupDialog.innerHTML = `
Markdown to Plain Text Converter

Paste your Markdown content below (Press Alt+Shift+M to toggle):

`; document.body.appendChild(popupDialog); headerElement = document.getElementById('mcp-header-draggable'); markdownInput = document.getElementById('mcp-markdown-input-draggable'); const convertButton = document.getElementById('mcp-convert-button-draggable'); const closeButtonHeader = document.getElementById('mcp-close-btn-header-draggable'); const closeButtonFooter = document.getElementById('mcp-close-button-footer-draggable'); headerElement.style.cursor = 'grab'; headerElement.addEventListener('mousedown', dragMouseDownHandler); convertButton.addEventListener('click', function() { const mdText = markdownInput.value; if (mdText.trim() === '') { GM_notification({ text: 'Input is empty.', title: 'Markdown Converter', timeout: 3000 }); return; } const plainText = markdownToPlainText(mdText); GM_setClipboard(plainText, 'text'); GM_notification({ text: 'Plain text copied to clipboard!', title: 'Markdown Converter', timeout: 3000 }); hidePopup(); }); closeButtonHeader.addEventListener('click', hidePopup); closeButtonFooter.addEventListener('click', hidePopup); GM_addStyle(` #markdown-converter-popup-draggable { position: fixed; background-color: #_MODE_AUTO_f9f9f9_MODE_AUTO_282828; /* Adjusted dark mode bg */ border: 1px solid #_MODE_AUTO_cccccc_MODE_AUTO_555555; box-shadow: 0px 4px 10px rgba(0,0,0,0.2); z-index: 10001; display: none; border-radius: 8px; font-family: Arial, sans-serif; min-width: 400px; } #mcp-header-draggable { padding: 10px 15px; background-color: #_MODE_AUTO_e0e0e0_MODE_AUTO_3a3a3a; color: #_MODE_AUTO_111111_MODE_AUTO_eeeeee; /* Improved contrast for header text */ font-weight: bold; border-top-left-radius: 8px; border-top-right-radius: 8px; display: flex; justify-content: space-between; align-items: center; user-select: none; } #mcp-close-btn-header-draggable { background: none; border: none; font-size: 1.2em; color: #_MODE_AUTO_555555_MODE_AUTO_bbbbbb; /* Clearer close button */ cursor: pointer; } #mcp-content-draggable { padding: 15px; } .mcp-instruction-text { /* Added class for specific styling */ margin-top: 0; margin-bottom: 10px; color: #_MODE_AUTO_222222_MODE_AUTO_dddddd; /* Darker for light mode, lighter for dark mode */ } #mcp-markdown-input-draggable { width: calc(100% - 20px); padding: 8px; margin-bottom: 15px; border: 1px solid #_MODE_AUTO_cccccc_MODE_AUTO_555555; border-radius: 4px; background-color: #_MODE_AUTO_ffffff_MODE_AUTO_333333; /* Ensure good contrast for input bg */ color: #_MODE_AUTO_000000_MODE_AUTO_eeeeee; /* Ensure good contrast for input text */ font-size: 14px; min-height: 150px; } #mcp-buttons-draggable { display: flex; justify-content: flex-end; gap: 10px; } #mcp-buttons-draggable button { padding: 8px 15px; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; color: skyblue; /* White text for buttons, generally good on colored backgrounds */ } #mcp-convert-button-draggable { background-color: #_MODE_AUTO_4CAF50_MODE_AUTO_007bff; /* Green for light, Blue for dark */ } #mcp-convert-button-draggable:hover { background-color: #_MODE_AUTO_45a049_MODE_AUTO_0056b3; } #mcp-close-button-footer-draggable { background-color: #_MODE_AUTO_f44336_MODE_AUTO_6c757d; /* Red for light, Gray for dark */ } #mcp-close-button-footer-draggable:hover { background-color: #_MODE_AUTO_da190b_MODE_AUTO_545b62; } `); } function showPopup() { if (!popupDialog) createPopup(); markdownInput.value = ''; popupDialog.style.left = '50%'; popupDialog.style.top = '50%'; popupDialog.style.transform = 'translate(-50%, -50%)'; headerElement.style.cursor = 'grab'; popupDialog.style.display = 'block'; markdownInput.focus(); popupVisible = true; } function hidePopup() { if (dragState.isDragging) { dragEndHandler(); } if (popupDialog) { popupDialog.style.display = 'none'; } popupVisible = false; } function togglePopup() { if (popupVisible) { hidePopup(); } else { showPopup(); } } document.addEventListener('keydown', function(event) { if (event.altKey && event.shiftKey && event.key.toUpperCase() === 'M') { event.preventDefault(); togglePopup(); } }); createPopup(); console.log('Markdown to Plain Text Popup (Draggable & Improved Colors) script loaded. Press Alt+Shift+M to open.'); })();