npmjs

npm下载量查看

当前为 2019-11-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name npmjs
  3. // @description npm下载量查看
  4. // @namespace npm_script
  5. // @version 1.0
  6. // @author vizo
  7. // @require https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js
  8. // @include *://*npmjs.com/search*
  9. // @run-at document-end
  10. // @grant GM_addStyle
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @noframes
  14.  
  15. // @grant GM_getResourceText
  16. // @grant GM_xmlhttpRequest
  17. // @connect *
  18.  
  19. // ==/UserScript==
  20.  
  21. 'use strict'
  22.  
  23. GM_addStyle(`
  24. .spr7s {
  25. color: #f00;
  26. font-size: 12px;
  27. font-weight: normal;
  28. margin-left: 10px;
  29. font-family: Arial;
  30. font-style: italic;
  31. }
  32. `)
  33.  
  34. $(function () {
  35. function initScript() {
  36. let observer = new MutationObserver((mutations, observer) => {
  37. eachItem()
  38. })
  39. observer.observe(document.querySelector('.pt2-ns'), {
  40. childList: true, //子节点的变动
  41. attributes: false, //属性的变动
  42. characterData: true, //节点内容或节点文本的变动
  43. subtree: false, //是否将该观察器应用于该节点的所有后代节点
  44. })
  45. eachItem()
  46. }
  47. function reqItemDetail(url, domTit) {
  48. GM_xmlhttpRequest({
  49. url,
  50. method: 'get',
  51. onload: function(xhr) {
  52. try {
  53. let text = xhr.response
  54. let downNum = text.replace(/[\n\r\f]/g, '').replace(/.+?pb1\">([\d\,]+)\<\/p>.+/g, '$1')
  55. domTit.append(`<span class="spr7s">${downNum}</span>`)
  56. } catch (e) {}
  57. },
  58. })
  59. }
  60. // 遍历item
  61. function eachItem() {
  62. $('.pt2-ns .pl1-ns').each(function() {
  63. let tis = $(this)
  64. let url = tis.find('.flex-row a').attr('href')
  65. let h3 = tis.find('.flex-row a h3.fw6')
  66. reqItemDetail(url, h3)
  67. })
  68. }
  69. initScript()
  70. })