Simple Cracking Helper
当前为
// ==UserScript==
// @name torn-crack
// @namespace torn-crack
// @version 0.0.7.6
// @description Simple Cracking Helper
// @author SirAua [3785905]
// @match *://www.torn.com/page.php?sid=crimes*
// @grant GM_xmlhttpRequest
// @license mit
// ==/UserScript==
(function () {
'use strict';
if (window.CRACK_INJECTED) return;
window.CRACK_INJECTED = true;
const debug = false;
const UPDATE_INTERVAL = 800;
const MAX_SUG = 8;
const MAX_WORDS_PER_LENGTH = 10000;
const MIN_LENGTH = 4;
const MAX_LENGTH = 10;
const wordlistUrl = 'https://raw.githubusercontent.com/danielmiessler/SecLists/refs/heads/master/Passwords/Common-Credentials/xato-net-10-million-passwords-1000000.txt';
const DB_NAME = 'crack';
const STORE_NAME = 'dictionary';
let dict = [];
let dictLoaded = false;
function crackLog(...args) {
if (debug) console.log('[Crack]', ...args);
}
function openDB() {
return new Promise((resolve, reject) => {
const request = indexedDB.open(DB_NAME, 1);
request.onupgradeneeded = () => {
const db = request.result;
if (!db.objectStoreNames.contains(STORE_NAME)) {
db.createObjectStore(STORE_NAME);
}
};
request.onsuccess = () => resolve(request.result);
request.onerror = () => reject(request.error);
});
}
async function idbSet(key, value) {
const db = await openDB();
return new Promise((resolve, reject) => {
const tx = db.transaction(STORE_NAME, 'readwrite');
tx.objectStore(STORE_NAME).put(value, key);
tx.oncomplete = resolve;
tx.onerror = () => reject(tx.error);
});
}
async function idbGet(key) {
const db = await openDB();
return new Promise((resolve, reject) => {
const tx = db.transaction(STORE_NAME, 'readonly');
const req = tx.objectStore(STORE_NAME).get(key);
req.onsuccess = () => resolve(req.result);
req.onerror = () => reject(req.error);
});
}
async function idbClear() {
const db = await openDB();
return new Promise((resolve, reject) => {
const tx = db.transaction(STORE_NAME, 'readwrite');
tx.objectStore(STORE_NAME).clear();
tx.oncomplete = resolve;
tx.onerror = () => reject(tx.error);
});
}
async function clearLocalDictCache() {
await idbClear();
crackLog('Cleared cached dictionary from IndexedDB');
}
async function loadDict() {
if (dictLoaded) return;
crackLog('Attempting to load dictionary from IndexedDB...');
let hasData = false;
dict = [];
for (let len = MIN_LENGTH; len <= MAX_LENGTH; len++) {
const chunk = await idbGet(`len_${len}`);
if (chunk) {
dict[len] = chunk;
hasData = true;
}
}
if (hasData) {
dictLoaded = true;
crackLog('Dictionary loaded from IndexedDB');
return;
}
crackLog('No cache found. Downloading dictionary...');
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'get',
url: wordlistUrl,
timeout: 30000,
ontimeout: reject,
onerror: reject,
onload: async (res) => {
const lines = res.responseText.split(/\r?\n/).map(w => w.trim().toUpperCase());
dict = [];
for (const word of lines) {
if (!/^[A-Z0-9_.]+$/.test(word)) continue;
const len = word.length;
if (len < MIN_LENGTH || len > MAX_LENGTH) continue;
if (!dict[len]) dict[len] = [];
if (dict[len].length < MAX_WORDS_PER_LENGTH) {
dict[len].push(word);
}
}
for (let len = MIN_LENGTH; len <= MAX_LENGTH; len++) {
if (dict[len]) {
await idbSet(`len_${len}`, dict[len]);
}
}
dictLoaded = true;
crackLog('Dictionary downloaded and cached in IndexedDB');
resolve();
},
});
});
}
async function suggest(pat) {
const len = pat.length;
if (len < MIN_LENGTH || len > MAX_LENGTH) return [];
if (!dict[len]) {
const chunk = await idbGet(`len_${len}`);
if (!chunk) return [];
dict[len] = chunk;
}
const worker = new Worker(URL.createObjectURL(new Blob([`
self.onmessage = function(e) {
const { dictChunk, pattern, max } = e.data;
const regex = new RegExp('^' + pattern.replace(/[*]/g, '.') + '$');
const out = [];
for (const word of dictChunk) {
if (regex.test(word)) out.push(word);
if (out.length >= max) break;
}
self.postMessage(out);
};
`], { type: 'application/javascript' })));
return new Promise((resolve) => {
worker.onmessage = (e) => {
worker.terminate();
resolve([...new Set(e.data)]);
};
worker.postMessage({ dictChunk: dict[len], pattern: pat.toUpperCase(), max: MAX_SUG });
});
}
function prependPanelToRow(row, pat) {
const existing = row.querySelector('.__crackhelp_panel');
if (existing && existing.dataset.pattern === pat && existing.querySelector('span')) return;
if (existing) existing.remove();
const panel = document.createElement('div');
panel.className = '__crackhelp_panel';
panel.dataset.pattern = pat;
panel.style.cssText = 'background: #000; font-size: 10px; text-align: center; position: absolute; z-index: 9999;';
const listDiv = document.createElement('div');
listDiv.style.cssText = 'margin-top: 2px;';
panel.appendChild(listDiv);
row.prepend(panel);
async function updateSuggestions() {
const sugs = await suggest(pat);
listDiv.innerHTML = '';
sugs.forEach(word => {
const sp = document.createElement('span');
sp.style.cssText = 'padding:2px; color: #00ff00;';
sp.textContent = word;
listDiv.appendChild(sp);
});
if (sugs.length === 0) {
const none = document.createElement('span');
none.textContent = '(no matches)';
none.style.color = '#a00';
listDiv.appendChild(none);
}
}
loadDict().then(updateSuggestions);
}
function scanCrimePage() {
if (!location.href.endsWith('cracking')) return;
const currentCrime = document.querySelector('[class^="currentCrime"]');
if (!currentCrime) return;
const container = currentCrime.querySelector('[class^="virtualList"]');
if (!container) return;
const crimeOptions = container.querySelectorAll('[class^="crimeOptionWrapper"]');
crackLog('Scanning crime options:', crimeOptions.length);
for (const crimeOption of crimeOptions) {
let patText = '';
const charSlots = crimeOption.querySelectorAll('[class^="charSlot"]:not([class*="charSlotDummy"])');
for (const charSlot of charSlots) {
let char = charSlot.textContent.trim();
patText += char ? char.toUpperCase() : '*';
}
if (!/^[*]+$/.test(patText)) prependPanelToRow(crimeOption, patText);
}
}
function showMenuOverlay() {
const overlay = document.createElement('div');
overlay.style.cssText = `
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.7); color: #fff;
display: flex; align-items: center; justify-content: center;
z-index: 10000; font-size: 14px;
`;
const box = document.createElement('div');
box.style.cssText = `
background: #111; padding: 20px; border: 1px solid #0f0;
border-radius: 6px; text-align: center; min-width: 300px;
`;
box.innerHTML = `<div style="margin-bottom: 12px; font-size: 14px; color: #0f0;">Settings</div>`;
const btnCache = document.createElement('button');
btnCache.textContent = 'Clear Wordlist Cache';
btnCache.style.cssText = 'margin: 4px; padding: 4px 8px; background: #a00; color: #fff; cursor: pointer;';
btnCache.onclick = async () => { await clearLocalDictCache(); location.reload(); };
const cancelBtn = document.createElement('button');
cancelBtn.textContent = 'Cancel';
cancelBtn.style.cssText = 'margin: 4px; padding: 4px 8px; background: #222; color: #fff; cursor: pointer;';
cancelBtn.onclick = () => { document.body.removeChild(overlay); };
box.appendChild(btnCache);
box.appendChild(cancelBtn);
overlay.appendChild(box);
document.body.appendChild(overlay);
}
function injectMenuButton() {
if (!location.href.endsWith('cracking')) return;
if (document.getElementById('__crack_menu_btn')) return;
const appHeader = document.querySelector('[class^="appHeaderDelimiter"]');
if (!appHeader) return;
const btn = document.createElement('button');
btn.id = '__crack_menu_btn';
btn.textContent = 'Bruteforce characters to show suggestions! (Click this message to open a menu)';
btn.style.cssText = 'background: #000; color: #0f0; font-size: 10px; text-align: left; z-index: 9999; cursor: pointer;';
btn.onclick = showMenuOverlay;
appHeader.appendChild(btn);
}
scanCrimePage();
setInterval(scanCrimePage, UPDATE_INTERVAL);
setInterval(injectMenuButton, UPDATE_INTERVAL);
})();