您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds infinite scroll to HackerNews
当前为
- // ==UserScript==
- // @description Adds infinite scroll to HackerNews
- // @name Hacker News Infinite Scroll
- // @namespace Violentmonkey Scripts
- // @match https://news.ycombinator.com/
- // @version 1.0.0
- // @grant none
- // ==/UserScript==
- const xhr = new XMLHttpRequest();
- const regex = new RegExp(/<center>.*(<table id="hnmain".*)<\/center>/gms);
- let count = 2;
- window.onscroll = function() {
- if ((window.innerHeight + Math.ceil(window.pageYOffset)) >= document.body.offsetHeight) {
- let testResponse;
- let parsed;
- xhr.open('GET', `https://news.ycombinator.com/news?p=${count}`);
- xhr.onload = function() {
- if (xhr.status === 200) {
- testResponse = xhr.responseText;
- parsed = regex.exec(testResponse);
- let newDiv = document.createElement('div');
- newDiv.innerHTML = parsed[1];
- let table = document.querySelector('table.itemlist');
- let tableMore = [...table.querySelectorAll('tr')].slice(-2)[0];
- [...newDiv.querySelector('tr#pagespace + tr tbody').querySelectorAll('tr')].slice(0, 90).forEach((newTr, idx) => {
- tableMore.parentNode.insertBefore(newTr, tableMore);
- })
- count++;
- }
- else {
- alert('Request failed. Returned status of ' + xhr.status);
- }
- };
- xhr.send();
- }
- };