Wazeopedia Enhancements

Fixes anchor scrolling on wazeopedia due to having a fixed height header

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Wazeopedia Enhancements
// @namespace    https://greasyfork.org/users/30701-justins83-waze
// @version      2017.11.17.01
// @description  Fixes anchor scrolling on wazeopedia due to having a fixed height header
// @author       JustinS83
// @include      https://wazeopedia.waze.com*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function bootstrap(tries) {
        tries = tries || 1;

        if ($) {
            init();
        } else if (tries < 1000) {
            setTimeout(function () {bootstrap(tries++);}, 200);
        }
    }

    bootstrap();

    function init(){
        $('a[href*=#]:not([href=#])').click(function() {
            if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
                var target = $(this.hash);
                target = target.length ? target : $('[name="' + this.hash.slice(1) +'"]');
                if (target.length) {
                    $('html,body').animate({
                        scrollTop: target.offset().top - 60 //offsets for fixed header
                    }, 250);
                    //return false;
                }
            }
        });
        $(window).load(function(){setTimeout(function(){
        //Executed on page load with URL containing an anchor tag.
        if($(location.href.split("#")[1])) {
            //debugger;
            var target = $('#'+location.href.split("#")[1]);
            if (target.length) {
                $('html,body').animate({
                    scrollTop: target.offset().top - 60 //offset height of header here too.
                }, 250);
                return false;
            }
        }},25);});
    }
})();