ChronoTrigger_

avenoel toolkit

Nov 13th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        avenoel-toolkit
  3. // @namespace   avnt
  4. // @description toolbar for scroll to top, to bottom, and others later
  5. // @include     https://avenoel.org/*
  6. // @version     1.01
  7. // @grant       none
  8. // @require     https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js
  9. // ==/UserScript==
  10.  
  11. "use strict";
  12.  
  13. $(document).ready(function () {
  14.  
  15.   var avnt = {
  16.     addToolBar : function () {
  17.       if ($('#backtotop').length == 0) {
  18.         let gototop_l = "<li class=\'gototop\'><a href='#top'><span class='glyphicon glyphicon-arrow-up'></span></a></li>";
  19.         let gotobottom_l = "<li class=\'gotobottom\'><a href='#bottom'><span class='glyphicon glyphicon-arrow-down'></span></a></li>";
  20.         let gototop_sm = "<li class=\'gototop\'><a href='#top'><span class='glyphicon glyphicon-arrow-up'></span></a></li>";
  21.         let gotobottom_sm = "<li class=\'gotobottom\'><a href='#bottom'><span class='glyphicon glyphicon-arrow-down'></span></a></li>";
  22.  
  23.         $(".navbar-user li:first-of-type").after(gototop_l);
  24.         $(".navbar-user li:first-of-type").after(gotobottom_l);
  25.        
  26.         $(".bottombar li:first-of-type").after(gototop_sm);
  27.         $(".bottombar li:first-of-type").after(gotobottom_sm);
  28.  
  29.       }
  30.     },
  31.    
  32.     createEventListener : function () {
  33.       $(".avnt .gototop").on('click touchstart', function (e) {
  34.         e.stopPropagation();
  35.         document.body.scrollTop = document.documentElement.scrollTop = 0;
  36.       });
  37.       $(".avnt .gotobottom").on('click touchstart', function (e) {
  38.         e.stopPropagation();
  39.         window.scrollTo(0, document.body.scrollHeight);
  40.       });
  41.     },
  42.    
  43.     init : function() {
  44.       $("body").addClass("avnt");
  45.       var host = window.location.host;
  46.       switch(host) {
  47.         case "avenoel.org":
  48.         default:
  49.           this.addToolBar();
  50.           this.createEventListener();
  51.           break;
  52.       }
  53.     }
  54.   };
  55.  
  56.   avnt.init();
  57. });
Advertisement
Add Comment
Please, Sign In to add comment