Enhance CyberChef workstation popup with dynamic file loading

- Implemented dynamic CyberChef HTML file discovery
- Added flexible iframe loading mechanism
- Improved CSS for CyberChef container
- Removed verbose console logging
- Simplified workstation interaction logic
This commit is contained in:
Damian-I
2025-02-01 02:09:13 +00:00
parent 48ca5248ff
commit 66f15ccb9a

View File

@@ -87,6 +87,18 @@
height: 100%;
border: none;
}
#cyberchef-container {
flex: 1;
width: 100%;
height: 100%;
}
#cyberchef-container iframe {
width: 100%;
height: 100%;
border: none;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.60.0/dist/phaser.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/easystarjs@0.4.4/bin/easystar-0.4.4.js"></script>
@@ -204,7 +216,7 @@
// creates the workstation
function addCryptoWorkstation() {
console.log('CyberChef: Adding crypto workstation...');
// console.log('CyberChef: Adding crypto workstation...');
const workstationData = {
type: "workstation",
name: "Crypto Analysis Station",
@@ -220,11 +232,11 @@
// Override the default handleObjectInteraction for this specific item
workstationSprite.customInteraction = function() {
console.log('CyberChef: Workstation custom interaction triggered');
// console.log('CyberChef: Workstation custom interaction triggered');
// Create popup
let popup = document.getElementById('laptop-popup');
if (!popup) {
console.log('CyberChef: Creating new popup...');
// console.log('CyberChef: Creating new popup...');
popup = document.createElement('div');
popup.id = 'laptop-popup';
popup.innerHTML = `
@@ -234,13 +246,33 @@
<span>CryptoWorkstation</span>
<button class="close-btn">&times;</button>
</div>
<iframe src="assets/cyberchef/CyberChef_v10.19.4.html" frameborder="0"></iframe>
<div id="cyberchef-container"></div>
</div>
</div>
`;
document.body.appendChild(popup);
// Add close button handler
// Find the CyberChef file
fetch('assets/cyberchef/')
.then(response => response.text())
.then(html => {
// Use regex to find the CyberChef filename
const match = html.match(/CyberChef_v[0-9.]+\.html/);
if (match) {
const cyberchefPath = `assets/cyberchef/${match[0]}`;
// Create and append the iframe with the found path
const iframe = document.createElement('iframe');
iframe.src = cyberchefPath;
iframe.frameBorder = "0";
document.getElementById('cyberchef-container').appendChild(iframe);
} else {
console.error('Could not find CyberChef file');
}
})
.catch(error => {
console.error('Error loading CyberChef:', error);
});
popup.querySelector('.close-btn').addEventListener('click', () => {
popup.style.display = 'none';
});
@@ -251,7 +283,7 @@
// Add to inventory directly
addToInventory(workstationSprite);
console.log('CyberChef: Workstation added to inventory');
// console.log('CyberChef: Workstation added to inventory');
}
// creates the game