Guest User

Untitled

a guest
Apr 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /**
  2. * "Happy Birthday Nenad" OpenSocial Script
  3. * UNTESTED
  4. * Probably won't work in most OpenSocial containers
  5. * due to privacy settings
  6. */
  7.  
  8. var NENADS_USER_ID = '<UserId>'; // eg. VIEWER
  9.  
  10. var req = opensocial.newDataRequest();
  11. var params = {};
  12.  
  13. params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.BIRTHDAY];
  14.  
  15. req.add(req.newFetchPersonRequest(NENADS_USER_ID, params), "nenad"));
  16. req.send(function(data) {
  17. var profileData = data.get("nenad").getData();
  18. var today = new Date();
  19. var birthday = profileData.getField(opensocial.Person.Field.BIRTHDAY);
  20. bithday = createDateObject(birthday);
  21. if (birthday.getDate() == today.getDate() && birthday.getMonth() == today.getMonth()) {
  22. alert("Dude seems like it's your big day. You better shout out a few drinks when you're back in the office!");
  23. } else {
  24. alert("Today is not your birthday!");
  25. }
  26. });
  27.  
  28. /**
  29. * Expects a dateStr like "31-12-2009"
  30. */
  31. function createDateObject(dateStr) {
  32. var dateObj = new Date();
  33. var dateArr = dateStr.split("-");
  34.  
  35. var day = dateArr[0];
  36. var month = dateArr[1] - 1; // (0 => January, 1 => February, ...)
  37. var year = dateArr[2];
  38.  
  39. with (dateObj) {
  40. setMonth(month);
  41. setDate(day);
  42. setYear(year);
  43. }
  44.  
  45. return dateObj;
  46. }
Add Comment
Please, Sign In to add comment