- Go to https://www.torn.com/health.php
- Hit F12
- Paste the
torn-prettify.jscode in and hit enter
note: does not make Torn pretty
torn-prettify.js code in and hit enternote: does not make Torn pretty
| (async () => { | |
| document.querySelector('html').innerHTML = '<head></head><body>Loading...</body>' | |
| async function loadTornEngine(url) { | |
| const tornEngine = document.createElement('iframe') | |
| const onload = new Promise(res => tornEngine.onload = res) | |
| tornEngine.src = url | |
| tornEngine.style.height = '600px' | |
| tornEngine.style.width = '800px' | |
| tornEngine.style.position = 'fixed' | |
| tornEngine.style.bottom = '0' | |
| tornEngine.style.right = '0' | |
| document.body.appendChild(tornEngine) | |
| await onload | |
| // Find a better way to know Torn has loaded | |
| await new Promise(res => setTimeout(res, 2000)) | |
| return { windowRef: tornEngine.contentWindow, dispose: () => document.body.removeChild(tornEngine) } | |
| } | |
| async function getUserID() { | |
| const { windowRef, dispose } = await loadTornEngine(`/index.php`) | |
| const { userID } = JSON.parse(windowRef.document.querySelector('#websocketConnectionData').innerHTML) | |
| dispose() | |
| return userID | |
| } | |
| async function getUserName() { | |
| const userID = await getUserID() | |
| const { windowRef, dispose } = await loadTornEngine(`/profiles.php?XID=${userID}`) | |
| const userName = windowRef.document.querySelector('.info-table .user-info-value span').innerText.split('[')[0].trim() | |
| dispose() | |
| return userName | |
| } | |
| async function searchForCash() { | |
| const { windowRef, dispose } = await loadTornEngine('/crimes.php#') | |
| Array.from(windowRef.document.querySelectorAll('li')).filter(el => el.innerText.includes('Search for Cash'))[0].click() | |
| windowRef.document.querySelector('.torn-btn').click() | |
| await new Promise(res => setTimeout(res, 2000)) | |
| Array.from(windowRef.document.querySelectorAll('li')).filter(el => el.innerText.includes('Search the Train Station'))[0].click() | |
| windowRef.document.querySelector('.torn-btn').click() | |
| // Temporary pause to see if it worked | |
| await new Promise(res => setTimeout(res, 5000)) | |
| dispose() | |
| } | |
| let username = await getUserName() | |
| document.body.innerHTML = ` | |
| <h1>Hi ${username}</h1> | |
| <button id="search-for-cash">Search for cash</button> | |
| ` | |
| document.getElementById('search-for-cash').addEventListener('click', searchForCash) | |
| })() |