BlueCat Address Manager Top Button

Add a "Go to Top" button in BlueCat Address Manager

  1. // ==UserScript==
  2. // @name BlueCat Address Manager Top Button
  3. // @namespace *
  4. // @description Add a "Go to Top" button in BlueCat Address Manager
  5. // @include */app*
  6. // @version 2
  7. // @author Marius Galm
  8. // @copyright 2018, Marius Galm
  9. // @license MIT
  10. // @grant none
  11. // @icon https://www.bluecatnetworks.com/wp-content/uploads/2018/03/cropped-bluecat-favicon-32x32.png
  12. // ==/UserScript==
  13.  
  14. if (document.readyState === "interactive" ) {
  15. addTopButton();
  16. }
  17.  
  18. function addTopButton() {
  19. var button = document.createElement("button");
  20. button.innerHTML="Top";
  21. button.id="topBtn";
  22. button.title="Go to top";
  23. var body = document.getElementsByTagName("body")[0];
  24. body.appendChild(button);
  25. button.addEventListener ("click", function() {
  26. document.body.scrollTop = 0; // For Safari
  27. document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
  28. });
  29. var btncss = '#topBtn {display: none; box-shadow: 1px 1px #888888; position: fixed; width: 60px; bottom: 20px; right: 30px; z-index: 99; border: none; outline: none; background-color: #8CB7D1; color: white; cursor: pointer; padding: 15px; border-radius: 10px; font-size: 18px; } #topBtn:hover { background-color: #555; }';
  30. var head = document.head || document.getElementsByTagName('head')[0];
  31. var style = document.createElement('style');
  32. style.type = 'text/css';
  33. if (style.styleSheet){
  34. style.styleSheet.cssText = btncss;
  35. } else {
  36. style.appendChild(document.createTextNode(btncss));
  37. }
  38. console.log("add new btncss stylings to head element")
  39. head.appendChild(style);
  40. // When the user scrolls down 20px from the top of the document, show the button
  41. window.onscroll = function() {scrollFunction()};
  42. }
  43.  
  44. function scrollFunction() {
  45. if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
  46. document.getElementById("topBtn").style.display = "block";
  47. } else {
  48. document.getElementById("topBtn").style.display = "none";
  49. }
  50. }