MozillaZine

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

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

Post Posted July 25th, 2020, 2:28 pm

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/pagezipper/pagezipper_10.js';document.getElementsByTagName('head')[0].appendChild(window._page_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: 3842
Joined: February 3rd, 2009, 6:29 pm

Post Posted July 25th, 2020, 3:45 pm

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/pagezipper/pagezipper_10.js

You could create something like a userscript bookmarklet.

http://www.tampermonkey.net/documentation.php#GM_registerMenuCommand

therube

User avatar
 
Posts: 20459
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Post Posted July 26th, 2020, 7:16 am

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.)
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: 3842
Joined: February 3rd, 2009, 6:29 pm

Post Posted July 26th, 2020, 8:32 am

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.

Return to Firefox Support


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 11 guests