Bookmarklet: possible to embed inside the .js it depends on?

User Help for Mozilla Firefox
Post Reply
user2018
Posts: 196
Joined: September 23rd, 2018, 11:07 am

Bookmarklet: possible to embed inside the .js it depends on?

Post by user2018 »

Here we have the PageZipper bookmarklet (https://www.printwhatyoulike.com/pagezipper):

javascript:(function(){if(window['pgzp']){_pgzpToggleBookmarklet();}else{window._page_zipper_is_bookmarklet=true;window._page_zipper=document.createElement('script');window._page_zipper.type='text/javascript';window._page_zipper.src='//www.printwhatyoulike.com/static/pagezip ... ge_zipper);}})();

The problem is that it loads an external JavaScript file (located at https://www.printwhatyoulike.com/static ... pper_10.js). I would like to have an only-local bookmarklet, that does not load any external JavaScript located in the web. Is it possible, somehow, to embed the contents of pagezipper_10.js in the bookmarklet itself. If so, how could I do that? I tried but the bookmarklet does not seem to do anything in that case (probably because I did it incorrectly, just trying...).

As PageZipper is open source (https://github.com/jkoomjian/PageZipper), I also tried to do a local installation, with a local webserver to serve the JavaScript file from the local filesystem, but with no success either (I get an "Loading failed for the <script> with source ....." error). Anyway, if possible I would prefer to pursue the first approach rather than having to run a local webserver.

Any idea would be great.
morat
Posts: 6426
Joined: February 3rd, 2009, 6:29 pm

Re: Bookmarklet: possible to embed inside the .js it depends

Post by morat »

The maximum length for a bookmarklet is around 65,536 bytes.

http://support.mozilla.org/questions/1259005

The pagezipper script file is 137,132 bytes.

http://www.printwhatyoulike.com/static/ ... pper_10.js

You could create something like a userscript bookmarklet.

http://www.tampermonkey.net/documentati ... enuCommand
User avatar
therube
Posts: 21714
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Re: Bookmarklet: possible to embed inside the .js it depends

Post by therube »

If you could include the pertinent parts of the .js into the bookmarklet itself...

For local, don't know that you need a server per se ?, would think that simply pointing to the .js file would be sufficient?

But, that security minded, can't do anything browser, you know, Quantum, could be hampered by things like, Bookmarklets affected by CSP?
(Seven years, so far. Hard to believe. And its only been 2 years since Boris said - enough!, & fixed the easier part of this.)
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript
morat
Posts: 6426
Joined: February 3rd, 2009, 6:29 pm

Re: Bookmarklet: possible to embed inside the .js it depends

Post by morat »

In Chrome, I get a "not allowed to load local resource: file:///C://pagezipper_10.js" error on a forums.mozillazine.org page.

Code: Select all

(function () {
  if (window['pgzp']) {
    _pgzpToggleBookmarklet();
  } else {
    window._page_zipper_is_bookmarklet = true;
    window._page_zipper = document.createElement('script');
    window._page_zipper.type = 'text/javascript';
    window._page_zipper.src = 'file:///C://pagezipper_10.js';
    document.getElementsByTagName('head')[0].
      appendChild(window._page_zipper);
  }
})();
The script works on a local page.
Post Reply