Page percentage

Display page reading percentage on bottom right

  1. // ==UserScript==
  2. // @name Page percentage
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.3
  5. // @description Display page reading percentage on bottom right
  6. // @author You
  7. // @match *://*/*
  8. // @exclude *://*/*kibana*
  9. // @grant none
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13. // Your code here...
  14. function fn (){
  15. var p = document.getElementById('pgpercentage');
  16. p.innerText = (document.documentElement.scrollTop / (document.documentElement.scrollHeight - window.innerHeight) * 100).toFixed(2);
  17. p.style.visibility = 'visible';
  18. p.style.opacity = 1;
  19. window.clearTimeout(p);
  20. setTimeout(function(){
  21. p.style.visibility = 'hidden';
  22. p.style.opacity = 0;
  23. p.style.transition = 'visibility 1s, opacity 0.5s linear';
  24. }, 3000);
  25. };
  26. window.addEventListener("scroll", fn, false);
  27. var pp = document.createElement('div')
  28. pp.setAttribute('id', 'pgpercentage')
  29. pp.setAttribute('style', "position: fixed; z-index:1000; bottom: 0; right: 0;font-weight: bold;")
  30. document.getElementsByTagName('body')[0].appendChild(pp)
  31. })();