1

When this page loads, I want to simulate automatically clicking the send me this thing button whilst having it open in a new window (or new tab)

  • There will only ever be one send me this thing button on any page like that

What for?

This is for Greasekit on Fluid.app, which is similar to Greasemonkey.

Brock Adams
  • 82,642
  • 19
  • 207
  • 268
Hannah Ellis
  • 163
  • 1
  • 8

1 Answers1

2

That Button is a link and that page uses jQuery. So you can get the button like:

var buyItBtn = $("a:contains('Send me this thing')");

Then modify the link to open in a new tab/window.
Then click the link.

The code is:

//-- Note  that :contains() is case-sensitive.
var buyItBtn = $("a:contains('Send me this thing')");
buyItBtn.attr ("target", "_blank");
buyItBtn[0].click ();

BUT, beware that modern popup blockers will block this, I don't know about the webkit embedded in your version of Fluid. Tell your popup blocker to allow these particular popups.

Also, because this is Greasekit, you need to inject the above code, so the complete userscript will be something like:

// ==UserScript==
// @name        _Amazon-like store, buy things in a new window
// @include     https://dl.dropboxusercontent.com/u/5546881/*
// @grant       GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/
function GM_main () {
    //-- Note  that :contains() is case-sensitive.
    var buyItBtn = $("a:contains('Send me this thing')");
    buyItBtn.attr ("target", "_blank");
    buyItBtn[0].click ();
}

addJS_Node (null, null, GM_main);

function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
    var D                                   = document;
    var scriptNode                          = D.createElement ('script');
    if (runOnLoad) {
        scriptNode.addEventListener ("load", runOnLoad, false);
    }
    scriptNode.type                         = "text/javascript";
    if (text)       scriptNode.textContent  = text;
    if (s_URL)      scriptNode.src          = s_URL;
    if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';

    var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
    targ.appendChild (scriptNode);
}
Brock Adams
  • 82,642
  • 19
  • 207
  • 268
  • Thanks, i was actually able to use the 3-line code that you gave without any problems (in other words, I didn't need to do the injection thing) – Hannah Ellis Oct 25 '13 at 03:04
  • That's interesting, If you can, see if Fluid+Greasekit is including jQuery automatically (good) or if it is automatically running scripts in the page scope (very bad). – Brock Adams Oct 25 '13 at 03:22
  • Confusingly, I’ve just tried it again and **neither** options presented in your answer work. (Was I drunk when I tried it and it worked?) – Hannah Ellis Oct 26 '13 at 16:07
  • Given that the answer to your other Q worked, and given that I tested this script on your test page, this answer will work for you -- at least for the test page. If the actual page is different (now), that's on you unless you provide us a way to use it. As Far as it now "not working", that's not good enough. We need details and error messages. What's the error console say? Did you tune or disable your popup blocker? – Brock Adams Oct 26 '13 at 21:06