Greasy Fork is available in English.
使用w和s键进行平滑滚动翻页。
当前为
// ==UserScript==
// @name 平滑滚动翻页
// @namespace http://tampermonkey.net/
// @version 1.2
// @description 使用w和s键进行平滑滚动翻页。
// @author coccvo
// @match https://www.qidian.com/*
// @match https://tieba.baidu.com/*
// @match https://s.weibo.com/*
// @match https://weibo.com/*
// @match https://www.miyoushe.com/*
// @match https://www.zhihu.com/*
// @match https://www.bilibili.com/read/*
// @match https://m.ithome.com/*
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 定义一个函数来绑定按键事件监听器
function bindKeyListeners() {
// 获取视窗高度
let viewportHeight = window.innerHeight;
// 定义每次滚动的距离为视窗高度的0.9倍
let scrollDistance = viewportHeight * 0.9;
// 监听按键事件
document.addEventListener('keydown', function(event) {
if (event.key === 'w') {
// 按下w键向上滚动
window.scrollBy({
top: -scrollDistance,
left: 0,
behavior: 'smooth'
});
} else if (event.key === 's') {
// 按下s键向下滚动
window.scrollBy({
top: scrollDistance,
left: 0,
behavior: 'smooth'
});
}
});
}
// 页面加载完毕后执行
window.addEventListener('DOMContentLoaded', function() {
bindKeyListeners();
});
// 窗口获取焦点时重新绑定按键事件监听器
window.addEventListener('focus', function() {
bindKeyListeners();
});
})();