npmjs

npm下载量查看

Versione datata 22/11/2019. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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()
})