2

If you take a look at this page, there's a drop down to show results per page: it can be 10, 20 or 50.

I would like a Greasemonkey-like script to simulate selecting 50 per page.

For ease of reference some of the HTML from the page is here:

<select><option value="10">10</option><option value="20">20</option><option value="50">50</option></select> per page

How can I achieve this, please?

Edits

URL updated with more than 20 items

This is for Greasekit on Fluid.app (which is very old, but I am restricted to using it). Brock reliably tells me it is very old and no longer updated. (I don't think I can even use jQuery)

Community
  • 1
  • 1
Sockie
  • 189
  • 1
  • 9
  • Updated the answer. It *should* work even for Greasekit. Not sure about within Fluid. Your sample page uses jQuery. If your Fluid app runs the same kind of page, then your userscript can also use the page's jQuery. – Brock Adams Oct 20 '13 at 04:51

1 Answers1

2

Since that select is driven by jQuery, you can use jQuery to change it and trigger all the necessary javascript.

But your Greasemonkey script must use injection or @grant none mode, because you need to trigger the page's javascript functions.

A complete script for that sample page would be like:

// ==UserScript==
// @name        _Amazon-like store, auto select 50 items per page
// @include     https://dl.dropboxusercontent.com/u/5546881/*
// @grant       none
// ==/UserScript==

//-- $ not defined. Use jQuery
jQuery('#v_pagination_long select').val (50).trigger ('change');



Update:

Since the OP is not really using Greasemonkey, or a modern equivalent like Tampermonkey, @grant none is not supported.
Here is the same script using script injection, that will work on almost any browser+userscript-engine combo:

// ==UserScript==
// @name        _Amazon-like store, auto select 50 items per page
// @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 () {
    jQuery('#v_pagination_long select').val (50).trigger ('change');
}

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);
}



Important:

  1. That sample page shows 9 items max, so it's impossible to be 100% sure that the script is doing everything needed. With the OP's new sample page, verified that the script works on FF+GM and Chrome+TM.
  2. The <select> is wrapped in a div with the id: v_pagination_long. Use that to help get the correct control.
  3. That page uses various mouse events (not click), so it may be that more stateful approaches are needed (Can't tell for sure, see item 1). Not needed in this case for the demo page. See Choosing and activating the right controls on an AJAX-driven site for other pages.
Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Thanks. I'm not quite using Greasemonkey, though; I'm using something called Greasekit (which is very similar). – Sockie Oct 19 '13 at 23:57
  • Regarding point 2, I have another sample page I can try it on, that has several hundred entries. (It's not public though). – Sockie Oct 20 '13 at 00:00
  • Again, regarding point 2, how would I go about that, please? (I'm a newbie to Javascript). Would it be something like `document.getElementsByDiv`? [Upon researching, that's not a real command…] How about `document.getElementById("id")` – Sockie Oct 20 '13 at 00:03
  • Damn, I tested it and it doesn't seem to work. I've just read all your footnotes, it's probably due to [3] (it uses mouse events). Regarding [4], I shall create a new page with more items so it can be tested fully. THANK YOU VERY MUCH! – Sockie Oct 20 '13 at 00:07
  • You didn't specify Greasekit in the question! I tested the script in FF+GM and it works. It should also work in Chrome+Tampermonkey. As for Greasekit, it hasn't been updated in 5 years, best I can tell. I don't think it or Ninjakit support `@grant none`, so you need to use script injection. See the question I linked in my answer. – Brock Adams Oct 20 '13 at 03:10
  • About point 2, I showed you exactly how. Use that jQuery selector. I only mentioned it because that part of the HTML structure was not otherwise clear from the question. – Brock Adams Oct 20 '13 at 03:12
  • Edit your question to list exactly what browser and script engine you are using. Also include a link to a test page with more than 20 items. – Brock Adams Oct 20 '13 at 03:14
  • See the updated answer as of just now -- without any `console.log` calls. – Brock Adams Oct 20 '13 at 04:54
  • Outstanding, thank you! Near the top of the page, there is a "Show sold out items" checkbox. What could I append to this script to make that auto check this box. (Perhaps I should submit this as a new question?) – Sockie Oct 20 '13 at 23:07
  • You would add `jQuery("#v_showOOS").click ().trigger ("change");` to `GM_main()`. Anything more, please open a new question. – Brock Adams Oct 20 '13 at 23:46