mirror of
https://github.com/elder-plinius/P4RS3LT0NGV3.git
synced 2026-02-13 09:12:47 +00:00
- Implement tool registry system with individual tool modules - Reorganize transformers into categorized source modules - Remove emojiLibrary.js, consolidate into EmojiUtils and emojiData - Fix mobile close button and tooltip functionality - Add build system for transforms and emoji data - Migrate from Python backend to pure JavaScript - Add comprehensive documentation and testing - Improve code organization and maintainability - Ignore generated files (transforms-bundle.js, emojiData.js)
101 lines
3.9 KiB
JavaScript
101 lines
3.9 KiB
JavaScript
function universalDecode(input, context = {}) {
|
|
if (!input) return null;
|
|
|
|
const allDecodings = [];
|
|
const { activeTab, activeTransform } = context;
|
|
|
|
function addDecoding(text, method, priority = 20) {
|
|
if (text && text !== input && text.length > 0) {
|
|
const exists = allDecodings.some(d => d.text === text);
|
|
if (!exists) {
|
|
allDecodings.push({ text, method, priority });
|
|
}
|
|
}
|
|
}
|
|
|
|
let foundHighPriorityMatch = false;
|
|
for (const [transformKey, transform] of Object.entries(window.transforms)) {
|
|
if (transform.detector && transform.reverse) {
|
|
try {
|
|
if (transform.detector(input)) {
|
|
const result = transform.reverse(input);
|
|
if (result && result !== input && result.length > 0) {
|
|
const hasContent = result.replace(/[\x00-\x1F\x7F-\x9F\s]/g, '').length > 0;
|
|
if (hasContent) {
|
|
const detectorPriority = transform.priority || 285;
|
|
addDecoding(result, transform.name, detectorPriority);
|
|
if (detectorPriority >= 280) {
|
|
foundHighPriorityMatch = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.debug('Error in transform detector:', e);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (foundHighPriorityMatch || allDecodings.some(d => d.priority >= 280)) {
|
|
const exclusiveMatches = allDecodings.filter(d => d.priority >= 280);
|
|
if (exclusiveMatches.length > 0) {
|
|
exclusiveMatches.sort((a, b) => b.priority - a.priority);
|
|
return {
|
|
text: exclusiveMatches[0].text,
|
|
method: exclusiveMatches[0].method,
|
|
alternatives: exclusiveMatches.slice(1).map(d => ({ text: d.text, method: d.method }))
|
|
};
|
|
}
|
|
}
|
|
|
|
if (window.steganography && window.steganography.hasEmojiInText && window.steganography.hasEmojiInText(input)) {
|
|
try {
|
|
const decoded = window.steganography.decodeEmoji(input);
|
|
if (decoded) {
|
|
addDecoding(decoded, 'Emoji Steganography', 100);
|
|
}
|
|
} catch (e) {
|
|
console.debug('Error decoding emoji steganography:', e);
|
|
}
|
|
}
|
|
|
|
if (activeTab === 'transforms' && activeTransform) {
|
|
try {
|
|
const transformKey = Object.keys(window.transforms).find(
|
|
key => window.transforms[key].name === activeTransform.name
|
|
);
|
|
|
|
if (transformKey && window.transforms[transformKey].reverse) {
|
|
const result = window.transforms[transformKey].reverse(input);
|
|
if (result && result !== input) {
|
|
addDecoding(result, activeTransform.name, 150);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('Error decoding with active transform:', e);
|
|
}
|
|
}
|
|
|
|
for (const name in window.transforms) {
|
|
const transform = window.transforms[name];
|
|
if (transform.reverse && !transform.detector) {
|
|
try {
|
|
const result = transform.reverse(input);
|
|
if (result !== input && /[a-zA-Z0-9\s]{3,}/.test(result)) {
|
|
addDecoding(result, transform.name, 10);
|
|
}
|
|
} catch (e) {
|
|
console.error(`Error decoding with ${name}:`, e);
|
|
}
|
|
}
|
|
}
|
|
|
|
allDecodings.sort((a, b) => b.priority - a.priority);
|
|
|
|
if (allDecodings.length === 0) return null;
|
|
|
|
const primary = allDecodings[0];
|
|
const alternatives = allDecodings.slice(1).map(({ text, method }) => ({ text, method }));
|
|
|
|
return { text: primary.text, method: primary.method, alternatives };
|
|
} |