[SNOLAB] NPM Typescript Flag

Show "Dt" and "Ts" Icon on npm package search result.

Verze ze dne 11. 11. 2023. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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));