Last active
March 12, 2025 09:35
-
-
Save alex-salnikov/bc49c71e6ba1284c14217939f3642bbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bookmarklet: finds filenames with common extensions (pdf, zip, doc, ..) | |
// - generated using claude.ai | |
javascript:(function() { | |
function findTextNodes(node) { | |
const textNodes = []; | |
function getTextNodes(node) { | |
if (node.nodeType === Node.TEXT_NODE) { | |
textNodes.push(node); | |
} else { | |
for (let i = 0; i < node.childNodes.length; i++) { | |
getTextNodes(node.childNodes[i]); | |
} | |
} | |
} | |
getTextNodes(node); | |
return textNodes; | |
} | |
const fileRegex = /\b[\w\-\.\+]+\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|mp3|mp4|wav|avi|mov|zip|rar|tar|gz)\b/gi; | |
const textNodes = findTextNodes(document.body); | |
const foundFiles = []; | |
textNodes.forEach(node => { | |
const text = node.nodeValue; | |
const matches = text.match(fileRegex); | |
if (matches) { | |
matches.forEach(match => { | |
if (!foundFiles.includes(match)) { | |
foundFiles.push(match); | |
} | |
}); | |
} | |
}); | |
if (foundFiles.length > 0) { | |
const resultsDiv = document.createElement('div'); | |
resultsDiv.style.position = 'fixed'; | |
resultsDiv.style.top = '20px'; | |
resultsDiv.style.right = '20px'; | |
resultsDiv.style.padding = '15px'; | |
resultsDiv.style.backgroundColor = '#f8f8f8'; | |
resultsDiv.style.border = '1px solid #ccc'; | |
resultsDiv.style.borderRadius = '5px'; | |
resultsDiv.style.boxShadow = '0 2px 10px rgba(0,0,0,0.2)'; | |
resultsDiv.style.zIndex = '9999'; | |
resultsDiv.style.maxHeight = '80vh'; | |
resultsDiv.style.overflow = 'auto'; | |
resultsDiv.style.fontFamily = 'Arial, sans-serif'; | |
const header = document.createElement('h3'); | |
header.textContent = `Found ${foundFiles.length} files:`; | |
header.style.margin = '0 0 10px 0'; | |
resultsDiv.appendChild(header); | |
const closeButton = document.createElement('button'); | |
closeButton.textContent = '×'; | |
closeButton.style.position = 'absolute'; | |
closeButton.style.top = '5px'; | |
closeButton.style.right = '8px'; | |
closeButton.style.border = 'none'; | |
closeButton.style.background = 'none'; | |
closeButton.style.fontSize = '20px'; | |
closeButton.style.cursor = 'pointer'; | |
closeButton.onclick = function() { document.body.removeChild(resultsDiv); }; | |
resultsDiv.appendChild(closeButton); | |
const extensionCounts = {}; | |
foundFiles.forEach(file => { | |
const extension = file.split('.').pop().toLowerCase(); | |
extensionCounts[extension] = (extensionCounts[extension] || 0) + 1; | |
}); | |
const summary = document.createElement('div'); | |
summary.style.fontSize = '13px'; | |
summary.style.marginBottom = '10px'; | |
summary.style.color = '#555'; | |
const countText = Object.entries(extensionCounts) | |
.map(([ext, count]) => `${ext.toUpperCase()}: ${count}`) | |
.join(', '); | |
summary.textContent = `By type: ${countText}`; | |
resultsDiv.appendChild(summary); | |
const list = document.createElement('ul'); | |
list.style.paddingLeft = '20px'; | |
list.style.margin = '0'; | |
foundFiles.forEach(file => { | |
const item = document.createElement('li'); | |
item.style.margin = '5px 0'; | |
item.style.display = 'flex'; | |
item.style.alignItems = 'center'; | |
item.style.justifyContent = 'space-between'; | |
const fileName = document.createElement('span'); | |
fileName.textContent = file; | |
fileName.style.marginRight = '10px'; | |
item.appendChild(fileName); | |
const copyButton = document.createElement('button'); | |
copyButton.textContent = 'Copy'; | |
copyButton.style.padding = '3px 8px'; | |
copyButton.style.fontSize = '12px'; | |
copyButton.style.cursor = 'pointer'; | |
copyButton.style.backgroundColor = '#f0f0f0'; | |
copyButton.style.border = '1px solid #ccc'; | |
copyButton.style.borderRadius = '3px'; | |
copyButton.onclick = function() { | |
navigator.clipboard.writeText(file).then( | |
function() { | |
const originalText = copyButton.textContent; | |
copyButton.textContent = 'Copied!'; | |
copyButton.style.backgroundColor = '#d4edda'; | |
copyButton.style.borderColor = '#c3e6cb'; | |
setTimeout(function() { | |
copyButton.textContent = originalText; | |
copyButton.style.backgroundColor = '#f0f0f0'; | |
copyButton.style.borderColor = '#ccc'; | |
}, 1500); | |
}, | |
function() { | |
copyButton.textContent = 'Failed!'; | |
copyButton.style.backgroundColor = '#f8d7da'; | |
copyButton.style.borderColor = '#f5c6cb'; | |
setTimeout(function() { | |
copyButton.textContent = 'Copy'; | |
copyButton.style.backgroundColor = '#f0f0f0'; | |
copyButton.style.borderColor = '#ccc'; | |
}, 1500); | |
} | |
); | |
}; | |
item.appendChild(copyButton); | |
list.appendChild(item); | |
}); | |
resultsDiv.appendChild(list); | |
document.body.appendChild(resultsDiv); | |
} else { | |
alert('No files found on this page.'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment