Snapshot of the working tree exactly as it stood, no edits. This is the predecessor
PRICEGOD was rewritten from ("kept intact, untouched" per pricegod/README.md), and it
is still the only place the DYMO scale is actually implemented —
rfid-daemon/index.js:1068-1265: HID discovery, parseScaleReport, one-shot read, and a
streaming /weight + /scale/start|stop session whose JSON shape PRICEGOD's daemon.js
already speaks.
Preserved verbatim on purpose (hence -og), including the known bug: DYMO_PIDS at
index.js:1082 is [0x8003, 0x8004], so it cannot see the bench M25 (0x8009). Fix that
in whatever daemon inherits the scale, not here.
node_modules stays ignored (22M of the 24M tree). No credentials in the import: the
two PEM markers in utils.js/sheets.js only strip headers off a key read from settings,
and mrpadmin / johnking are an SSH and a Postgres username, both key/trust auth.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
152 lines
4.9 KiB
JavaScript
152 lines
4.9 KiB
JavaScript
// BLAGGINATE Bridge Content Script
|
|
// This script runs on the BLAGGINATE admin page to establish communication with the extension
|
|
|
|
console.log('BLAGGINATE Bridge: Content script loaded');
|
|
|
|
// Global variable to store cookies
|
|
window.youtubeCookies = null;
|
|
window.lastCookieUpdate = null;
|
|
|
|
// Function to handle cookie updates from the extension
|
|
function handleCookieUpdate(cookies) {
|
|
window.youtubeCookies = cookies;
|
|
window.lastCookieUpdate = Date.now();
|
|
console.log('BLAGGINATE Bridge: YouTube cookies updated');
|
|
|
|
// Trigger custom event for the BLAGGINATE page to listen to
|
|
const event = new CustomEvent('youtubeCookiesUpdated', {
|
|
detail: {
|
|
cookies: cookies,
|
|
timestamp: window.lastCookieUpdate
|
|
}
|
|
});
|
|
document.dispatchEvent(event);
|
|
}
|
|
|
|
// Function to get current cookies (can be called by BLAGGINATE page)
|
|
window.getYouTubeCookies = function() {
|
|
return {
|
|
cookies: window.youtubeCookies,
|
|
timestamp: window.lastCookieUpdate
|
|
};
|
|
};
|
|
|
|
// Beatport token bridge — mirrors the YouTube cookies pattern
|
|
window.getBeatportToken = function() {
|
|
return new Promise(function(resolve) {
|
|
chrome.storage.local.get(['beatportAuth'], function(result) {
|
|
resolve(result.beatportAuth || null);
|
|
});
|
|
});
|
|
};
|
|
|
|
window.requestFreshBeatportToken = function() {
|
|
return new Promise(function(resolve, reject) {
|
|
chrome.runtime.sendMessage({ action: 'refreshBeatportToken' }, function(response) {
|
|
if (chrome.runtime.lastError) return reject(new Error(chrome.runtime.lastError.message));
|
|
resolve(response);
|
|
});
|
|
});
|
|
};
|
|
|
|
// Function to request fresh cookies from extension
|
|
window.requestFreshCookies = function() {
|
|
return new Promise((resolve, reject) => {
|
|
chrome.runtime.sendMessage({
|
|
type: 'get_cookies'
|
|
}, (response) => {
|
|
if (chrome.runtime.lastError) {
|
|
reject(chrome.runtime.lastError);
|
|
return;
|
|
}
|
|
|
|
if (response && response.cookies) {
|
|
handleCookieUpdate(response.cookies);
|
|
resolve(response);
|
|
} else {
|
|
reject(new Error('No cookies available'));
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
// Listen for messages from the background script
|
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
console.log('BLAGGINATE Bridge: Received message:', message.type);
|
|
|
|
if (message.type === 'cookieUpdate') {
|
|
handleCookieUpdate(message.cookies);
|
|
sendResponse({ success: true });
|
|
return true;
|
|
}
|
|
|
|
if (message.type === 'ping') {
|
|
console.log('BLAGGINATE Bridge: Ping received');
|
|
sendResponse({ success: true, timestamp: Date.now() });
|
|
return true;
|
|
}
|
|
});
|
|
|
|
// Notify background script that BLAGGINATE page is ready
|
|
function notifyReady() {
|
|
chrome.runtime.sendMessage({
|
|
type: 'blagginate_ready'
|
|
}, (response) => {
|
|
if (chrome.runtime.lastError) {
|
|
console.log('BLAGGINATE Bridge: Failed to connect to background script:', chrome.runtime.lastError);
|
|
// Retry after a delay
|
|
setTimeout(notifyReady, 2000);
|
|
} else {
|
|
console.log('BLAGGINATE Bridge: Successfully connected to extension background');
|
|
}
|
|
});
|
|
}
|
|
|
|
// Wait for page to be fully loaded before notifying
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
setTimeout(notifyReady, 1000); // Small delay to ensure page is ready
|
|
});
|
|
} else {
|
|
setTimeout(notifyReady, 1000);
|
|
}
|
|
|
|
// Add visual indicator that the bridge is active
|
|
function addBridgeIndicator() {
|
|
const indicator = document.createElement('div');
|
|
indicator.id = 'youtube-cookie-bridge-indicator';
|
|
indicator.style.cssText = `
|
|
position: fixed;
|
|
top: 10px;
|
|
right: 10px;
|
|
background: #4CAF50;
|
|
color: white;
|
|
padding: 8px 12px;
|
|
border-radius: 4px;
|
|
font-size: 12px;
|
|
font-family: Arial, sans-serif;
|
|
z-index: 10000;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
|
`;
|
|
indicator.textContent = 'YouTube Cookie Bridge: Connected';
|
|
document.body.appendChild(indicator);
|
|
|
|
// Update indicator when cookies are received
|
|
document.addEventListener('youtubeCookiesUpdated', () => {
|
|
indicator.style.background = '#2196F3';
|
|
indicator.textContent = 'YouTube Cookie Bridge: Cookies Updated';
|
|
setTimeout(() => {
|
|
indicator.style.background = '#4CAF50';
|
|
indicator.textContent = 'YouTube Cookie Bridge: Connected';
|
|
}, 2000);
|
|
});
|
|
}
|
|
|
|
// Add indicator when page is ready
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', addBridgeIndicator);
|
|
} else {
|
|
addBridgeIndicator();
|
|
}
|
|
|
|
console.log('BLAGGINATE Bridge: Initialization complete'); |