Giter VIP home page Giter VIP logo

bookmarklet's Introduction

Bookmarklet: sane development, familiar format

Build Status code style: prettier

Bookmarklet is a nodejs module for compiling bookmarklets in server-side code and directly from the shell. You can run it on any JavaScript file—it will minify it using uglify-js, wrap it in a self executing function, and return an escaped bookmarklet.

More so, it supports a metadata block—modeled after the greasemonkey userscript metadata block—to specify metadata, external stylesheets and script includes, which can look like this:

// ==Bookmarklet==
// @name LoveGames
// @author Old Gregg
// @style !loadOnce https://mrcoles.com/media/css/silly.css
// @script https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/Bookmarklet==

Most notably, you can specify any external scripts that you’d like your bookmarklet to include via the @script rule, which can be repeated as many times as you’d like.

NOTE: currently with script includes you have to handle noConflict scenarios yourself, e.g., you might want to start off a script with var $ = jQuery.noConflict(true).

In addition, any css files included with @style will be injected.

By default, every time the bookmark is hit, it will add the script and style tags again. You customize each one per line by adding a !loadOnce declaration between the @style or @script param and the path for the asset. See the example above.

As of v1.0.0, this now uses Babel with the present "env" to make the code backwards compatible before minifying it.

This project is open to suggestions & pull requests.

Also, if you’re just looking for a quick way to throw together a bookmarklet, try my browser-based bookmarklet creator.

Installation

The dependency can be found on NPM as “bookmarklet”. You can install it with:

npm install bookmarklet

Usage

You can easily see usage by running bookmarklet -h:

> bookmarklet -h
Bookmarklet v0.0.1 usage: bookmarklet [-d | --demo] source [destination]

-d | --demo - output a demo HTML page for sharing the bookmarklet
source      - path to file to read from or `-` for stdin
destination - path to file to write to

The default output is the raw bookmarlet code. NEW add the --demo flag to output a test HTML page that includes the bookmarklet on it.

Testing

A very basic test script can be run via bash test/run.sh

bookmarklet's People

Contributors

didericis avatar mrcoles avatar nathanathan avatar richardfrost avatar ronnyo avatar rpavlik avatar timcharper avatar vzvu3k6k avatar ytilis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bookmarklet's Issues

-d option no longer documented in help (plus a typo)

The README in this repo shows that there's a -d option to make a demo page, which is neat. However, when running bookmarklet -h in the terminal, this isn't document. Also there's a spurious ' in the output, after "stdout".

Just found this tool and it looks really helpful, thanks :-).

Low contrast in generated demo page

The feature that generates a demo page is a real time-saver. However, the styling makes the button and the link have very low contrast. The contrast ratio between the white and cyan is just 1.63:1. Depending on screen, environment and visual acuity, it will be hard for some people to see.

The Web Content Accessibility Guidelines (level AA) recommend at least a 3:1 contrast ratio for meaningful graphical elements (i.e. to help people identify the button against its background) and 4.5:1 for text (for the button's label, and the link)—though if the text is considered large this drops to 3:1.

There are some examples of how to improve non-text contrast on W3C's site.

If you're interested, I'd be happy to submit a PR that addresses the contrast issues. Here are two different possibilities...

  1. Simply use a darker colour than the cyan both for the button's background and link text.
  2. Use a darker colour for the link text, keep the cyan for the button's background, but use a darker colour for the button's text and add border.

Further, if you try tabbing through the page, the focus indication is very slight too, because it is using the browser's default, and in some browsers this means it's the same light cyan colour, and quite thin, so is also hard to see. (You can use CSS outline-offset to create a border between the focus outline and the button/link, to make it easier to meet contrast requirements.)

Not working on Windows 10

When using this with any code (including running test/run.sh) I am getting the following in the output file:

javascript:(function()%7BNaN%7D)()

js-core dependency complains that it needs to be upgraded to js-core 3

When installing the bookmarklet module NPM warns us that the js-core < 3 has a number of issues and should not be used.

EDIT: Confirmed that this is an issue of babel-core and babel-preset-env. There seems to be an outstanding PR to upgrade to a newer version of babel. Possible fix for this?

ReferenceError: regeneratorRuntime is not defined SOLVED

I am posting for the next unfortunate one who is hoping to find a solution for the regeneratorRuntime issue.
I could be persuaded to submit a PR, but it appears the author has abandoned this project so there is no incentive there.

Here is what I did.

  1. cloned the project
  2. removed all babel dependencies from package.json and code.
  3. replaced "uglify-js" with "terser"
  4. Here is the function that you have to change.
    function minify(code) { return terser.minify(code).code; }

ta-dah. No more questionably useful babel transpilations.

'\w' gets transpiled to 'w'

Source:

console.log('\w');

Expected result:

console.log('\w');

Actual result:

console.log('w');

Thanks & greetings!

Demo page customization

Hi. Awesome job - I used to have to do all that work manually. I haven't been so excited to find a new package like this in months! :)

Have you considered making the demo page customizable? For the sake of simplicity, a key in package.json would be enough.
Being able to provide a name for the bookmarklet to show instead of 'Bookmarklet; would be a great start.
Pointing to a HTML page template would be even better.

I could help out with that.

No LICENSE file

Please can you add a LICENSE file to this project. package.json says it is has an MIT license - it would be good to add the text of that to the project to make it clear.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.