GithubGoTop

scroll top

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name GithubGoTop
// @name:CN-zh_cn Github一键返回顶部
// @version 0.5
// @description scroll top
// @author gaojr
// @namespace https://github.com/gaojr/scripts-styles
// @license MIT
// @match https://*github.com/*
// @grant none
// @connect github.com
// @icon https://github.githubassets.com/pinned-octocat.svg
// ==/UserScript==

(function () {
  var body = document.querySelector('body');
  var goTop = document.createElement('div');
  var imgBox = document.createElement('img');
  goTop.style.position = 'fixed';
  goTop.style.right = '0%';
  goTop.style.bottom = '0%';
  goTop.style.cursor = 'pointer';
  imgBox.src =
    'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHhtbDpzcGFjZT0icHJlc2VydmUiIHZpZXdCb3g9IjAgMCAxMDAgMTAwIiB5PSIwIiB4PSIwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGlkPSJMYXllcl8xIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSI0OHB4IiBoZWlnaHQ9IjQ4cHgiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBzdHlsZT0id2lkdGg6MTAwJTtoZWlnaHQ6MTAwJTtiYWNrZ3JvdW5kLXNpemU6aW5pdGlhbDtiYWNrZ3JvdW5kLXJlcGVhdC15Om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aD4KPG1ldGFkYXRhIHhtbG5zOmQ9Imh0dHBzOi8vbG9hZGluZy5pby9zdG9jay8iIHN0eWxlPSJhbmltYXRpb24tcGxheS1zdGF0ZTpwYXVzZWQiID48ZDpuYW1lIHN0eWxlPSJhbmltYXRpb24tcGxheS1zdGF0ZTpwYXVzZWQiID51cDwvZDpuYW1lPgoKCjxkOnRhZ3Mgc3R5bGU9ImFuaW1hdGlvbi1wbGF5LXN0YXRlOnBhdXNlZCIgPm5vcnRoLHVwbG9hZCx0b3AsZGlyZWN0aW9uLHdheSxjaXJjbGUsdXAsYXJyb3c8L2Q6dGFncz4KCgo8ZDpsaWNlbnNlIHN0eWxlPSJhbmltYXRpb24tcGxheS1zdGF0ZTpwYXVzZWQiID5ieTwvZDpsaWNlbnNlPgoKCjxkOnNsdWcgc3R5bGU9ImFuaW1hdGlvbi1wbGF5LXN0YXRlOnBhdXNlZCIgPmhhOWxqejwvZDpzbHVnPjwvbWV0YWRhdGE+PC9nPjwhLS0gZ2VuZXJhdGVkIGJ5IGh0dHBzOi8vbG9hZGluZy5pby8gLS0+PC9zdmc+';
  imgBox.style.height = '48px';
  imgBox.style.width = '48px';
  goTop.appendChild(imgBox);
  body.appendChild(goTop);
  goTop.onclick = function () {
    document.body.scrollTop = document.documentElement.scrollTop = 0;
  };
  // theme mode
  var html = document.querySelector('html');
  html.onchange = function () {
    var github_mode = html.getAttribute('data-color-mode');
    var system_dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
    imgBox.style.filter = "light" === github_mode ? "" : "dark" === github_mode || system_dark ? "invert(100%)" : "";
  };
  window.matchMedia && (window.matchMedia('(prefers-color-scheme: dark)').onchange = html.onchange);
  html.onchange();
})();