5

This is a TamperMonkey userscript. Why doesn't "HELLO" popup? I am running Google Chrome on Ubuntu.

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://*/*
// @match        https://*/*
// @grant        none
// ==/UserScript==

window.addEventListener("DOMContentLoaded", function(event) {
    alert("HELLO");
  });
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
Joshua Meyers
  • 619
  • 1
  • 8
  • 17

1 Answers1

10

Use this:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
        alert("Already Loaded");
    } else {
        document.addEventListener("DOMContentLoaded", function(event) {
            alert("Just Loaded");
        });
    }
})();

Borrowed from How to detect if DOMContentLoaded was fired.

Community
  • 1
  • 1
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153