Background Network Requests Indicator

Shows an indicator at bottom right/left when there is one or more background network requests in progress.

Από την 05/06/2017. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Background Network Requests Indicator
// @namespace   BackgroundNetworkRequestsIndicator
// @description Shows an indicator at bottom right/left when there is one or more background network requests in progress.
// @version     1.0.1
// @author      jcunews
// @include     *://*/*
// @grant       none
// @run-at      document-start
// ==/UserScript==

(function() {
  var ele = document.createElement("SCRIPT");
  ele.text = "(" + (function() {

    var xhrCount = 0, xhrSend = XMLHttpRequest.prototype.send;
    var eleStyle = "\
display:block!important; opacity:1!important; visibility:visible!important; \
position:fixed!important; z-index:9999999999!important; left:auto!important; \
top:auto!important; right:0!important; bottom:0!important; float:none!important; \
margin:0!important; box-sizing:content-box!important; border:4px solid #bb0!important; \
border-radius:12px!important; padding:0!important; min-width:16px!important; \
background:#ff0!important; text-align:center!important; \
font:12px/16px sans-serif!important";
    var ele = document.createElement("DIV");
    ele.style.cssText = eleStyle;

    function checkCursor(ev) {
      if (ev.clientX >= Math.floor(innerWidth / 2)) {
        ele.style.cssText = eleStyle.replace(/left:auto/, "left:0").replace(/right:0/, "right:auto");
      } else ele.style.cssText = eleStyle;
    }

    ele.onclick = function(){
    ele.style.cssText = eleStyle.replace(/left:auto/, "left:0").replace(/right:0/, "right:auto");
    };
    function xhrDone() {
      if (--xhrCount < 0) xhrCount = 0;
      if (xhrCount) {
        ele.textContent = xhrCount;
      } else {
        removeEventListener("mousemove", checkCursor);
        document.body.removeChild(ele);
      }
    }

    XMLHttpRequest.prototype.send = function() {
      if (!this.indicator) {
        this.addEventListener("error", xhrDone);
        this.addEventListener("load", xhrDone);
        this.indicator = true;
      }
      ele.textContent = ++xhrCount;
      if (!ele.parentNode) {
        document.body.appendChild(ele);
        addEventListener("mousemove", checkCursor);
      }
      return xhrSend.apply(this, arguments);
    };

  }).toString() + ")()";
  document.head.appendChild(ele);
})();