To Top

Web to Top & Bottom

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         To Top
// @namespace
// @version      1.5
// @description  Web to Top & Bottom
// @author       MZ
// @match        *://*/*
// @namespace MZ
// ==/UserScript==

(function() {
  //add css
  var css = `
      #buttonContainer {
          position: fixed;
          right: 10px;
          top: 50%;
          transform: translateY(-50%);
          z-index: 99;
          display: flex;
          flex-direction: column;
          gap: 10px;
      }

      #topBtn, #botBtn{
          font-size: 18px;
          border: none;
          outline: none;
          background-color: #000000;
          color: white;
          cursor: pointer;
          padding: 10px;
          border-radius: 4px;
      }`;

  var node = document.createElement("style");
  node.type = "text/css";
  node.appendChild(document.createTextNode(css));
  var heads = document.getElementsByTagName("html");
  if (heads.length > 0) {
      heads[0].appendChild(node);
  } else {
      document.documentElement.appendChild(node);
  }


  //add button
  var div = document.createElement("div");
  div.id = "buttonContainer";

  var gotopbtn = document.createElement("input");
  gotopbtn.type = "button";
  gotopbtn.id = "topBtn";
  gotopbtn.value = "↑";
  gotopbtn.style.visibility = "hidden"
  div.appendChild(gotopbtn);

  var gobottombtn = document.createElement("input");
  gobottombtn.type = "button";
  gobottombtn.id = "botBtn";
  gobottombtn.value = "↓";
  div.appendChild(gobottombtn);

  document.getElementsByTagName("body")[0].appendChild(div);


  //button function
  gotopbtn.onclick = function () { window.scrollTo({ top: 0, behavior: 'smooth' }) }

  gobottombtn.onclick = function () { window.scrollTo({ top: document.documentElement.scrollHeight , behavior: 'smooth' }) }



  //button auto hide
  window.onscroll = function () { scrollFunction() };

  function scrollFunction() {
    if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
      document.getElementById("topBtn").style.visibility = "visible";
    } else {
      document.getElementById("topBtn").style.visibility = "hidden";
    }


    if (document.documentElement.scrollTop < document.documentElement.scrollHeight - window.screen.availHeight) {
      document.getElementById("botBtn").style.visibility = "visible";
    } else {
      document.getElementById("botBtn").style.visibility = "hidden";
    }
  }


})();