Advertisement
Songs0fFailure

What.CD : Relative to Absolute Time [UTC +4]

Nov 3rd, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @id             whatcd-absolute-time
  3. // @name           What.CD : Relative to Absolute Time
  4. // @version        1.5
  5. // @namespace      hateradio)))
  6. // @author         hateradio
  7. // @description    Changes the relative time format to an absolute date.
  8. // @homepage       http://userscripts.org/scripts/show/121372
  9. // @include        http*://*what.cd/*
  10. // ==/UserScript==
  11.  
  12. var timezone = 60*60*1000*4;
  13. var timeChange = {
  14.     f : 'date-month-year, [hour:min]',
  15.     t : document.querySelectorAll('.time'),
  16.     m : ['Янв.' , 'Фев.' , 'Мар.' , 'Апр.' , 'Май' , 'Июн.' , 'Июл.' , 'Авг.' , 'Сен.' , 'Окт.' , 'Ноя.' , 'Дек.'],
  17.     d : ['Sun', 'Mon' , 'Tues' , 'Weds' , 'Thurs' , 'Fri' , 'Sat'],
  18.     now : function(){
  19.         var i = this.t.length, t, f;
  20.         while(i--){
  21.             t = this.t[i];
  22.             f = new Date(t.title);
  23.             f.setTime(Date.parse(f)+timezone);
  24.             t.title = t.textContent;
  25.             t.textContent = this.s(f);
  26.         }
  27.     },
  28.     s : function(date){
  29.             var a = this.f.split(/\W/).reverse(), i = a.length, d, s = this.f;
  30.             while(i--){
  31.                 d = a[i];
  32.                 switch(d){
  33.                     case 'date' : s = s.replace('date', date.getDate()); break;
  34.                     //case 'day' : s = s.replace('day', this.d[date.getDay()]); break;
  35.                     case 'year' : s = s.replace('year', date.getFullYear()); break;
  36.                     case 'hour' : if(date.getHours()<=9){s = s.replace('hour', "0"+date.getHours())} else {s = s.replace('hour', date.getHours())}; break;
  37.                     case 'min' : if(date.getMinutes()<=9){s = s.replace('min', "0"+date.getMinutes())} else {s = s.replace('min', date.getMinutes())}; break;
  38.                     case 'month' : s = s.replace('month', this.m[date.getMonth()]); break;
  39.                     default : break;
  40.                 }
  41.             }
  42.             return s;
  43.     }
  44. };
  45.  
  46. timeChange.now();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement