3

Some sites (namely Steam Community Market) require the user to manually check a specific checkbox for repetitive actions like buying items.

I'd like to have that checkbox always checked.

  • URL:
    http://steamcommunity.com/market/listings/730/USP-S%20%7C%20Torque%20(Field-Tested)
  • element:
    <input id="market_buynow_dialog_accept_ssa" type="checkbox" value="0" name="accept_ssa">

Can that be done with Tampermonkey?

I found document.getElementById("checkbox").checked = true; which seems logical to me. I put it in a new Tampermonkey script and added steam market to the list of websites the script activates on but it didn't work.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Schmix
  • 57
  • 1
  • 2
  • 6
  • This is possible and it's not too difficult but you'll have to provide some specifics like the page url and the *actual* checkbox html (and a link to the entire page html posted on pastie.org or similar). If you provide these details your question, although borderline offtopic, may still be useful for other people. – wOxxOm Nov 17 '15 at 19:36
  • @wOxxOm Well I was going to use it for the general steam market (at [link](http://steamcommunity.com/market/)) but to be specific i was trying on [link](http://steamcommunity.com/market/listings/730/USP-S%20%7C%20Torque%20(Field-Tested)). HTML code (just source code) at [link](http://pastebin.com/mtcF5CGE). Though it may be useful to know that the box only appears once you click "buy now", and also the listings change a lot. I hope this is what is needed – Schmix Nov 17 '15 at 20:31
  • See, also: [Choosing and activating the right controls on an AJAX-driven site](http://stackoverflow.com/questions/15048223/choosing-and-activating-the-right-controls-on-an-ajax-driven-site). – Brock Adams Nov 17 '15 at 22:40

2 Answers2

5
  1. Find a pattern in the urls where the userscript should be executed, for example if it's http://steamcommunity.com/market/listings/730/USP-S%20%7C%20Torque%20(Field-Tested) then we can assume the part starting with 730 is volatile so we'll replace it with * in @include key.
  2. We should wait for the checkbox element to be added on the page, there are two methods: MutationObserver-based (I'll use setMutationHandler wrapper) and setInterval-based (best known wrapper is waitForKeyElements). Both are plugged in via @require key.

// ==UserScript==
// @name        Steam - accept the agreement
// @include     http://steamcommunity.com/market/listings/*
// @require     https://greasyfork.org/scripts/12228/code/setMutationHandler.js
// ==/UserScript==


// maybe the elements are already on the page
checkThem([].slice.call(document.querySelectorAll('input[type="checkbox"]')));

// but anyway set a MutationObserver handler for them
setMutationHandler(document, 'input[type="checkbox"]', checkThem);

function checkThem(nodes) {
    nodes.forEach(function(n) { n.checked = true });
}

More info: Greasespot wiki.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • Thank you! Though I no longer have enough money for anything and when i click buy now it just comes up with "add more funds" so I cant really test it, but at least Tamper monkey is showing that the script is executed. And while we're at it, is it also possible to make the "buy now" button instantly buy items? (or autocheck the box and autoclick the confirm button?) Also, doesnt the function (checkThem) have to be declared before its first used and not after? Just wondering – Schmix Nov 17 '15 at 21:08
  • 1
    Yep it's possible but since this is another question I suggest you poke around yourself. – wOxxOm Nov 17 '15 at 21:10
1

Bit late, but your code is wrong.

The grtelementbyid should refer to the html tag's id, not type. I.e. getelementbyid("market_buynow_....")

Ivan S
  • 19
  • 1