npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-tampermonkey-auto-meta

v0.1.9

Published

用于自动提取注释内容或GM_*函数到头部userscript注释块

Downloads

13

Readme

获取全局GM_*函数以及其他符合tampermonkey的注释并提取到头部注释UserScript中

入口头部注释 = 内部注释 = 其他函数注释> 初始化配置 > package.json

注意事项

1. window: 由于判断的比较简单,故而只提升window.close而不会提升window['close']、window?.close、window .close等,但会提升window?close,考虑到window.find提升和不提升并不影响实际功能,故而可能对此条内容不再优化,如后续对此优化提的比较多会进行优化。

2. name:zh-cn将视为name,不需要额外定义

3. 本插件基于rollup所使用的acorn完成代码解析实现元数据提升

Usage

  1. 单输入单输出
// rollup.config.js
import autoMeta from 'rollup-plugin-tampermonkey-auto-meta';

export default {
  input: 'src/main.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife'
  },

  plugins: [
    autoMeta({})
  ]
};

License

MIT

[0.1.9] 2023-02-04

  1. 默认关闭二维码
  2. 限制只会自动提升 window.close、window.focus、window.onurlchange

[0.1.8] 2022-10-10

修复获取最后一个块注释时少一个字符的bug

[0.1.7] 2022-10-03

  1. 修复0.1.6更新说明
  2. 修复fix-header在ts中的支持,以及tampermonkey在ts中丢失头部部分元数据的问题 见[0.1.6],编译到后面的时候头部元数据丢失,又因为rollup使用的acorn无法解析ts,导致走进死胡同无解, 故而自己写了一个用于获取头部注释的函数,可能会出现bug,如出现请及时邮件告知。

[0.1.6] 2022-10-03

  1. 重大更新,添加控制台输出支付宝赚钱红包码,1分也是爱,可配置[qr:false]关闭打印

  2. 为了解决rollup-plugin-cleanup的冲突问题,故将cleanup集成到本插件中,同时不再需要读取原始文件才能拿到头注释,故而不再有文件格式限制,需在对应的解析插件之后使用。

  3. 本插件的cleanup的功能基于rollup-plugin-cleanup实现,可使用与rollup-plugin-cleanup一样的配置

import autoMeta from "rollup-plugin-tampermonkey-auto-meta";
autoMeta(
  /** meta元数据默认配置,可被文件内的替换或合并 */ { name: '是的' },
  /** 本插件功能配置,可自行添加需要提取的元数据等 */ { array: 'include' },
  /** 本插件的cleanup配置,同rollup-plugin-cleanup */ {}
)
  1. metablock新增block,可将头部元数据的//修改成自定义。注意: 当使用/* /块注释作为生成结果时,可能会出现@match :///导致注释提前结束导致代码出错,建议使用/* /作为生成结果时,尽量避免@match中带有/
比如 start: '/*', block: ' *', end: '*/'时输出
/*
 *
 *
*/
5. 新增配置cleanup,用于开启/关闭cleanup功能, 默认开启,去除注释

6. 优化提取逻辑,支持全局提取块注释[ps:实现方式为以\n分割并单独提取@之后的内容,如果@之前有内容将被忽略,且同一行只会取一次@,如有多个请注意换行以便插件解析]

7. 添加typescript可使用栗子,可作为模板使用

8. 重要: 由于当前使用的是经过ts编译之后获得的代码,头部注释有多个时只会获取到第一个注释,请使用一个块注释[虽然是多行但是会被rollup当成一个]或尽量使用配置生成
此问题在ts中暂时无解[ps:使用rollup自带的acorn不支持直接解析ts],见栗子参考使用。
在使用js时会尝试获取原始文件经过acorn解析拿到代码开始之前的所有注释, 故js可在头部使用多种注释组合。

[0.1.5] - 2022-09-18

  1. 重构 支持单配置单输入多输出,多输入多输出, 多个配置多输入多输出功能

  2. 不在支持分割注释内容

  3. 不在支持从package.json里拿数据

  4. 不再提取include [参考6]

  5. 支持解析块注释, 只解析头部的块注释

  6. 新增配置可自行修改单元数据提取和多元数据提取,如需@include请添加配置include,请参考内附栗子

  7. 新增fix-header,仅会将头部注释复制一份并粘贴过去,如果使用删除注释插件,可使用此功能

  8. 新增metablock可将生成的// ==userscript==// ==/userscript改成自定义

  9. 使用rollup-plugin-cleanup时会导致自动提升头部功能缺失,只能提取入口文件注释[ps: 直接读取的原文件,故而不受影响,然而其他的是读取chunk.modules上的信息,已被clearup清除注释,故而无法生效@todo待优化]

[0.1.3] - 2022-09-13

修复npm run dev下roll watch异常的问题

单文件多window.key去重

调整顺序,入口文件内注释优先显示

调整顺序,单字段优先显示

完善demo

@todo 修改逻辑,使其支持自定义字段可进行扩展

[0.1.2] - 2022-09-08

修改import ==> require 使其能在node_modules使用

修正__dirname ==> process.cwd() 使其获取运行命令下的package.json

添加入口目录,用于减少头部分割展示时的分割注释内容

-src
--main.js
--utils
---index.js
-package.json
生成分割注释内容如下
// ========= src utils =========

添加注释回调函数,用于头部分割展示时的分割注释

添加ts

[0.1.0] - 2022-09-07

功能原型,待修复填充数据、使用说明以及例子