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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gm-context

v0.2.1

Published

A html5 contextmenu library

Readme

GM_context

A JavaScript library to create native HTML5 contextmenu in the browser. This library is designed for userscripts.

Compatibility

It uses native HTML5 <menu> and <menuitem> to build the context menu, so:

  1. It only works on latest Firefox.
  2. It doesn't replace the original context menu but extends it.

Usage

GM_context.add({
	context: ["image"],
	items: [{
		type: "submenu",
		label: "Reverse image search",
		items: [{
			label: "TinEye",
			onclick(e) {
				// ...
			}
		}, {
			type: "separator"
		}, {
			label: "Google",
			onclick(e) {
				// ...
			}
		}]
	}]
});

Demo

API reference

GM_context.add(menu: object)

Add a menu. The menu object contains following properties:

  • context: array of string. A list of valid context type that the context menu should apply to. Possible values are:

    • page: when there is no other context type matched.
    • image: match images.
    • link: match links.
    • editable: match editable target.
    • selection: when part of the page is selected.

    If this property is missing, the menu is globally applied.

  • items: array of object. A list of items. See Define a menu item.

  • oncontext: function. An event handler to handle contextmenu event, which would be called after context property is matched. The function may return false to not show the menu.

GM_context.remove(menu: object)

Remove the menu.

GM_context.update(item: object, changes: object)

Update the property of an item. If changes object contains items, it would replace all sub-items with it.

const myCheckbox = {
	type: "checkbox",
	label: "A checkbox"
};
GM_context.add({items: [myCheckbox]});

function toggleCheckbox() {
	GM_context.update(myCheckbox, {
		checked: !myCheckbox.checked
	});
}

GM_context.addItem(parent: object, item: object, position: number)

Add a sub-item to parent.

  • parent: Must be submenu, radiogroup, or the menu itself.
  • item: The item to add. See Define a menu item.
  • position: Where the item should insert to. Negative value is allowed. Default to parent.items.length.

GM_context.removeItem(parent: object, item: object)

Remove a sub-item from parent.

  • parent: Must be submenu, radiogroup, or the menu itself.
  • item: The item to remove.

Define a menu item

An item may have following properties:

  • checked: boolean. Only available to checkbox and radiogroup's items.

  • disabled: boolean. To disable an item.

  • icon: string. Image URL, used to provide a picture to represent the command.

  • items: array of object. Define sub-items. Only available to submenu and radiogroup type. A submenu may contain any type of the items, but the items of radiogroup can only define label, checked, and value properties.

  • label: string. The label of the item. The label may contain a special string %s which would be replaced with the value of window.getSelection().

  • onclick: function. Called when the item is clicked. It would recieve a contextmenu event not a click event. Also, checkbox type items would recieve a boolean to indicate if the item is checked.

  • onchange: function. Only available to radiogroup. The handler would recieve following params:

    • contextmenu event.
    • The value of the item currently choosed.
  • type: string. Define different type of menuitem. Available values are:

    • command: A normal menuitem. (default)
    • submenu: A submenu.
    • separator: A separator.
    • checkbox: An item which can be checked/unchecked.
    • radiogroup: A group of checkbox. When an item is checked, the others are unchecked. It is suggested to separate radiogroup from other items, or display it in a submenu.
  • value: string. Only available to radiogroup's items. The value is passed to onchange handler as the second parameter.

Changelog

  • 0.2.1 (Sep 21, 2017)

    • Fix empty container issue.
  • 0.2.0 (Sep 21, 2017)

    • Add test.
    • Add oncontext handler.
    • Add .addItem, .removeItem, update.
  • 0.1.0 (Sep 8, 2017)

    • First release.