[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/vendor/ozh/bookmarkletgen/ -> README.md (source)

   1  ![Bookmarklet Gen Logo](https://private-user-images.githubusercontent.com/223647/511368974-902e538e-0a33-4214-8c13-4b320bc473fe.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjI1MzIxNTgsIm5iZiI6MTc2MjUzMTg1OCwicGF0aCI6Ii8yMjM2NDcvNTExMzY4OTc0LTkwMmU1MzhlLTBhMzMtNDIxNC04YzEzLTRiMzIwYmM0NzNmZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUxMTA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MTEwN1QxNjEwNThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02YWVmZGYwNDg3MmFkYmQ0OGJiYThlYTk3OWUxMDRiY2VhODY1MzAyYmEzNjcxMjdmNzMyNGE3MDViOGMwMjg5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.dbNtvWtjo3n7pqXjudl7oK8wMsWOugelOTdmziFNezM)
   2  
   3  # Bookmarklet Gen 
   4  
   5  > Convert (readable) Javascript code into bookmarklet links
   6  
   7  ## Features
   8  
   9  - removes comments
  10  - compresses code by removing extraneous spaces, but not within literal strings.
  11    Example:
  12      ```javascript
  13    function   someName(   param   ) {
  14       alert( "this is a string" )
  15    }
  16      ```
  17    will return:
  18      ```js
  19    function%20someName(param){alert("this%20is%20a%20string")}
  20      ```
  21  - encodes what needs to be encoded
  22  - wraps code into a self-invoking function ready for bookmarking
  23  
  24  This is basically a slightly enhanced PHP port of the excellent Bookmarklet Crunchinator: 
  25  http://ted.mielczarek.org/code/mozilla/bookmarklet.html
  26  
  27  ## Installation
  28  
  29  If you are using Composer, add this requirement to your `composer.json` file and run `composer install`:
  30  
  31  ```json
  32      {
  33          "require": {
  34              "ozh/bookmarkletgen": "~1.3"
  35          }
  36      }
  37  ```
  38  
  39  Or simply in the command line : `composer install ozh/bookmarkletgen`
  40  
  41  If you're not using composer, download the class file and include it manually.
  42  
  43  ## Example
  44  
  45  ```php
  46  <?php
  47  $javascript = <<<CODE
  48  var link="https://google.com/"; // destination
  49  window.location = link;
  50  CODE;
  51  
  52  require 'vendor/autoload.php'; // if you install using Composer
  53  require 'path/to/Bookmarkletgen.php'; // otherwise
  54  
  55  $book = new \Ozh\Bookmarkletgen\Bookmarkletgen;
  56  $link = $book->crunch( $javascript );
  57  
  58  printf( '<a href="%s">bookmarklet</a>', $link );
  59  ```
  60  
  61  will print:
  62  
  63  ```html
  64  <a href="javascript:(function()%7Bvar%20link%3D%22https%3A%2F%2Fgoogle.com%2F%22%3Bwindow.location%3Dlink%3B%7D)()%3B">bookmarklet</a>
  65  ```
  66  
  67  See provided examples for more details.
  68  
  69  ## Tests
  70  
  71  This library comes with unit tests to make sure the resulting crunched Javascript is valid code.
  72  
  73  The current version supports PHP 8.1+ ([previous releases](https://github.com/ozh/bookmarkletgen/releases) were tested with PHP 5.3 – 7.2).
  74  
  75  ## License
  76  
  77  Do whatever the hell you want to do with it.


Generated: Sun Sep 27 05:12:21 2026 Cross-referenced by PHPXref 0.7.1