Guest User

RS2004 Autofil

a guest
Jan 16th, 2026
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         2004Scape Login
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2026-01-16
  5. // @description  Connects the browser's secure password manager to RS2004 game login screen
  6. // @author       LR2004
  7. // @include      https://w*-2004.lostcity.rs/rs2.cgi*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=lostcity.rs
  9. // @run-at       document-end
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     'use strict';
  14.     // 1. check page, either provide hotlink to iframe page, or to provide login form
  15.     const iframeTabOpened = window.top === window.self;
  16.     const worldNum = location.href.match(/world=(\d+)/i)[1];
  17.  
  18.     const lowmem = window.location.search.includes("lowmem=1") ? 1 : 0;
  19.  
  20.     if ( !iframeTabOpened ) { // 1a. hotlink to iframe page
  21.         const controlBarEl = document.querySelector('#controls');
  22.         controlBarEl.appendChild(document.createTextNode(" | "));
  23.         const iframeUrlNewTabEl = document.createElement('a');
  24.         iframeUrlNewTabEl.innerText = "Expose Client Mode";
  25.         iframeUrlNewTabEl.href = "https://w"+worldNum+"-2004.lostcity.rs/rs2.cgi?plugin=0&world="+worldNum+"&lowmem="+lowmem;
  26.         iframeUrlNewTabEl.target = '_blank';
  27.         controlBarEl.appendChild(iframeUrlNewTabEl);
  28.         return;
  29.     }
  30.  
  31.     // 1b. provide login form...
  32.  
  33.  
  34.     // 3. grab page HTML and customise it so that "c" will be defined as a the Client instance,
  35.     //    and lastly create a message listener for login details, and set in window.c.
  36.     const html = document.getElementsByTagName("html")[0].innerHTML;
  37.     const clientNum = html.match(/new Client\((\d+)/)[1];//need to grab nums in constructor or else won't work for
  38.     const customHTML = html.replace("new Client("+clientNum+", "+lowmem+", true);", `
  39.     window.c = new Client(${clientNum}, ${lowmem}, true);
  40.     addEventListener("message", e => {
  41.         if (e.data.hasOwnProperty('username') && e.data.hasOwnProperty('password')) {
  42.             c.login(e.data.username,e.data.password); // obsfucated but exists!
  43.         }
  44.     });
  45.     `);
  46.  
  47.  
  48.     // 4. create iframe and inject into current page
  49.     const iframe = document.createElement('iframe');
  50.     iframe.width = '100%';
  51.     iframe.height = '1000px';
  52.     document.body.appendChild(iframe);
  53.  
  54.  
  55.     // 5. inject custom HTML into iframe
  56.     iframe.contentWindow.document.open();
  57.     iframe.contentWindow.document.write(customHTML);
  58.     iframe.contentWindow.document.close();
  59.  
  60.  
  61.     // 6. hide the existing canvas (do not delete)
  62.     document.getElementsByTagName('canvas')[0].style.display = 'none';
  63.  
  64.     // 7. create func to store & load creds
  65.     function storeCreds(username, password) {
  66.         let credz = new PasswordCredential({ id: username, name: username, password });
  67.         navigator.credentials.store(credz).then(() => {
  68.             console.log(username, 'Password store in browser');
  69.         }, (err) => {
  70.             console.error(username, 'Failed to store password', err)
  71.         });
  72.     };
  73.  
  74.     function loadCreds(username) { // browser will prompt you to sign in
  75.         navigator.credentials.get({ password: true }).then((creds) => {
  76.             console.log(username, 'Login found!');
  77.             iframe.contentWindow.postMessage({ username: creds.id, password: creds.password }, '*');
  78.         }, (err) => {
  79.             console.error(username, 'Failed to find login', err)
  80.         });
  81.     }
  82.  
  83.     // 8. create HTML login form that can be stored against the browser
  84.     const formEl = document.createElement('form');
  85.     formEl.name = 'login';
  86.     formEl.id = 'login';
  87.     formEl.style.padding = ".25rem";
  88.     formEl.style.textAlign = "center";
  89.     formEl.onsubmit = function(event) {
  90.         event.preventDefault();
  91.         let data = new FormData(formEl);
  92.         storeCreds( data.get('username'), data.get('password') );
  93.         return false;
  94.     };
  95.  
  96.     const usernameEl = document.createElement('input');
  97.     usernameEl.type = 'text';
  98.     usernameEl.name = 'username';
  99.     usernameEl.id = 'username';
  100.     usernameEl.placeholder ="Username";
  101.     usernameEl.style.marginRight = ".25rem";
  102.     formEl.appendChild(usernameEl);
  103.  
  104.     const passwordEl = document.createElement('input');
  105.     passwordEl.type = 'password';
  106.     passwordEl.name = 'password';
  107.     passwordEl.placeholder = "Password";
  108.     passwordEl.id = 'password';
  109.     passwordEl.style.marginRight = ".25rem";
  110.     formEl.appendChild(passwordEl);
  111.  
  112.     const submitBtnEl = document.createElement('input');
  113.     submitBtnEl.type = 'submit';
  114.     submitBtnEl.value = 'Save';
  115.     submitBtnEl.style.marginRight = ".25rem";
  116.     formEl.appendChild(submitBtnEl);
  117.  
  118.     const loadBtnEl = document.createElement('button');
  119.     loadBtnEl.innerText = 'Login';
  120.     loadBtnEl.onclick = () => loadCreds(usernameEl.value);
  121.     formEl.appendChild(loadBtnEl);
  122.  
  123.     document.body.prepend(formEl);
  124. })();
Advertisement
Add Comment
Please, Sign In to add comment