Tampermonkey autologin : getElementById

Posted under » JavaScript on 5 December 2010

One of the easiest method to practice Javascript is to write a tampermonkey or greasemonkey script.

A simple autologin script for tampermonkey

// ==UserScript==
// @name         auto login to drupalsite
// @namespace    anoneh
// @version      2026-08-05
// @description  tired of login
// @author       Hanafi
// @match        http://bb.les.com/index.php?sid=*
// @match        http://bb.les.com/index.php*
// @match        http://bb.les.com*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ad-ls.com
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
var name = "root"
var pass = "4444666666"
document.getElementById('input_username').value = name
document.getElementById('input_password').value = pass
})();

You will notice the use strict thingie. It is there for a reason. Use it and don't get put off by it.

However, not all forms has id but have name only. In this case.

var zTextFields = document.getElementsByTagName("input");
for (var i=0; i < zTextFields.length; i++) {
  var thefield;
  thefield=zTextFields[i].name;
  if (!thefield) thefield=zTextFields[i].id;
  // Set up your auto-fill values here
  if (thefield == "username") zTextFields[i].value="bradpitt";
  if (thefield == "password") zTextFields[i].value="jolie";
//   alert("field:" + thefield + " value: " + zTextFields[i].value);
}

web security linux ubuntu Raspberry   git   javascript python django Laravel drupal php apache mysql  MongoDB AWS data  ML AI