Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var daysFromLastVisit = 7; // Change this and only this to modify the cutoff date.
  2. var cutoffDate = new Date(); // Gets current date
  3. var AmericanDateFormat=true; //Set to true for American Date Format (Month/Day/Year), false for (Day/Month/Year)
  4. cutoffDate.setHours(0,0,0,0); // setting the current date to a plain date, without the hour and such. This could cause problems otherwise.
  5. cutoffDate.setDate(cutoffDate.getDate() - daysFromLastVisit); // Specs say this should work everywhere. In doubt, use Chrome or Firefox.
  6.  
  7. var usernamesArray = document.getElementsByClassName('nobold'); // This will probably break with any site updates.
  8.  
  9. // Output strings
  10. var hasVisited = '';
  11. var hasntVisited = '';
  12.  
  13. if (usernamesArray.length == 0){
  14.     console.log("NO USERS DETECTED, THE SITE HAD A LAYOUT UPDATE"); // Adding a warning, just in case
  15. }else{
  16.     for(var i=0; i < usernamesArray.length; i++){
  17.         var username = usernamesArray[i].innerHTML; // Grabs username
  18.         var AMURICAdateText = usernamesArray[i].parentNode.parentNode.lastChild.innerHTML.trim(); // Does some DOM magic to get the date. This will probably break when the site updates.
  19.         var hasVisitedRecently = false; // This is set to true only if the user has visited, after all that code.
  20.  
  21.  
  22.         if(AMURICAdateText != ''){ // If the user has visited the board at least once. I don't feel particularly confident when checking against an empty string, this is very prone to breaking but it works for the current version of the admin page.
  23.             // Start code to fix the date to a standard format because AMURICA
  24.             var splitDate = AMURICAdateText.split('/'); // splits '11/18/14' into ['11', '18', '14']
  25.             if(AmericanDateFormat){
  26.             var outputDate = splitDate[0]+'/'+splitDate[1]+'/20'+splitDate[2]; // Switches month and day around. Will break when 2100 comes.
  27.             }else{
  28.                 var outputDate = splitDate[1]+'/'+splitDate[0]+'/20'+splitDate[2]; // Switches month and day around. Will break when 2100 comes.
  29.             }
  30.             // End AMURICA code
  31.  
  32.             // This has to be done manually as I don't trust at all that different browsers will parse a non ISO date correctly.
  33.             var lastVisitDateObject = new Date();
  34.             lastVisitDateObject.setHours(0,0,0,0); // Plain date, no hours.
  35.             lastVisitDateObject.setFullYear('20'+splitDate[2]);
  36.             lastVisitDateObject.setMonth(splitDate[0] - 1); // WHY THE **** MONTH IS 0-11 WHEN DAY IS 1-31
  37.             lastVisitDateObject.setDate(splitDate[1]);
  38.  
  39.             if(lastVisitDateObject.toString() == 'NaN'){ // Just doing some housekeeping, this should never happen but if GF screws up you'll be warned
  40.                 var lastVisitDate = "ERROR";
  41.             }else{
  42.                 if(cutoffDate <= lastVisitDateObject){
  43.                     hasVisitedRecently = true; // Whew. Done.
  44.                 }; 
  45.             };
  46.         }else{
  47.             var outputDate = "Hasn't visited the board";
  48.         };
  49.        
  50.         if(hasVisitedRecently){
  51.             hasVisited += (username + ' @ ' + outputDate + "\n");
  52.         }else{
  53.             hasntVisited += (username + ' @ ' + outputDate + "\n");
  54.         };
  55.     };
  56.  
  57.     // The following generates a textarea and fills it with the output.
  58.     var textareaVisited = document.createElement('textarea');
  59.     textareaVisited.style.width = '49%';
  60.     textareaVisited.style.height = '300px';
  61.     textareaVisited.innerHTML = "Users who visited in the last "+daysFromLastVisit+" days:\n" + hasVisited;
  62.     var textareaNotVisited = document.createElement('textarea');
  63.     textareaNotVisited.style.width = '49%';
  64.     textareaNotVisited.style.height = '300px';
  65.     textareaNotVisited.innerHTML = "Users who did NOT visit in the last "+daysFromLastVisit+" days:\n" + hasntVisited;
  66.     // The following adds it to the page.
  67.     var userTable = document.getElementsByClassName('board')[0];
  68.     var parentDiv = userTable.parentNode;
  69.     parentDiv.insertBefore(textareaVisited, userTable);
  70.     parentDiv.insertBefore(textareaNotVisited, userTable);
  71. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement