2017 © Pedro Peláez
 

library bookmarkletgen

PHP class to convert JS into valid bookmarklet links

image

ozh/bookmarkletgen

PHP class to convert JS into valid bookmarklet links

  • Sunday, June 18, 2017
  • by ozh
  • Repository
  • 2 Watchers
  • 10 Stars
  • 520 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 4 Versions
  • 17 % Grown

The README.md

Bookmarklet Gen Tests Codacy Badge

Convert (readable) Javascript code into bookmarklet links, (*1)

Requires PHP 7.2 - 8.1, (*2)

Features

  • removes comments
  • compresses code by removing extraneous spaces, but not within literal strings. Example: javascript function someName( param ) { alert( "this is a string" ) } will return: javascript function%20someName(param){alert("this%20is%20a%20string")}
  • encodes what needs to be encoded
  • wraps code into a self invoking function ready for bookmarking

This is basically a slightly enhanced PHP port of the excellent Bookmarklet Crunchinator: http://ted.mielczarek.org/code/mozilla/bookmarklet.html, (*3)

Installation

If you are using Composer, add this requirement to your composer.json file and run composer install:, (*4)

    {
        "require": {
            "ozh/bookmarkletgen": "1.2.0"
        }
    }

Or simply in the command line : composer install ozh/bookmarkletgen, (*5)

If you're not using composer, download the class file and include it manually., (*6)

Example

<?php
$javascript = <<<CODE
var link="http://google.com/"; // destination
window.location = link;
CODE;

require 'vendor/autoload.php'; // if you install using Composer
require 'path/to/Bookmarkletgen.php'; // otherwise

$book = new \Ozh\Bookmarkletgen\Bookmarkletgen;
$link = $book->crunch( $javascript );

printf( '<a href="%s">bookmarklet</a>', $link );

will print:, (*7)

<a href="javascript:(function()%7Bvar%20link%3D%22http%3A%2F%2Fgoogle.com%2F%22%3Bwindow.location%3Dlink%3B%7D)()%3B">bookmarklet</a>

Tests

This library comes with unit tests to make sure the resulting crunched Javascript is valid code under various PHP versions., (*8)

Current version supports PHP 7.2+ (previous releases were tested with PHP 5.3 - 7.1), (*9)

License

Do whatever the hell you want to do with it, (*10)

The Versions

18/06 2017

dev-master

9999999-dev https://github.com/ozh/bookmarkletgen

PHP class to convert JS into valid bookmarklet links

  Sources   Download

MIT

The Requires

  • php >=5.3

 

javascript bookmarklet

18/05 2017

1.2

1.2.0.0 https://github.com/ozh/bookmarkletgen

PHP class to convert JS into valid bookmarklet links

  Sources   Download

MIT

The Requires

  • php >=5.3

 

javascript bookmarklet

18/05 2017

1.1

1.1.0.0 https://github.com/ozh/bookmarkletgen

PHP class to convert JS into valid bookmarklet links

  Sources   Download

MIT

The Requires

  • php >=5.3

 

javascript bookmarklet

30/08 2014

1.0

1.0.0.0 https://github.com/ozh/bookmarkletgen

PHP class to convert JS into valid bookmarklet links

  Sources   Download

MIT

The Requires

  • php >=5.2.4

 

javascript bookmarklet