Req: binsearch.info - remember default search age

Subscribe to Req: binsearch.info - remember default search age 10 posts, 3 voices

 
Dink Scriptwright

binsearch.info has changed something to where now when you try to change the default search age that firefox won't keep your setting...So does anyone have any ideas as to how a script could be made that will make firefox remember the setting??

 
Joel H Scriptwright

gm_setvalue and gm_getvalue

-Joel

 
Dink Scriptwright

Joel,
thanks for your reply, but I could use a little more input, as I am not that great with the coding myself!!

 
znerp Scriptwright

It strikes me that the simplest way to do this would be simply to manipulate the url; changing the &adv_age= bit depending on your needs. If you do that, it should be simple enough ... something like

// ==UserScript==
// @name           foo
// @include        http://binsearch.info/?q=*
// ==/UserScript==

if !(/&adv_age=\d+/.test(document.location.href)) {
  document.location.replace(document.location.href + "&adv_age=" + GM_GetValue("search age", 7))
} else if (document.location.href.match(/&adv_age=(\d+)/)[1] != GM_GetValue("search age", 7)) {
  document.location.replace(document.location.href.replace(/&adv_age=(\d+)/, "&adv_age=" + GM_GetValue("search age", 7)))
}

GM_registerMenuCommand(
  "Set search age...", 
  function() { 
    age = prompt("Enter search age in days:",GM_getValue("search age", 7));
    if (age!=null && age!="") {
      GM_setValue("search age", parseInt(age));
    }
  })
This is completely untested and written on the fly, but I think it should work.

 
Dink Scriptwright

Thanks for your efforts Znerp,
but my tests came up with no results at all....
I do appreciate the input on this idea though!!!

 
znerp Scriptwright

No results at all sounds strange because my code shouldn't remove anything. I installed this script and so I know it works fine for me now and I've ironed out the minor bugs. Try this;

// ==UserScript==
// @name           foo
// @include        http://binsearch.info/?q=*
// ==/UserScript==

if (!(/&adv_age=\d+/.test(document.location.href))) {
  document.location.replace(document.location.href + "&adv_age=" + GM_getValue("search age", 7))
} else if (document.location.href.match(/&adv_age=(\d+)/)[1] != GM_getValue("search age", 7)) {
  document.location.replace(document.location.href.replace(/&adv_age=(\d+)/, "&adv_age=" + GM_getValue("search age", 7)))
}

GM_registerMenuCommand(
  "Set search age...", 
  function() { 
    age = prompt("Enter search age in days:",GM_getValue("search age", 7));
    if (age!=null && age!="") {
      GM_setValue("search age", parseInt(age));
    }
  })

 
Dink Scriptwright

I still have no results with this...just how do you get it to work for you....and does it work still if you close firefox and then go back to the site (binsearch.info) later...I just want firefox to remember my default search age of 70 days.
Thanks for your time and effort on this!!!

 
znerp Scriptwright

Ok ... I'll go through this step by step with you. When performing a search on binsearch.info, the search age is specified in the url by &adv_age= and then the number of days.

The code I wrote performs a simple if-else to check firstly if you're on a search page and &adv_age= doesn't appear in the url, and so adds it on in that case. Else it must be in there, so it compares the number of days in the url with the number that's set using GM_setValue. If they're not the same, it will simply change the url to the value in GM_getValue (which is defaulted to 7 days).

Just for good measure and useability, I then added a menu command to allow you to set the number of days (right click on the monkey when on a results page then "User Script Commands.." then "Set search age..")

If this still isn't working for you, then could you please paste the url of a test search and I'll see if I can see what went wrong. Sorry I hadn't explained all of this before, I'd assumed that since you were a scriptwright you might be able to work out what my code is doing.

 
Dink Scriptwright

ok...I got it now!!
Thanks for being so patient with me....
I may add this to the repository later, but you get all the credit!!!
Thanks again!!

 
Dink Scriptwright

http://userscripts.org/scripts/show/24743

I hope I explained this well enough to all other users!