您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Show "Dt" and "Ts" Icon on npm package search result.
当前为
// ==UserScript== // @name [SNOLAB] NPM Typescript Flag // @namespace https://userscript.snomiao.com/ // @version 0.1.0 // @description Show "Dt" and "Ts" Icon on npm package search result. // @author [email protected] // @match *://www.npmjs.com/search* // @match *://npmjs.com/search* // @grant none // @contributionURL https://snomiao.com/donate // @supportURL https://github.com/snomiao/userscript.js/issues // ==/UserScript== const observer = new IntersectionObserver((entries) => entries.forEach(async (entry) => { if (!entry.isIntersecting) return; const h3 = entry.target; if (h3.ariaChecked) return; //const rect = h3.getBoundingClientRect(); //const isVisible = 0 < rect.bottom && rect.top < window.innerHeight; // if(!isVisible) return; const pathname = h3.parentElement.pathname; const content = await ( await fetch(pathname, { cache: "force-cache" }) ).text(); const hasDt = content.match( '(?<="true">)<img.*?This package has TypeScript declarations provided by.*?/>' )?.[0] ?? ""; const hasTs = content.match( '(?<="true">)<img.*?This package contains built-in TypeScript declarations.*?/>' )?.[0] ?? ""; h3.innerHTML = h3.innerText + " / " + hasDt + hasTs; console.log({ pathname, hasDt, hasTs }); h3.ariaChecked = true; }) ); function $$(sel, el = document) { return [...el.querySelectorAll(sel)]; } $$("a>h3").forEach(async (h3) => observer.observe(h3));