Scroll Up

Tool to let you scroll to the top/bottom of the page

  1. // ==UserScript==
  2. // @name Scroll Up
  3. // @version 1.20
  4. // @description Tool to let you scroll to the top/bottom of the page
  5. // @author A Meaty Alt
  6. // @exclude https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=21
  7. // @include /fairview.deadfrontier.com/
  8. // @exclude https://fairview.deadfrontier.com/onlinezombiemmo/ExternalLoginReg.php
  9. // @exclude http://chat.deadfrontier.com
  10. // @exclude https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=21&webplayer=1
  11. // @grant none
  12. // @namespace
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. var scrollerUp = document.createElement("img");
  18. scrollerUp.src = "https://puu.sh/xluRH/c8dd354a59.png";
  19. scrollerUp.id = "scrollerUp";
  20. scrollerUp.style.opacity = 0.3;
  21. scrollerUp.style.position = "fixed";
  22. scrollerUp.style.zIndex = 99;
  23. scrollerUp.style.cursor = "pointer";
  24. scrollerUp.style.bottom = "30px";
  25. scrollerUp.style.right = "10px";
  26. scrollerUp.height = 80;
  27. scrollerUp.width = 80;
  28. var scrollerDown = document.createElement("img");
  29. scrollerDown.src = "https://puu.sh/xsiqh/ed54ae27ab.png";
  30. scrollerDown.id = "scrollerDown";
  31. scrollerDown.style.opacity = 0.3;
  32. scrollerDown.style.position = "fixed";
  33. scrollerDown.style.zIndex = 99;
  34. scrollerDown.style.cursor = "pointer";
  35. scrollerDown.style.bottom = "30px";
  36. scrollerDown.style.right = "90px";
  37. scrollerDown.height = 80;
  38. scrollerDown.width = 80;
  39. function defineOnClickEvent(){
  40. $(scrollerUp).click(function() {
  41. $("html, body").animate({ scrollTop: 0 }, "slow");
  42. return false;
  43. });
  44. $(scrollerDown).click(function() {
  45. var bottom = $(document).height() - $(window).height();
  46. $("html, body").animate({ scrollTop: bottom }, "slow");
  47. return false;
  48. });
  49. }
  50. function defineOnScrollEvent(){
  51. $(document).scroll(function() {
  52. if($(window).scrollTop() === 0) {
  53. $(scrollerUp).css("opacity", 0.3);
  54. }
  55. else
  56. $(scrollerUp).css("opacity", 1);
  57. var bottom = $(document).height() - $(window).height();
  58. if($(window).scrollTop() === bottom){
  59. $(scrollerDown).css("opacity", 0.3);
  60. }
  61. else
  62. $(scrollerDown).css("opacity", 1);
  63. });
  64. }
  65. defineOnScrollEvent();
  66. defineOnClickEvent();
  67. $("body").append(scrollerUp);
  68. $("body").append(scrollerDown);
  69. })();