| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/python273/eimi/master/scripts/code-block-differ.js | [Back] [Original] |
Focus on a message with code blocks to see diff
No code blocks found in messages
'; return; } const code1 = firstCodeBlocks[firstCodeBlocks.length - 1]; const code2 = secondCodeBlocks[secondCodeBlocks.length - 1]; // Preserve scroll position of the entire window let scrollTop = 0; const diffContentEl = this.windowArgs.el.querySelector('#diff-content'); if (diffContentEl && diffContentEl.firstElementChild) { scrollTop = diffContentEl.firstElementChild.scrollTop; } diffContentEl.innerHTML = this.createDiffView(code1, code2); // Restore scroll position after updating content if (diffContentEl && diffContentEl.firstElementChild) { diffContentEl.firstElementChild.scrollTop = scrollTop; } } extractCodeBlocks(content) { const codeBlockRegex = /```[\s\S]*?```/g; const matches = content.match(codeBlockRegex) || []; return matches.map(block => block.slice(3, -3).trim()); } createDiffView(code1, code2) { if (typeof Diff === 'undefined') { return "Diff library not loaded. Please try again.
"; } const escapeHtml = (unsafe) => { return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); }; const truncateNonChangedBlock = (lines) => { if (lines.length { const color = part.added ? '#0f0' : part.removed ? '#ff6e04' : 'grey'; const bgColor = part.added ? '#00ff001f' : part.removed ? '#ff00001f' : 'transparent'; // For non-changed parts, truncate middle lines let lines = part.value.split('\n') if (!part.added && !part.removed) { lines = truncateNonChangedBlock(lines); } // Escape HTML in the diff content const escapedValue = lines.map(line => escapeHtml(line)).join('\n'); result += `| Web Proxy Viewer | New URL | Original Page |