Bing TopScroll Blocker

防止Bing自动滚动到顶部.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Bing TopScroll Blocker
// @namespace    https://greasyfork.org/zh-CN/users/1327614-fakerjms
// @version      1.0.2
// @description  防止Bing自动滚动到顶部.
// @author       FakerJMS
// @match        http*://*.bing.com/*
// @icon         https://www.bing.com/sa/simg/favicon-trans-bg-blue-mg.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    //
    let fk_origin_scrollTo = window.scrollTo;
    //
    let fk_fake_scrollTo = function(x, y) {
        console.log('fake scrollTo!');
    };

    // 禁用"滚动到顶部"
    function disable_scrollToTop() {
        window.scrollTo = fk_fake_scrollTo;
    }

    // 使能"滚动到顶部"
    function enable_scrollToTop() {
        window.scrollTo = fk_origin_scrollTo;
    }

    // 监听"窗口获取焦点"事件, 使能"滚动到顶部"
    window.addEventListener('focus', () => {
        console.log('窗口获取焦点');
        enable_scrollToTop();
    });
    // 监听"窗口失去焦点"事件, 禁用"滚动到顶部"
    window.addEventListener('blur', () => {
        console.log('窗口失去焦点');
        disable_scrollToTop();
    });
    // 监听"鼠标进入窗口"事件, 使能"滚动到顶部"
    document.addEventListener('mouseenter', () => {
        console.log('鼠标进入文档区域');
        enable_scrollToTop();
    });
    // 监听"鼠标离开窗口"事件, 禁用"滚动到顶部"
    document.addEventListener('mouseleave', () => {
        console.log('鼠标离开文档区域');
        disable_scrollToTop();
    });
})();