90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
// content.js - Content script that runs on web pages (Chrome-optimized)
|
|
|
|
function extractSQLQuery() {
|
|
// Look for the specific input element
|
|
const sqlInput = document.getElementById('SQLStatementHide');
|
|
|
|
if (sqlInput) {
|
|
const sqlQuery = sqlInput.value;
|
|
if (sqlQuery && sqlQuery.trim()) {
|
|
return cleanupSQLQuery(sqlQuery.trim());
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// Fallback: look for any input with name="SQLStatementHide"
|
|
const sqlInputByName = document.querySelector('input[name="SQLStatementHide"]');
|
|
if (sqlInputByName) {
|
|
const sqlQuery = sqlInputByName.value;
|
|
if (sqlQuery && sqlQuery.trim()) {
|
|
return cleanupSQLQuery(sqlQuery.trim());
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function cleanupSQLQuery(sqlQuery) {
|
|
// Fix double single quotes around dates/values (''2017-10-23'' becomes '2017-10-23')
|
|
// This handles the common issue where systems incorrectly double-escape quotes
|
|
return sqlQuery.replace(/''/g, "'");
|
|
}
|
|
|
|
// Listen for messages from popup
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
if (request.action === "extractSQL") {
|
|
const sqlQuery = extractSQLQuery();
|
|
sendResponse({
|
|
success: sqlQuery !== null,
|
|
sqlQuery: sqlQuery,
|
|
url: window.location.href,
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
}
|
|
});
|
|
|
|
// Optional: Add a visual indicator when SQL is found
|
|
function addVisualIndicator() {
|
|
const sqlInput = document.getElementById('SQLStatementHide') ||
|
|
document.querySelector('input[name="SQLStatementHide"]');
|
|
|
|
if (sqlInput && sqlInput.value && sqlInput.value.trim()) {
|
|
// Add a small visual indicator that SQL was found
|
|
if (!document.getElementById('sql-extractor-indicator')) {
|
|
const indicator = document.createElement('div');
|
|
indicator.id = 'sql-extractor-indicator';
|
|
indicator.style.cssText = `
|
|
position: fixed;
|
|
top: 10px;
|
|
right: 10px;
|
|
background: #4CAF50;
|
|
color: white;
|
|
padding: 5px 10px;
|
|
border-radius: 3px;
|
|
font-size: 12px;
|
|
z-index: 10000;
|
|
font-family: Arial, sans-serif;
|
|
opacity: 0.8;
|
|
pointer-events: none;
|
|
`;
|
|
indicator.textContent = 'SQL Query Found';
|
|
document.body.appendChild(indicator);
|
|
|
|
// Remove indicator after 3 seconds
|
|
setTimeout(() => {
|
|
if (document.getElementById('sql-extractor-indicator')) {
|
|
document.body.removeChild(indicator);
|
|
}
|
|
}, 3000);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Run indicator check when page loads
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', addVisualIndicator);
|
|
} else {
|
|
addVisualIndicator();
|
|
}
|