0

Can somebody help me loop the following function and make it run every 5 seconds:

javascript:listAction(
    'editObjectSingle','inforUpdateAction','divEditObjectSingle','formEditObjectSingle'
);

for the specific website google.com?

I'm still new to this and unsure how to write it

// ==UserScript==
// @name           Google
// @description    Google
// @include        Google.com
// ==/UserScript==

// initiate

This is what I have so far, not sure how to add other stuff. Thanks!

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • 1
    Maybe I'm missing something, but what does this have to do with Java? – Hovercraft Full Of Eels Nov 27 '14 at 20:36
  • Hm, no response....? I've taken the liberty of deleting your [tag:java] tag, but please do let me know if I did this in error. You know of course that Java and Javascript are two completely different programming languages, about as closely related as ham is to hamburger, that if you mis-tag your question you will not get the right experts in to review it, and that this may hurt your chances of getting decent help. Since I know absolutely nothing about Javascript, this is about all that I can do for you except to wish you well and hope that you get a decent answer soon. – Hovercraft Full Of Eels Nov 27 '14 at 21:22
  • 1
    @HovercraftFullOfEels, for future reference, [java] will almost never apply to Greasemonkey or userscript questions. – Brock Adams Nov 27 '14 at 21:24

1 Answers1

1

See, also:


For the default @grant setting (@grant none), calling a page's javascript is relatively straightforward.

If, and only if, listAction is a global function on the page (it probably is), then you can call it like so:

// ==UserScript==
// @name        Google function spammer
// @match       *://*.google.com/*
// @description Spam the snot out of the listAction function on Google.
// @grant       none
// ==/UserScript==

var updateTimer = setInterval ( function () {
        //-- The function will not always exist (right away).
        if (typeof listAction === "function") {
            listAction (
                'editObjectSingle', 'inforUpdateAction',
                'divEditObjectSingle', 'formEditObjectSingle'
            );
        }
    },
    5 * 1000    // 5 seconds
);

Note that the @include directive in the question is off and the replacement with @match, above.

Also beware that if the function is called from a click handler, etc., it may expect/require a context (this). In that case, calling it requires more information than is present in this question and probably can be accomplished by programmatically clicking on the control.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295