1

At our school website, the homework pages for our teachers only shows the upcoming assignments.
To show all of the assignments you click See All and then All Homework.

The URL changes in the following way

http://example.com/apps/classes/show_class.jsp?classREC_ID=000000
http://example.com/apps/classes/show_assignment.jsp?classREC_ID=000000&showAll=true

I have looked (mainly on Stack Overflow) for solutions such as User Scripts that will automatically change the URL, but I have not been able to figure out how to do this based off of other peoples questions/answers.

To keep it short, how would I be able to modify the URL so show_class becomes show_assignment and has &showAll=true appended to it at the end.

Thanks for any help.

Ylj
  • 45
  • 1
  • 7
  • were you going to do this as a greasemonkey script or similar? if so you just need to fire off a sequence of xmlhttprequests with different URLs and then put the results somewhere – Max DeLiso Sep 06 '12 at 03:19
  • possible duplicate of [How can I make a redirect page in jQuery/JavaScript?](http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript) – Brock Adams Sep 06 '12 at 05:18
  • @BrockAdams I just looked over that question, and while it is in the same territory, at my level I would not have known how to adapt it for my purposes. That might just mean that I am at a very low level of JavaScript comprehension, but I think it is worth having this question just so there are more specific examples for formatting. – Ylj Sep 06 '12 at 05:53
  • @Ylj, You may be right. Not all duplicates are complete duplicates. Nor are all duplicates closed (which basically just stops new answers and refers people to older and possibly better answers). Only the worst duplicates are deleted -- which would make the question invisible to most users. – Brock Adams Sep 06 '12 at 06:00

2 Answers2

1

This would do it:

window.location = String(window.location).replace(/show_class/,"show_assignment") + "&showAll=true";
Rhyono
  • 2,420
  • 1
  • 25
  • 41
  • When I tried your code, the page kept refreshing and going through the URL change (adding "&showAll=true" over and over). I have been trying to edit your code a bit but have been unsuccessful so far. – Ylj Sep 06 '12 at 03:59
  • My stupid mistake, I set the @include up so it would keep reloading. Thanks for the help. – Ylj Sep 06 '12 at 04:43
0

Are you trying to modify links, or modify buttons, or redirect all show_class.jsp pages?

If you are trying to modify links, buttons, etc. Edit your answer to show the appropriate HTML source of the target page.

If you want to redirect, a script like the following should do it:

// ==UserScript==
// @name        _Redirect to see all homework assignments
// @include     http://example.com/apps/classes/show_class.jsp?classREC_ID=*
// @run-at      document-start
// ==/UserScript==

var newURL  = location.href.replace (/show_class\.jsp/i, "show_assignment.jsp")
            + "&showAll=true"
            ;

//--- Keep browser history / back-button, uncluttered.
location.replace (newURL);
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • I tried using your script, however, just like Rhyono's script, the script would keep loading and the page would continually add "&showAll=true" to the end. I tried tweaking your script, Rhyono's script, and adding parts of each together, but so far I am getting the same results as before. Any insight as to why it would keep loading the script would be very helpful. (I have tried your old script and your updated one if it makes a difference.) – Ylj Sep 06 '12 at 04:18
  • Oh sorry, didn't really answer your first question. I want to redirect all show_class pages so the homework pages just became "All homework" pages. – Ylj Sep 06 '12 at 04:30
  • My answer script should not loop, because the `show_assignment` page does not match the `@include` directive. You must have modified the include directive from what I've shown. Post or link to your exact script. ... Provide 2 matching **exact**, **unedited** example-URLs, so we can make sure the include and regex match. You can do it in a comment (which you can later delete, if needed). – Brock Adams Sep 06 '12 at 04:34
  • To be more clear, the script only continued after I had tried other editing. When I used your script (the first and updated), the page would not redirect. Sorry for the hassle. And right now Rhyono's script is working, I just had to make the @include more exact because I set it for all "show" pages instead of "show_class". When trying your script again (just now), I only edited "example", so I'm not sure what the problem is. – Ylj Sep 06 '12 at 05:00
  • When using your script just now I was redirected to an undefined page. (http://example.com/apps/classes/undefined&showAll=true) In addition, when you mention javascript-regex, are you speaking of the @include line or something else in your script? Lastly, I just added in your section of script for the back-button into Rhyono's script (added "var newURL = "), but what else about your script is different? I cant tell why yours wont work and cant think of any reason why it wouldn't, other than the more complex (for me at least) formatting. And I am editing the "example" part. – Ylj Sep 06 '12 at 05:46
  • My bad. I made a rookie mistake. (Omitted the `.href`) That's what happens when you type from memory and don't test against live URL's/code/etc. ... Sorry about that. – Brock Adams Sep 06 '12 at 05:55
  • Alright, just tried out this version and it worked just fine. Thanks for your help on this and for sticking through some pretty low-level stuff. Just a question, once I add on the browser history section to Rhyono's script, is there any functional difference between the two? Which one would work better? – Ylj Sep 06 '12 at 06:00
  • No, at that point, the code operation is essentially identical. I'll upvote Rhyono's answer. – Brock Adams Sep 06 '12 at 06:02