1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Greasemonkey help yarr +rep

Discussion in 'Code Snippets and Tutorials' started by Phee, May 28, 2010.

  1. Phee

    Phee Moderator
    Staff Member

    Joined:
    Aug 18, 2007
    Messages:
    6,206
    Likes Received:
    101
    Okay, this is from another forum, but it's pretty much dead, so who cares.

    Is there some reason this script isn't working for me?

    Code (Text):
    1. // ==UserScript==
    2. // @name           Neopets Username Checker
    3. // @namespace      neofreaks.org
    4. // @include        http://*.neopets.com/*
    5. // @license        GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
    6. // @copyright      2010+, Freaky (http://neofreaks.org)
    7. // ==/UserScript==
    8.  
    9. GM_registerMenuCommand("Neopets Username Checker", checkMain);
    10.  
    11. var bodyHTML = '<body style="background-color:#ccc; margin:20px">\
    12.     <h1>Neopets Username Checker</h1>\
    13.     <h2>By <a href="http://neofreaks.org">Freaky</a></h2>\
    14.     <div id="input">\
    15.     <form>\
    16.         <label style="display:block" for="users">Usernames to check:</label>\
    17.         <textarea id="users" name="users" rows="10" cols="30"></textarea><br />\
    18.         <input type="button" id="check" value="Check Availability" />\
    19.     </form>\
    20.     </div>\
    21.     <hr />\
    22.     <div id="output">\
    23.         <label style="display:block" for="outusers">Usernames available:</label>\
    24.         <textarea id="outusers" name="outusers" rows="10" cols="30"></textarea><br />\
    25.         <p id="status"></p>\
    26.         <label style="display:block" for="errusers">The following usernames were not checked due to errors:</label>\
    27.         <textarea id="errusers" name="errusers" rows="5" cols="30"></textarea><br />\
    28.     </div>\
    29. </body>'
    30. var checkCount=0;
    31. var stop=0;
    32. var users;
    33.  
    34. function checkMain() {
    35.     //Open window
    36.     checkerWindow=window.open("", "checkerWindow");
    37.     checkerWindow.document.write(bodyHTML); //Write html to window
    38.     checkerWindow.document.close();         //Close document to writing
    39.  
    40.     // add event listeners
    41.     checkerWindow.document.getElementById("check").addEventListener("click", checkUsernames, false);
    42.     checkerWindow.addEventListener("unload", cleanupListener, false);
    43. }
    44.  
    45. function checkUsernames() {
    46.     checkerWindow.document.getElementById("outusers").value = "";
    47.     users = checkerWindow.document.getElementById("users").value.split('\n');
    48.     checkCount=0;
    49.     checkInterval(0);
    50. }
    51.  
    52. // checks users between start and start+250 in list, then starts next check
    53. function checkInterval(start) {
    54.     for(var i=start; i<Math.min(users.length,start+250); i++) {
    55.         checkUser(users[i], Math.min(users.length,start+250));
    56.     }
    57. }
    58.  
    59. function checkUser(user, end) {
    60.     if (!stop) {
    61.        GM_xmlhttpRequest({
    62.            method: "GET",
    63.         url: "http://www.neopets.com/reg/process_index.phtml?r=265&dowhat=check_availability&username=" + user + "&destination=dailydare",
    64.            onload: function(result) {
    65.             checkCount++;
    66.                if (result.responseText.indexOf("is available") > -1)
    67.                 checkerWindow.document.getElementById("outusers").value += user + "\n";
    68.                checkerWindow.document.getElementById("status").innerHTML = "Checked " + checkCount + " usernames so far";
    69.             if (checkCount == end && end != users.length) {
    70.                 checkInterval(end);
    71.             }
    72.         },
    73.         onerror: function(result) {
    74.             checkCount++;
    75.             // report the username that caused the error
    76.             checkerWindow.document.getElementById("errusers").value += user + "\n";
    77.             if (checkCount == end && end != users.length) {
    78.                 checkInterval(end);
    79.             }
    80.            }
    81.     });
    82.     }
    83. }
    84.  
    85. function cleanupListener() {
    86.     stop=1;
    87. }
     
  2. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    I guess the filter didn't work because we can see the forum this program came from :p
     
  3. Junior

    Junior Administrator
    Staff Member

    Joined:
    Nov 8, 2009
    Messages:
    3,350
    Likes Received:
    169
    Location:
    I come from a land down under! (Maaaate!)
    Filter doesn't work if posted inside a code box?? Interesting ;)...

    Out of curiosity, when did it stop working? And how does it not work?
     
  4. Phee

    Phee Moderator
    Staff Member

    Joined:
    Aug 18, 2007
    Messages:
    6,206
    Likes Received:
    101
    When I use it, nothing happens :/ A blank tab opens up. If you scan the code some content adn forms should pop up but nothing does.

    and we probably just didn't block neofreaks because it's pretty dead anyways.