[kesai]通用返回顶部

通用返回顶部

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         [kesai]通用返回顶部
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  通用返回顶部
// @author       lizeping
// @match        https://www.douban.com/*
// @match        https://movie.douban.com/*
// @match        https://sspai.com/*
// @match        https://www.youtube.com/*
// @match        https://www.baidu.com/*
// @match        https://www.google.com.hk/*
// @match        https://www.google.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function addCSS(url) {
        var link = window.document.createElement('link');
        link.rel = 'stylesheet';
        link.type = 'text/css';
        link.href = url+'?t='+new Date().getTime();
        document.getElementsByTagName("HEAD")[0].appendChild(link);
    }

    function addScript(url) {
        var link = window.document.createElement('script');
        link.type = 'text/javascript';
        link.src = url+'?t='+new Date().getTime();
        link.async = true;
        document.getElementsByTagName("HEAD")[0].appendChild(link);
    }


    if (typeof jQuery == 'undefined') {
        addScript("https://code.jquery.com/jquery-3.3.1.min.js");
    }
    addCSS("https://kesai.gitee.io/kesai_scripts/returnTop/share.css");

    window.onload = function() {
        var div = $('<div id="share"><a id="totop" title="返回顶部">返回顶部</a></div>');
        $("body").append(div);
        $("#totop").hide();

        $(window).scroll(function() {
            if ($(window).scrollTop() > 100) {
                $("#totop").fadeIn();
            } else {
                $("#totop").fadeOut();
            }
        });

        $("#totop").click(function() {
            $('body,html').animate({ scrollTop: 0 }, 500);
            return false;
        });
    }

})();