npmjs

npm下载量查看

Ekde 2019/11/22. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         npmjs
// @description  npm下载量查看
// @namespace    npm_script
// @version      1.0
// @author       vizo
// @require      https://cdn.jsdelivr.net/npm/[email protected]/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()
})