Total noob looking for (hopefully) simple greasemonkey script
I have knowledge of the basic concepts of programming in general and html and some very basic knowledge of javascript, but this specific task is proving a little beyond me. I'm actually using tampermonkey, in case that matters.
www.bricklink.com is a site to buy Lego from private sellers. By default, when looking at a shop's listing of items, it shows 25 per page. I would like to automatically switch to 100 per page every time.
Here's a randomly selected store page (no affiliation) at the default 25 per page:
https://store.bricklink.com/TheBricky#/shop?o={"itemType":"P","catID":"18","showHomeItems":0}
Now, same page set to display 100 per page. Note how "pgSize" is added to the url but doesn't appear by default:
What I would like is for pgSize to be set to 100 only IF
"shop" appears in the url
AND
"pgSize" does not appear in the url OR "pgSize" does appear in the url but does not equal 100.
Since Bricklink remembers pgSize per shop page per session, once pgSize is set to 100 for a particular shop greasemonkey doesn't need to do anything. Intercepting the url before the page loads would be nice but unnecessary since loading is fast and I'm not worried about bandwidth.
I tried making this but wasn't sure how to input what I'm trying to test for in the url. Of course now that I've thought about it some more it seems the task is more probably difficult than I thought it would be at first. Any help would be appreciated.
EDIT: This comment below seems to be working, although the way Bricklink makes their urls feels funky at times.
That is a really bizarre URL structure.
If it helps, start with retrieving
window.location.hash
. You could then grab everything after?o=
and parse the JSON to transform it into an object. If that object doesn't contain thepgSize
property or that property has a value that isn't100
, then you can add the property with value100
. After that, you can convert the object back into JSON and replace the URL hash with one that contains the new JSON. For the record, the "hash" is the#
and everything that comes after it. So you would e.g. dowindow.location.hash = '#/shop?o=...';
.I'm not really able to write up some code at the moment, but that should get you going in the right direction.
I'm actually surprised that this works, given that it generates JSON that should be invalid. Nice work!
This seems to do the trick. Thanks very much!
Simplest way would probably be this, which seems to work:
I didn't make it check if pgSize is set but not 100 but that should be enough to get you started.
I am no programmer but if you create an account in the site and go to your search setting you can set the search result to show up to 500 items per page.
Thanks, but that doesn't affect shop pages.
My bad
To give a quick answer, you may want to look into Regex, it could probably solve your URL checking problem.