// ==UserScript==
// @name 自动阅读器
// @namespace http://tampermonkey.net/
// @version 0.1
// @description pc 端自动阅读器,实现不同速度,在阅读中解放双手,页面自动滚动
// @author windymiao
// @match https://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @grant none
// @license MIT
// @downloadURL https://update.greasyfork.icu/scripts/455685/%E8%87%AA%E5%8A%A8%E9%98%85%E8%AF%BB%E5%99%A8.user.js
// @updateURL https://update.greasyfork.icu/scripts/455685/%E8%87%AA%E5%8A%A8%E9%98%85%E8%AF%BB%E5%99%A8.meta.js
// ==/UserScript==
(function() {
'use strict';
var button = `
阅读设置
`
var content = ``
var styleStr = ``
console.log('aaa');
$('body').append(button);
$('body').append(content);
$('head').append(styleStr);
var interval; // 定时器
var v; // 阅读速度
$('.start').on('click', function () {
start();
})
$('.stop').on('click', function () {
stop();
})
/**
* 开始自动阅读
* */
function start() {
if (interval) {
clearInterval(interval);
}
var startPos = $(window).scrollTop();
var top = 0;
v = parseFloat($('input[name="step"]:checked').val());
interval = setInterval(function () {
top = startPos += v
window.scrollTo({
left: 0, // x坐标
top: top, // y 坐标
behavior: 'smooth' // 可选值:smooth、instant、auto
})
}, 50)
}
/**
* 停止自动阅读
*/
function stop() {
if (interval) {
clearInterval(interval);
interval = null;
}
}
/**
* 改变阅读速度
*/
$('input:radio[name="step"]').change(function (event) {
if (interval) {
start();
}
})
/**
* 监听鼠标滑动事件
*/
$(window).on('mousewheel', function (event) {
console.log(event);
stop();
}, function () {
if (interval) {
start();
}
});
$('.toggle').click(function (event) {
$(this).fadeOut();
$('#auto-reading').addClass('active');
})
$('.hidden').click(function () {
hiddenSetting();
})
function hiddenSetting(){
setTimeout(() => {
$('.toggle').fadeIn();
}, 500);
$('#auto-reading').removeClass('active');
}
$(window).scroll(function(){
if ($(window).scrollTop() + $(window).height() + 5 >= $(document).height()) {
console.log('bottom');
clearInterval(interval);
interval = null;
}
});
})();