How to include local scripts?

3,902 views
Skip to first unread message

ASR

unread,
Apr 20, 2012, 7:32:16 AM4/20/12
to greasemonkey-users
Hi,

I am new to Greasemonkey and while writing few scripts, i realize that
there are some common functions that I am using across all scripts. I
think it will be better to have all these functions in a common js
file and then include that in various scripts.

Can that be done? I tried using @require but it doesn't worked.

thanks

Tei

unread,
Apr 20, 2012, 7:45:06 AM4/20/12
to greasemon...@googlegroups.com
Why no?

You can place your JS somewhere on the net. @require
http://www.prionhkiyt.com/js/prionhkiyt.lib-1.0.0.js then use that
as a require.
I don't see why this would not work.


--
--
ℱin del ℳensaje.

Anthony Lieuallen

unread,
Apr 20, 2012, 9:09:09 AM4/20/12
to greasemon...@googlegroups.com
On Fri, Apr 20, 2012 at 7:45 AM, Tei <oscar...@gmail.com> wrote:
I don't see why this would not work.

The key word is "local".  As you pointed out, @requires need to come from the internet.  (There's a longer answer, but this is the simple easy one.)

Klaus Johannes Rusch

unread,
Apr 20, 2012, 9:52:05 AM4/20/12
to greasemon...@googlegroups.com
Loading a library javascript file from a file:/// URL works perfectly fine for me:

// ==UserScript==
// @name          test script
// @namespace      http://www.example.com/
// @description   test script
// @include       *
// @require          file:///path/to/test2.user.js
// ==/UserScript==

-- 
Klaus Johannes Rusch
klaus...@atmedia.net
http://klausrusch.atmedia.net/

Matt Sargent

unread,
Apr 20, 2012, 12:54:49 PM4/20/12
to greasemon...@googlegroups.com
On 4/20/2012 8:52 AM, Klaus Johannes Rusch wrote:
On 20.04.2012 15:09, Anthony Lieuallen wrote:
On Fri, Apr 20, 2012 at 7:45 AM, Tei <oscar...@gmail.com> wrote:
I don't see why this would not work.

The key word is "local".  As you pointed out, @requires need to come from the internet.  (There's a longer answer, but this is the simple easy one.)

Loading a library javascript file from a file:/// URL works perfectly fine for me:

// ==UserScript==
// @name          test script
// @namespace      http://www.example.com/
// @description   test script
// @include       *
// @require          file:///path/to/test2.user.js
// ==/UserScript==


Doesn't that require altering the "fileIsGreaseable" browser setting?

Klaus Johannes Rusch

unread,
Apr 20, 2012, 3:38:19 PM4/20/12
to greasemon...@googlegroups.com
On 20.04.2012 18:54, Matt Sargent wrote:
On 4/20/2012 8:52 AM, Klaus Johannes Rusch wrote:
Loading a library javascript file from a file:/// URL works perfectly fine for me:
Doesn't that require altering the "fileIsGreaseable" browser setting?

I don't think so, the "greasability" applies to which schemes can be used in the @include statements, not where the scripts are loaded from. GM scripts are not executed if the page is a local file.

http://wiki.greasespot.net/Include_and_exclude_rules#Greaseable_schemes

Anthony Lieuallen

unread,
Apr 20, 2012, 5:08:39 PM4/20/12
to greasemon...@googlegroups.com
On Fri, Apr 20, 2012 at 12:54 PM, Matt Sargent <matt.s...@locusprime.net> wrote:
Doesn't that require altering the "fileIsGreaseable" browser setting?

To download any file (require, resource, icon) along with a script it has to be greaseable -- or come from the same scheme as the script itself.

https://github.com/greasemonkey/greasemonkey/blob/master/modules/remoteScript.js#L455

Klaus Johannes Rusch

unread,
Apr 20, 2012, 6:31:29 PM4/20/12
to greasemon...@googlegroups.com
On 20.04.2012 23:08, Anthony Lieuallen wrote:
On Fri, Apr 20, 2012 at 12:54 PM, Matt Sargent <matt.s...@locusprime.net> wrote:
Doesn't that require altering the "fileIsGreaseable" browser setting?

To download any file (require, resource, icon) along with a script it has to be greaseable -- or come from the same scheme as the script itself.
Thanks for the correction, you are right ... since the OP wanted to load his shared code fragments into another script the same scheme condition should apply though.
Reply all
Reply to author
Forward
0 new messages