// ==UserScript== // @name 简洁版阮一峰周报 // @namespace https://github.com/AliubYiero/TamperMonkeyScripts // @version 1.0.0 // @description 显示简洁版阮一峰周报, 点击标题可以展开内容 // @author Yiero // @license GPL-3 // @match https://www.ruanyifeng.com/blog/* // @require https://scriptcat.org/lib/513/2.0.0/ElementGetter.js // @grant GM_addStyle // ==/UserScript== (async () => { GM_addStyle(` p.content:not(:has(a)).hide {display: none;} h2.title.hide {color: #a3a3a3;} h2.title.hide::after { content: 'hide'; font-size: 50%; border-radius: 10px; margin: 0 0 10px 10px; background-color: #a3a3a36b; padding: 5px; color: #fff; } `) await elmGetter.get('#main-content > h2'); let index = 0; document.querySelectorAll('#main-content > h2, #main-content > p').forEach(element => { if (element.tagName === 'H2') { index++; element.classList.add('title', 'hide') } else { element.classList.add('content', 'hide') } element.dataset.index = index }) document.querySelector('#main-content').addEventListener('click', (e) => { e.preventDefault() if (!e.target.classList.contains('title')) { return; } document.querySelectorAll(`[data-index="${e.target.dataset.index}"]`).forEach(ele => { ele.classList.toggle('hide') }) }) })()