On 2010-03-10 01:57, TP wrote:
On Mar 9, 10:49 pm, Aleksandr Rainchik<[email protected]> wrote:
On Mar 10, 12:26 am, cc<[email protected]> wrote:
On 2010-03-09 22:12, Dave Land wrote:
On Mar 9, 2010, at 9:44 PM, Dave Land wrote:
The "anonymous function wrapper" ensures that the script's
identifiers don't collide with identifiers in JavaScript in the page
itself. All of the script's identifiers exist only within the
anonymous function, so they can't "leak out" into the page, or vice
versa � the script's identifiers are all local to the script.
And so forth...
I thought I could find where it is documented that this is an archaic
way of writing GM scripts, but I can't find it now.
I wonder if someone can explain to us: does GM automatically wrap user
scripts in an anonymous function (or the equivalent) to gain the
security and scoping benefits I named above? Is it overkill to add the
anon function in your own user scripts?
Yes, it is. See http://wiki.greasespot.net/Metadata_Block#.40unwrap
(Actually, GM wraps *twice* -- once with an anonymous function, for
compatibility and reliability, and once with evalInSandbox, for
security. This last wrapping is what's responsible for unsafeWindow and
friends, or more accurately for why there's a distinction possible
between unsafeWindow and window.)
--
cc | pseudonymous |<http://carlclark.mp/>
Sounds good. If GM double-wraps my code, I don' really have to wrap it
myself :)
Thank you!
I have the opposite question.
This isn't quite opposite; here the anonymous function wrapping that the
page does is irrelevant to your problem, which only has to do with the
security wrapping I mentioned.
Suppose the *webpage* does something like:
if (!PIP.HOLD) {
PIP.HOLD = {};
}
(function () {
PIP.HOLD.summaryFields = [
'checkbox',
'title',
'author',
'status',
'holdPickupDate',
'holdPickupBranch',
'queuePosition',
'available'
];
})();
And I want to change PIP.HOLD.summaryFields to:
PIP.HOLD.summaryFields = [
'checkbox',
'title',
'author',
];
How can I do that from a Greasemonkey script?
See http://wiki.greasespot.net/UnsafeWindow for ideas.
--
cc | pseudonymous |<http://carlclark.mp/>
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.