Is there ANY WAY to load a javascript library using Greasemonkey and have the functions executable by a bookmarklet?
(safely / securely, or relatively so)
--
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to greasemonkey-us...@googlegroups.com.
To post to this group, send email to greasemon...@googlegroups.com.
Visit this group at http://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.
On Dec 3, 2014, at 9:18 PM, GmUser <pop...@p-t-b.com> wrote:
Is there ANY WAY to load a javascript library using Greasemonkey and have the functions executable by a bookmarklet?
-- Klaus Johannes Rusch klaus...@atmedia.net http://klausrusch.atmedia.net/
I FINALLY found a solution to my problem. It's kind of "stupid", because, although you are limited in what URL
you can use to inject a script into certain CSP-protected documents,
you can insert ANY text DIRECTLY into the document. (now watch them
take that away from us, too) Of course, there is (still?) usually
some limit to the size of a saved bookmarklet, but I (needed to)
get around that. (plus the "squishing" and such needed in bookmarklets) The solution is fairly simple using a Greasemonkey userscript.
I don't know why people who supposedly know how the "new" stuff
in Gm works couldn't simply tell me how to do it. (?) I use the @resource command to access my 56K JavaScript library
file (which is loaded as a SNAPSHOT into the Gm directory that
holds the userscript upon installation -- there are some issues
with that and modifications/reload to the referenced source file --
so I directly edit the snapshot file), get the contents of it,
and directly insert that .JS file document text using the script object
.text property instead of the .src property. I also didn't want to load the library into every page, so I made
the bookmarklet "communicate" with the userscript and let it know
that it wants the library loaded, and then it executes the library
bookmarklet function after 1/5th of a second. This is the script I use to load my bookmarklets library now:
(with some names 'obfuscated') // ==UserScript== // @name Bookmarklet Library // @namespace choose-a-namespace.com // @description Loads bookmarklet library into page // @include * // @version 1.0 // @resource bmlib http://www.blah-blah-blah.com/bookmarkletlibrary.js // @grant GM_getResourceText // @grant unsafeWindow // ==/UserScript== // NOTE that the library file is a STATIC SNAPSHOT saved into the directory that contains this userscript function checkLibraryLoadRequest() { if (typeof (unsafeWindow.Bm_bLibraryRequest) != 'undefined') { // value set as request from bookmarklet if (typeof (unsafeWindow.Bm_bLibraryLoaded) == 'undefined') { // value set inside library script var sBMLibSource = GM_getResourceText ('bmlib'); var oScript = document.createElement ('script'); oScript.type = 'text/javascript'; oScript.text = sBMLibSource; // document.getElementsByTagName ('head')[0].appendChild (oScript); document.body.appendChild (oScript); } } else { setTimeout (checkLibraryLoadRequest, 100); // check every 100 ms } return; } // checkLibraryLoadRequest checkLibraryLoadRequest(); // EXAMPLE Bookmarklet shell/template: // javascript:(function(){window.Bm_bLibraryRequest=true;setTimeout(function(){window['***FUNCTION-NAME***']();},200);})() /**********************************************************************/ At the top of the library script file I have: var Bm_bLibraryLoaded = true; // stops library from being loaded twice (just in case) And then my bookmarklets all have the format as the example above. I just change the "***FUNCTION-NAME***" value to the name of
the function I want to call in the library. I kept the "communication" between the userscript and the
bookmarklet simple. So far it has worked. Although one time
it may not have, so you might want to either decrease the
"check for request time" to 50 and/or increase the
"execute bookmarklet function" time to 250.
I haven't noticed any noticeable lag time because it's
only about 1/5th of a second. So far it works great. I can now execute my bookmarklets
from Twitter, Facebook, Google, and anywhere else and
and https:// "secure" website.
So I suppose this will work until someone does something
else to screw us over. btw -- I am using Pale Moon now ("old-style Firefox"),
so I don't know if there are any differences in Firefox, Chrome, etc.