Advertisement
tragikos

trains

Jun 2nd, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Student's trains
  3. // @namespace    http://steamcommunity.com/id/tragikos/
  4. // @version      0.3
  5. // @description  A button that sets the correct ending time for your giveaway according to your timezone
  6. // @author       tragikos
  7. // @match        http://www.steamgifts.com/giveaways/new
  8. // @grant        none
  9. // @run-at       document-end
  10. // ==/UserScript==
  11.  
  12. var startDateUTC = '6/5/2015 00:00:00 UTC'; // 5th of June
  13. var eventDateUTC = '6/15/2015 00:00:00 UTC'; // 15th of June
  14. var startingTimeMinOffset = 5;
  15. var groupId = "1898";
  16. var description="##My giveaway train  \n\n----------------  \n\n";
  17.  
  18. function formatDate(date) {
  19.     var formattedDate = $.datepicker.formatDate('M d, yy', date);
  20.     var hours = date.getHours()%12 < 10 ? '0'+date.getHours()%12 : date.getHours()%12;
  21.     var minutes = date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes();
  22.     var ampm = date.getHours() >= 12 ? 'pm' : 'am';
  23.     formattedDate += " " + hours + ":" + minutes + " " + ampm;
  24.    
  25.     return formattedDate;
  26. }
  27.  
  28. function applyDates() {
  29.     var startDate = new Date(startDateUTC)
  30.     $("input[name='start_time']").val(formatDate(startDate));
  31.    
  32.     var endDate = new Date(eventDateUTC);
  33.     $("input[name='end_time']").val(formatDate(endDate));
  34. }
  35.  
  36. function applyRegionRestrictions() {
  37.     $("div[data-checkbox-value='0']").trigger("click");
  38. }
  39.  
  40. function applyGroup() {
  41.     $("div[data-checkbox-value='invite_only']").trigger("click");
  42. }
  43.  
  44. function applyGenericDescription(){
  45.     var newDesc = description + $("textarea[name='description']").val().replace(description, "");
  46.     $("textarea[name='description']").val(newDesc);
  47. }
  48.  
  49. $(".form__time-container").children('div').eq(1).after('<div id="dateBtn" class="form__submit-button js__submit-form"><i class="fa fa-arrow-circle-right"></i> My Train</div>');
  50. $("#dateBtn").css({
  51.     'height': '32px'
  52. });
  53.  
  54. $("#dateBtn").click(function() {
  55.     applyDates();
  56.     applyRegionRestrictions();
  57.     applyGroup();
  58.     applyGenericDescription();
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement