Tarball viewer

View content of tarballs without download them.

  1. // ==UserScript==
  2. // @name Tarball viewer
  3. // @namespace https://gera2ld.space/
  4. // @description View content of tarballs without download them.
  5. // @match *://www.npmjs.com/package/*
  6. // @version 0.2.0
  7. // @author Gerald <i@gera2ld.space>
  8. // @require https://cdn.jsdelivr.net/combine/npm/@violentmonkey/dom@2,npm/@violentmonkey/ui@0.7
  9. // @grant GM_openInTab
  10. // @grant GM_registerMenuCommand
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. async function main() {
  17. const matches = window.location.pathname.match(/^\/package\/(.*?)(?:\/v\/([a-z0-9.-]+))?$/);
  18. if (!matches) {
  19. VM.showToast('Package not found');
  20. return;
  21. }
  22. const [, pkgName, version] = matches;
  23. const name = [pkgName, version].filter(Boolean).join('@');
  24. const qs = new URLSearchParams({
  25. r: `npm:${name}`
  26. });
  27. GM_openInTab(`https://webfs.gera2ld.space/#${qs}`);
  28. }
  29. GM_registerMenuCommand('Explore tarball', main);
  30.  
  31. })();