feat: improve Clipboard Sniffer extension integration and UI fixes

This commit is contained in:
2026-02-27 03:37:33 +00:00
parent 1d7fd9a5bc
commit 8e8bf47297
14 changed files with 872 additions and 181 deletions

View File

@@ -1,51 +1,135 @@
<script setup>
import { ref, onUnmounted, nextTick } from 'vue'
import { ref, onUnmounted, nextTick, onMounted } from 'vue'
import { useFillHeight } from '../../composables/useFillHeight'
import { Plug, Info, X } from 'lucide-vue-next'
const clipboardContent = ref('')
const isListening = ref(false)
const lastClipboardText = ref('')
const textareaRef = ref(null)
const isExtensionReady = ref(false)
const showExtensionModal = ref(false)
let intervalId = null
let extensionCheckInterval = null
const { height: textareaHeight } = useFillHeight(textareaRef, 40) // 40px margin bottom
// Listen for extension messages
const handleExtensionMessage = (event) => {
if (event.source !== window) return
if (event.data.type === 'TOOLS_APP_EXTENSION_READY' || event.data.type === 'TOOLS_APP_PONG') {
isExtensionReady.value = true
lastPongTime = Date.now()
// console.log('Extension is ready')
}
if (event.data.type === 'TOOLS_APP_CLIPBOARD_UPDATE' && isListening.value) {
const text = event.data.content
if (text && text !== lastClipboardText.value) {
lastClipboardText.value = text
clipboardContent.value += (clipboardContent.value ? '\n' : '') + text
scrollToBottom()
}
}
}
const closeModalOnEsc = (e) => {
if (e.key === 'Escape' && showExtensionModal.value) {
showExtensionModal.value = false
}
}
// Watchdog for extension
let lastPongTime = Date.now()
const PING_INTERVAL = 200
const TIMEOUT_THRESHOLD = 500
const startExtensionWatchdog = () => {
extensionCheckInterval = setInterval(() => {
// 1. Send Ping
window.postMessage({ type: 'TOOLS_APP_PING' }, '*')
// 2. Check timeout
// If current time - lastPongTime > threshold, then disconnected
if (Date.now() - lastPongTime > TIMEOUT_THRESHOLD) {
isExtensionReady.value = false
}
}, PING_INTERVAL)
}
// Wrapper to intercept PONG and update heartbeat
const messageListener = (event) => {
if (event.source !== window) return
if (event.data.type === 'TOOLS_APP_PONG' || event.data.type === 'TOOLS_APP_EXTENSION_READY') {
lastPongTime = Date.now()
isExtensionReady.value = true
}
handleExtensionMessage(event)
}
onMounted(() => {
window.addEventListener('message', messageListener)
window.addEventListener('keydown', closeModalOnEsc)
// Initial check
window.postMessage({ type: 'TOOLS_APP_INIT' }, '*')
// Start heartbeat
startExtensionWatchdog()
})
onUnmounted(() => {
stopListening()
if (extensionCheckInterval) clearInterval(extensionCheckInterval)
window.removeEventListener('message', messageListener)
window.removeEventListener('keydown', closeModalOnEsc)
})
const scrollToBottom = () => {
nextTick(() => {
const textarea = document.querySelector('.tool-textarea')
if (textarea) {
textarea.scrollTop = textarea.scrollHeight
}
})
}
const startListening = async () => {
try {
// Initial read to ask for permission/check access
const text = await navigator.clipboard.readText()
lastClipboardText.value = text // Don't paste existing content immediately, only new content?
// Or maybe we want to paste the current content immediately?
// "wklejaj nasluchane wartosci" - usually implies new values.
// Let's set current as last seen so we don't duplicate it if it's already there?
// Actually, user might want the current clipboard too.
// Let's assume we start clean or append.
// If I set lastClipboardText to current, it won't be added.
// Let's add the current text if it's not empty.
if (text) {
lastClipboardText.value = text
clipboardContent.value += (clipboardContent.value ? '\n' : '') + text
}
isListening.value = true
// Try native API first (for web app usage without extension)
// Initial read
try {
const text = await navigator.clipboard.readText()
if (text) {
lastClipboardText.value = text
clipboardContent.value += (clipboardContent.value ? '\n' : '') + text
scrollToBottom()
}
} catch (e) {
console.log('Native clipboard read failed (expected if not focused), relying on extension if available')
}
// If extension is ready, ask it to start sniffing
if (isExtensionReady.value) {
window.postMessage({ type: 'TOOLS_APP_START_SNIFFING' }, '*')
}
// Fallback polling for web app (only works when focused usually)
intervalId = setInterval(async () => {
try {
const currentText = await navigator.clipboard.readText()
if (currentText && currentText !== lastClipboardText.value) {
lastClipboardText.value = currentText
clipboardContent.value += (clipboardContent.value ? '\n' : '') + currentText
// Auto-scroll to bottom
const textarea = document.querySelector('.tool-textarea')
if (textarea) {
textarea.scrollTop = textarea.scrollHeight
}
scrollToBottom()
}
} catch (err) {
console.error('Failed to read clipboard:', err)
// Don't stop immediately on one error, could be temporary focus loss?
// But if permission revoked, maybe stop.
// Ignore errors in polling (e.g. lost focus)
}
}, 1000)
} catch (err) {
@@ -60,6 +144,10 @@ const stopListening = () => {
clearInterval(intervalId)
intervalId = null
}
if (isExtensionReady.value) {
window.postMessage({ type: 'TOOLS_APP_STOP_SNIFFING' }, '*')
}
}
const clearText = () => {
@@ -90,7 +178,18 @@ onUnmounted(() => {
<template>
<div class="tool-container" style="max-width: 100%;">
<div class="tool-panel">
<h2 class="tool-title">Clipboard Sniffer</h2>
<div class="tool-header">
<h2 class="tool-title">Clipboard Sniffer</h2>
<div
class="extension-status"
:class="{ 'connected': isExtensionReady }"
@click="showExtensionModal = true"
:title="isExtensionReady ? 'Extension connected' : 'Extension not detected - Click for info'"
>
<Plug v-if="isExtensionReady" size="20" />
<Info v-else size="20" />
</div>
</div>
<div class="controls">
<button
@@ -119,20 +218,187 @@ onUnmounted(() => {
</button>
</div>
<div class="result-area" style="margin-top: 2rem;">
<div class="result-area" style="margin-top: 1rem;">
<div ref="textareaRef" :style="{ height: textareaHeight, width: '100%' }">
<textarea
v-model="clipboardContent"
class="tool-textarea"
placeholder="Clipboard content will appear here line by line..."
readonly
></textarea>
</div>
</div>
</div>
<!-- Extension Info Modal -->
<div v-if="showExtensionModal" class="modal-overlay" @click.self="showExtensionModal = false">
<div class="modal-content glass-panel">
<button class="close-btn" @click="showExtensionModal = false">
<X size="24" />
</button>
<div v-if="!isExtensionReady">
<h3>Enhance Your Experience</h3>
<p>
Install our browser extension to enable <strong>background clipboard sniffing</strong>!
</p>
<p class="description">
Without the extension, this tool can only capture clipboard content when the tab is active.
With the extension, you can capture content even when you're working in other apps.
</p>
<div class="modal-actions">
<a href="#" class="btn-neon" @click.prevent>Extension Coming Soon</a>
</div>
</div>
<div v-else>
<h3>Extension Connected!</h3>
<p>
You have successfully enabled <strong>background clipboard sniffing</strong>.
</p>
<p class="description">
The extension is active and monitoring your clipboard in the background.
You can now switch to other apps and copy text - it will appear here automatically.
</p>
<div class="modal-actions">
<button class="btn-neon" @click="showExtensionModal = false">Got it!</button>
</div>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.tool-header {
display: flex;
justify-content: center;
align-items: center;
position: relative;
width: 100%;
}
.extension-status {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
color: var(--text-secondary);
cursor: pointer;
transition: all 0.3s ease;
}
:global(:root[data-theme="light"]) .extension-status {
background: rgba(0, 0, 0, 0.05);
color: #666;
}
.extension-status:hover {
background: rgba(255, 255, 255, 0.2);
color: var(--text-color);
}
:global(:root[data-theme="light"]) .extension-status:hover {
background: rgba(0, 0, 0, 0.1);
color: #000;
}
.extension-status.connected {
color: #4ade80; /* Green for connected */
cursor: pointer; /* Allow clicking to see status */
}
/* :global(:root[data-theme="light"]) .extension-status.connected {
color: #16a34a;
} */
.extension-status.connected:hover {
background: rgba(74, 222, 128, 0.1);
}
/* :global(:root[data-theme="light"]) .extension-status.connected:hover {
background: rgba(22, 163, 74, 0.1);
} */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(4px);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
position: relative;
width: 90%;
max-width: 500px;
padding: 2rem;
border-radius: 16px;
background: var(--glass-bg);
border: 1px solid var(--glass-border);
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
text-align: center;
}
.close-btn {
position: absolute;
top: 1rem;
right: 1rem;
background: none;
border: none;
color: var(--text-secondary);
cursor: pointer;
padding: 0.5rem;
border-radius: 50%;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
}
.close-btn:hover {
background: rgba(255, 255, 255, 0.1);
color: var(--text-color);
}
.modal-content h3 {
margin-top: 0;
margin-bottom: 1rem;
font-size: 1.5rem;
color: var(--text-color);
}
.modal-content p {
margin-bottom: 1rem;
line-height: 1.6;
color: var(--text-color);
}
.description {
color: var(--text-secondary) !important;
font-size: 0.9rem;
margin-bottom: 2rem !important;
}
.modal-actions {
display: flex;
justify-content: center;
}
.controls {
display: flex;
gap: 1rem;

View File

@@ -71,9 +71,16 @@ const generatePasswords = () => {
</script>
<template>
<div class="tool-container">
<div class="tool-container full-width">
<div class="tool-panel">
<h2 class="tool-title">Bulk Passwords Generator</h2>
<div class="panel-header">
<h2 class="tool-title">Bulk Passwords Generator</h2>
<div class="action-area">
<button class="btn-neon generate-btn" @click="generatePasswords" v-ripple>
Generate
</button>
</div>
</div>
<div class="options-grid">
<div class="checkbox-group">
@@ -100,13 +107,13 @@ const generatePasswords = () => {
<label class="checkbox-label">
<input type="checkbox" v-model="skipSimilar">
<span class="checkmark"></span>
Skip Similar Chars (I, l, 1, O, 0, o)
Skip Similar (I, l, 1, O, 0, o)
</label>
</div>
<div class="inputs-group">
<div class="input-wrapper">
<label>Password Length</label>
<label>Length</label>
<div class="number-control">
<button class="control-btn" @click="length > 4 ? length-- : null">-</button>
<input type="number" v-model="length" min="4" max="128" class="number-input">
@@ -114,7 +121,7 @@ const generatePasswords = () => {
</div>
</div>
<div class="input-wrapper">
<label>Passwords Number</label>
<label>Count</label>
<div class="number-control">
<button class="control-btn" @click="count > 1 ? count-- : null">-</button>
<input type="number" v-model="count" min="1" max="1000" class="number-input">
@@ -124,37 +131,74 @@ const generatePasswords = () => {
</div>
</div>
<div class="action-area">
<button class="btn-neon generate-btn" @click="generatePasswords" v-ripple>
Generate
</button>
</div>
<div class="result-area">
<label>Passwords</label>
<div ref="textareaRef" :style="{ height: textareaHeight, width: '100%' }">
<textarea
class="tool-textarea"
v-model="result"
placeholder="Generated passwords will appear here..."
></textarea>
</div>
<div class="result-area" :style="{ height: textareaHeight }">
<textarea
class="tool-textarea"
v-model="result"
placeholder="Generated passwords will appear here..."
readonly
></textarea>
</div>
</div>
</div>
</template>
<style scoped>
.options-grid {
.tool-container.full-width {
max-width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
.tool-panel {
display: flex;
flex-direction: column;
height: 100%;
gap: 1.5rem;
}
.panel-header {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
.tool-title {
margin: 0;
}
.options-grid {
display: flex;
flex-wrap: wrap;
gap: 2rem;
padding: 1rem;
background: var(--toggle-bg);
border: 1px solid var(--toggle-border);
border-radius: 12px;
}
.checkbox-group {
display: flex;
flex-wrap: wrap;
gap: 1rem;
gap: 1.5rem;
flex: 2;
}
.inputs-group {
display: flex;
gap: 2rem;
flex: 1;
min-width: 300px;
}
.input-wrapper {
display: flex;
flex-direction: column;
gap: 0.5rem;
flex: 1;
}
.checkbox-label {
@@ -166,9 +210,9 @@ const generatePasswords = () => {
color: var(--text-secondary);
font-weight: 500;
white-space: nowrap;
flex: 1 0 auto;
}
/* Custom Checkbox */
.checkbox-label input {
position: absolute;
opacity: 0;
@@ -212,86 +256,63 @@ const generatePasswords = () => {
top: 2px;
width: 5px;
height: 10px;
border: solid white;
border: solid #000;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
.inputs-group {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
}
.input-wrapper {
display: flex;
flex-direction: column;
gap: 0.5rem;
flex: 1;
min-width: 200px;
}
.input-wrapper label {
color: var(--text-secondary);
font-weight: 500;
font-size: 0.9rem;
}
/* Number Control */
.number-control {
display: flex;
align-items: stretch;
background: var(--toggle-bg);
border: 1px solid var(--toggle-border);
border-radius: 8px;
overflow: hidden;
gap: 0;
}
.control-btn {
width: 42px;
background: none;
border: none;
color: var(--text-color);
font-size: 1.2rem;
width: 40px;
height: auto;
min-height: 40px;
cursor: pointer;
transition: background 0.2s;
padding: 0;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
background-color: var(--toggle-bg);
border: 1px solid var(--toggle-border);
color: var(--text-color);
border-radius: 0;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.2s;
user-select: none;
}
.control-btn:first-child {
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
border-right: none;
}
.control-btn:last-child {
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
border-left: none;
}
.control-btn:hover {
background-color: var(--button-hover-bg);
border-color: var(--toggle-hover-border);
z-index: 1;
}
.control-btn:active {
transform: scale(0.98);
background: var(--button-hover-bg);
}
.number-input {
flex: 1;
padding: 0.8rem;
background-color: var(--toggle-bg);
border: 1px solid var(--toggle-border);
border-radius: 0;
background: none;
border: none;
color: var(--text-color);
font-size: 1rem;
transition: border-color 0.3s;
width: 100%;
flex: 1;
text-align: center;
appearance: textfield; /* Remove default spinner */
min-width: 0;
font-size: 1rem;
font-weight: bold;
appearance: textfield;
-moz-appearance: textfield;
height: 100%;
border-radius: 0;
min-width: 60px;
}
.number-input:focus {
outline: none;
box-shadow: none;
background: rgba(0, 0, 0, 0.05);
}
.number-input::-webkit-outer-spin-button,
@@ -300,90 +321,54 @@ const generatePasswords = () => {
margin: 0;
}
.number-input:focus {
outline: none;
border-color: var(--primary-accent);
box-shadow: 0 0 0 2px var(--toggle-active-shadow);
z-index: 2;
position: relative;
}
.action-area {
display: flex;
justify-content: center;
margin-top: 1rem;
width: 100%;
}
.btn-neon {
width: 100%;
background: var(--button-bg);
border: 1px solid var(--button-border);
color: var(--button-text);
padding: 0.8rem 2rem;
font-size: 1.1rem;
font-weight: 600;
border-radius: 12px;
cursor: pointer;
transition: all 0.3s ease;
text-transform: uppercase;
letter-spacing: 1px;
position: relative;
overflow: hidden;
}
.btn-neon:hover {
background: var(--button-hover-bg);
box-shadow: var(--button-hover-shadow);
transform: translateY(-2px);
border-color: var(--toggle-hover-border);
}
.btn-neon:active {
transform: translateY(1px);
box-shadow: var(--button-active-shadow);
}
.result-area {
flex: 1;
display: flex;
flex-direction: column;
gap: 0.5rem;
flex: 1;
min-height: 200px;
}
.result-area label {
color: var(--text-secondary);
font-weight: 500;
font-size: 0.9rem;margin-top: auto;
}
.tool-textarea {
min-height: 200px;
resize: vertical;
}
.result-textarea:focus {
width: 100%;
height: 100%;
padding: 1rem;
border-radius: 12px;
border: 1px solid var(--glass-border);
background: var(--glass-bg);
color: var(--text-color);
font-family: monospace;
font-size: 0.9rem;
resize: none;
outline: none;
border-color: var(--primary-accent);
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}
/* Scrollbar for textarea */
.result-textarea::-webkit-scrollbar {
width: 8px;
.generate-btn {
padding: 0.75rem 2rem;
font-size: 1rem;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
}
.result-textarea::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.1);
border-radius: 4px;
}
@media (max-width: 768px) {
.options-grid {
flex-direction: column;
gap: 1rem;
}
.result-textarea::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.2);
border-radius: 4px;
}
.inputs-group {
flex-direction: column;
min-width: 100%;
}
.result-textarea::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.3);
.panel-header {
flex-direction: column;
align-items: stretch;
}
.generate-btn {
width: 100%;
}
}
</style>

View File

@@ -55,7 +55,7 @@
}
:root[data-theme="light"] {
--bg-gradient: radial-gradient(circle at center, #ffffff 0%, #cccccc 100%);
--bg-gradient: radial-gradient(circle at center, #ffffff 0%, #e5e7eb 100%);
--glass-bg: rgba(255, 255, 255, 0.75);
--glass-border: rgba(15, 23, 42, 0.12);
--glass-shadow: 0 8px 32px 0 rgba(15, 23, 42, 0.12);