daily pastebin goal
0%
SHARE
TWEET

The Opera onfocus, onblur bug demonstrator

a guest Dec 22nd, 2018 11 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name            The Opera onfocus, onblur bug demonstrator
  3. // @include         http://example.com/
  4.  
  5.  
  6. let focusCounter = 1;
  7. let blurCounter  = 1;
  8.  
  9. window.onfocus = () => {
  10.     logEntry(`<p style="color: #FFA400">FOCUS: ${blurCounter}</p>`);
  11.     focusCounter++;
  12. };
  13.  
  14. window.onblur  = () => {
  15.     logEntry(`<p style="color: #1049A9">BLUR: ${blurCounter}</p>`);
  16.     blurCounter++;
  17. };
  18.  
  19.  
  20. resetHTML();
  21. window.addEventListener("click", () => { logEntry("<hr>"); }, true);
  22.  
  23.  
  24.  
  25.  
  26. function logEntry(entry) {
  27.     document.querySelector("#log")
  28.             .insertAdjacentHTML("beforeend", entry);
  29. }
  30.  
  31.  
  32. function resetHTML() {
  33.     document.body.innerHTML = "";
  34.     document.querySelector("body")
  35.             .insertAdjacentHTML("afterbegin", `<div id="log"></div>`);
  36.     document.querySelector("body > div")
  37.             .insertAdjacentHTML("afterbegin", `<a href="http://example.com/">New window</a>`);
  38.            
  39.     document.querySelector("#log").addEventListener("click", resetHTML, false);
  40.    
  41.     focusCounter = 1;
  42.     blurCounter  = 1;
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top