定制 ozh/bookmarkletgen 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ozh/bookmarkletgen

最新稳定版本:1.3

Composer 安装命令:

composer require ozh/bookmarkletgen

包简介

PHP class to convert JS into valid bookmarklet links

README 文档

README

Bookmarklet Gen Logo

Bookmarklet Gen

Convert (readable) Javascript code into bookmarklet links

Features

  • removes comments
  • compresses code by removing extraneous spaces, but not within literal strings. Example:
    function   someName(   param   ) {
     alert( "this is a string" )
    }
    will return:
    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

Installation

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

    {
        "require": {
            "ozh/bookmarkletgen": "~1.3"
        }
    }

Or simply in the command line : composer install ozh/bookmarkletgen

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

Example

<?php
$javascript = <<<CODE
var link="https://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:

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

See provided examples for more details.

Tests

This library comes with unit tests to make sure the resulting crunched Javascript is valid code.

The current version supports PHP 8.1+ (previous releases were tested with PHP 5.3 – 7.2).

License

Do whatever the hell you want to do with it.

统计信息

  • 总下载量: 21.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-06-10