{"id":13681783,"url":"https://github.com/kevinashworth/make-bookmarklet","last_synced_at":"2026-01-26T05:06:22.217Z","repository":{"id":37087683,"uuid":"283360616","full_name":"kevinashworth/make-bookmarklet","owner":"kevinashworth","description":"Using node, make a bookmarklet from your JavaScript file.","archived":false,"fork":false,"pushed_at":"2023-01-10T06:35:41.000Z","size":291,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T07:03:18.275Z","etag":null,"topics":["bookmarklets","javascript","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinashworth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-29T00:45:46.000Z","updated_at":"2025-01-10T15:52:33.000Z","dependencies_parsed_at":"2023-02-08T17:31:55.263Z","dependency_job_id":null,"html_url":"https://github.com/kevinashworth/make-bookmarklet","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinashworth%2Fmake-bookmarklet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinashworth%2Fmake-bookmarklet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinashworth%2Fmake-bookmarklet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinashworth%2Fmake-bookmarklet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinashworth","download_url":"https://codeload.github.com/kevinashworth/make-bookmarklet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248565179,"owners_count":21125435,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bookmarklets","javascript","nodejs"],"created_at":"2024-08-02T13:01:35.812Z","updated_at":"2026-01-26T05:06:22.211Z","avatar_url":"https://github.com/kevinashworth.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# make-bookmarklet\n\n## Table of Contents\n* [Use](#use)\n* [Options](#options)\n* [Unmake / Reversal](#unmake--reversal)\n* [Install](#install)\n\n## Use\n\nTo run `make-bookmarklet`, the recommended approach is via `npx` (no install required): `npx make-bookmarklet inputfile.js`. Alternatively you can install globally with `npm install -g make-bookmarklet` and run `make-bookmarklet inputfile.js`, or run locally for development: `node src/make-bookmarklet inputfile.js`. See the **Install** section at the end of this README for installation details and links to development notes.\n\n```bash\nnode src/make-bookmarklet inputfile.js\n```\n\nPiping and stdout examples:\n\n- Pipe an input script into the CLI: `cat script.js | npx make-bookmarklet`\n- Write output to a file using shell redirection: `npx make-bookmarklet inputfile.js \u003e out.txt`\n- Disable clipboard copying when scripting: `npx make-bookmarklet inputfile.js --no-clipboard \u003e out.txt`\n\nThis creates a bookmarklet out of the JavaScript in `inputfile.js`. It outputs the new bookmarklet to the command line and also copies the new bookmarklet to the clipboard.\n\nFor some ideas on what goes into an input file, see the [examples](examples) folder or see below. I often use an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE), but you can see [the Shortwave folder](examples/shortwave) for a non-IIFE example. Typically I test out the code by pasting it into my browser console. Once it works to my liking there, I convert it to a bookmarklet.\n\n### A complete, simple example\n\nSo, given `inputfile.js` in the top directory of this repo\n```javascript\nh = window.location.href;\ni = h.indexOf('imdb.com');\np = h.indexOf('https://pro.imdb.com');\nt = h.indexOf('title');\nc = h.indexOf('combined');\nf = h.indexOf('fullcredits');\nr = h.indexOf('reference');\nbadword = Math.max(c, f, r);\n\nif (i === -1) {\n  window.location = 'https://pro.imdb.com/name/nm2825198/'\n}\nelse if (p === 0) {\n  window.location = h.replace('https://pro', 'https://www')\n}\nelse if (p === -1) {\n  if ((t \u003e 1) \u0026\u0026 (badword \u003e 1)) {\n    h = h.substring(0, badword)\n  }\n  window.location = h.replace(/https:\\/\\/[a-z]+/, 'https://pro');\n};\n```\n\nthen, running `node src/make-bookmarklet inputfile.js` yields:\n```\njavascript:var%20h=window.location.href;%20const%20i=h.indexOf('imdb.com');%20const%20p=h.indexOf('https://pro.imdb.com');%20const%20t=h.indexOf('title');%20const%20c=h.indexOf('combined');%20const%20f=h.indexOf('fullcredits');%20const%20r=h.indexOf('reference');%20const%20badword=Math.max(c,%20f,%20r);%20if%20(i===-1)%7Bwindow.location='https://pro.imdb.com/name/nm2825198/';%7Delse%20if%20(p===0)%7Bwindow.location=h.replace('https://pro',%20'https://www');%7Delse%20if%20(p===-1)%7Bif%20((t%3E1)%20\u0026\u0026%20(badword%3E1))%7Bh=h.substring(0,%20badword);%7Dwindow.location=h.replace(/https:%5C/%5C/%5Ba-z%5D+/,%20'https://pro');%20%7D\n```\n\n## Options\n\nTo keep your bookmarklet a little more readable, use the defaults. But to make more-compact or more-secure bookmarklets, try these options.\n\n### **-a** Agressively remove code\n\nJavaScript engines are very forgiving. So it can be safe to remove some JavaScript aggressively, which will mean relying on JavaScript engines to figure it out correctly, despite not following best coding practices. To remove a little more code before converting your script to a bookmarklet, just use the `--aggressive` (or `-a`) flag:\n\n```bash\nnode src/make-bookmarklet inputfile.js --aggressive\n```\n\nThe removals here go against best coding practices, but here’s an opinion: it will probably not matter to your bookmarklet. So this is your warning — *Not declaring variables will pollute the global scope. The implied use of `window` may cause rare problems. Perhaps your code truly relies on `===` not `==`. Gasp. Take your chances!*\n\n### **-c** Use encodeURIComponent\n\nBy default, we encode the reduced script using [`encodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI), but if you wish to use [`encodeURIComponent`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) instead, use the `--component` (or `-c`) flag:\n\n```bash\nnode src/make-bookmarklet.js -c inputfile.js\n```\n\n### **-d** Debug Mode (Verbose Output)\n\nTo see more of the make process printed to the console, use the `--debug` (or `-d`) flag:\n\n```bash\nnode src/make-bookmarklet.js inputfile.js -d\n```\n\n\n### **-h** Help\n\nTo get help for these programs, and to see more examples, run:\n\n```bash\nnode src/make-bookmarklet.js --help\n```\n\n\nPlease note that any `options` can go before or after `filename`.\n\n## Unmake / Reversal\n\nTo convert a bookmarklet back into more-readable code, run the `unmake` version:\n\n```bash\nnode src/unmake-bookmarklet bookmarklet.js\n```\n\nPlease note, this is not a true reversal or re-creation of any JavaScript that went in to creating a bookmarklet, but it does convert a hard-to-read bookmarklet into [`prettier`](https://prettier.io) code.\n\n## Install\n\n**Requires Node.js 22 or newer.**\n\nQuick options for end users:\n\n- Run via `npx` without installing: `npx make-bookmarklet inputfile.js` (recommended).\n- Install globally: `npm install -g make-bookmarklet` then run `make-bookmarklet inputfile.js`.\n- For local use from source: clone the repo, run `npm i`, and run `node src/make-bookmarklet inputfile.js`.\n\n### For contributors\n\nIf you're contributing, see DEVELOPMENT.md for setup, testing, linting, and release notes. Please run `npm test` and `npm run lint` locally and add tests for public-facing changes before opening a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinashworth%2Fmake-bookmarklet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinashworth%2Fmake-bookmarklet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinashworth%2Fmake-bookmarklet/lists"}