Greasy Fork is available in English.

npmjs

npm下载量查看

// ==UserScript==
// @name         npmjs
// @description  npm下载量查看
// @namespace    npm_script
// @version      1.0
// @author       vizo
// @require      https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js
// @include      *://*npmjs.com/search*
// @run-at       document-end
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @noframes

// @grant        GM_getResourceText
// @grant        GM_xmlhttpRequest
// @connect      *

// ==/UserScript==

'use strict'

GM_addStyle(`
  .spr7s {
    color: #f00;
    font-size: 12px;
    font-weight: normal;
    margin-left: 10px;
    font-family: Arial;
    font-style: italic;
  }
`)

$(function () {
  
  function initScript() {
    let observer = new MutationObserver((mutations, observer) => {
      eachItem()
    })
    observer.observe(document.querySelector('.pt2-ns'), {
      childList: true,   //子节点的变动
      attributes: false,  //属性的变动
      characterData: true,  //节点内容或节点文本的变动
      subtree: false,   //是否将该观察器应用于该节点的所有后代节点
    })
    eachItem()
  }
  
  function reqItemDetail(url, domTit) {
    GM_xmlhttpRequest({
      url,
      method: 'get',
      onload: function(xhr) {
        try {
          let text = xhr.response
          let downNum = text.replace(/[\n\r\f]/g, '').replace(/.+?pb1\">([\d\,]+)\<\/p>.+/g, '$1')
          domTit.append(`<span class="spr7s">${downNum}</span>`)
        } catch (e) {}
      },
    })
  }
  
  // 遍历item
  function eachItem() {
    $('.pt2-ns .pl1-ns').each(function() {
      let tis = $(this)
      let url = tis.find('.flex-row a').attr('href')
      let h3 = tis.find('.flex-row a h3.fw6')
      reqItemDetail(url, h3)
    })
  }
  
  initScript()
})