Tatoeba Merge Log with Comments

Places the log entries between the respective comments chronologically

  1. // ==UserScript==
  2. // @name Tatoeba Merge Log with Comments
  3. // @namespace Jakob V. <jakov@gmx.at>
  4. // @description Places the log entries between the respective comments chronologically
  5. // @include http://anonymouse.org/cgi-bin/anon-www_de.cgi/http://tatoeba.org/*
  6. // @include http://tatoeba.org/*
  7. // @require http://code.jquery.com/jquery-1.5.js
  8. // @version 0.0.1.20150423134444
  9. // ==/UserScript==
  10.  
  11. $(document).ready(function(){
  12. GM_log('ready');
  13. $changes = $(".annexeLogEntry");
  14. $changes.each(function(){
  15. text = $(this).find('div:first ').text().split('-').pop().trim();
  16. console.log(text);
  17. textdate_arr = text.match(/(\w{3}) (\d{1,2})\w+? (\d\d\d\d), (\d\d):(\d\d)/);
  18. if(textdate_arr){
  19. months_arr = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  20. date = new Date(1*textdate_arr[3],1*months_arr.indexOf(textdate_arr[1]),1*textdate_arr[2],1*textdate_arr[4],1*textdate_arr[5]);
  21. console.log(date);
  22. }
  23. else{
  24. languages_arr = [
  25. /deu|vor (\d+) Minuten|vor (\d+) Stunde\(n\)|vor (\d+) Tag\(en\)|(Datum unbekannt)/,
  26. /eng|(\d+) mn ago|(\d+) hour\(s\) ago|(\d+) day\(s\) ago|(date unknown)/,
  27. /spa|hace (\d+) minutos|hace (\d+) hora\(s\)|hace (\d+) día\(s\)|(fecha desconocida)/,
  28. /epo|antau (\d+) minutoj|antaŭ (\d+) horo\(j\)|antaŭ (\d+) tago\(j\)|(dato nekonata)/,
  29. /eus|duela (\d+) hilabete|duela (\d+) ordu|duela (\d+) egun|(Data, eguna, ezezaguna)/,
  30. /fre|il y a (\d+) mn|il y a (\d+) heure\(s\)|il y a (\d+) jour\(s\)|(date inconnue)/,
  31. /ita|(\d+) minuto\/i fa|(\d+) ora\/e fa|(\d+) giorno\/i fa|(data sconosciuta)/,
  32. /hun|(\d+) perce|(\d+) órája|(\d+) nappal ezelőtt|(ismeretlen dátum)/,
  33. /nds|vör (\d+) Minuten|vör (\d+) Stünn\(en\)|vör (\d+) Daag|(Datum nich kennt)/,
  34. /pol|(\d+) minut temu|(\d+) godzin temu|(\d+) dni temu|(data nieznana)/,
  35. /pt_BR|(\d+) minuto\(s\) atrás|(\d+) hora\(s\) atrás|(\d+) dias\(s\) atrás|(Data desconhecida)/,
  36. /tgl|(\d+) minuto nakaraan|(\d+) oras nakaraan|(\d+) araw nakaraan|(Hindi tiyak ang petsa)/,
  37. /tur|(\d+) dakika önce|(\d+) saat önce|(\d+) gün önce|(tarih bilinmiyor)/,
  38. /rus|(\d+) мин. назад|(\d+) ч. назад|(\d+) д. назад|(дата неизвестна)/,
  39. /ara|منذ (\d+) دقيقة \(دقائق\)|منذ (\d+) ساعة \(ساعات\)|منذ (\d+) يوم \(أيام\)|(التاريخ غير معروف)/,
  40. /chi|(\d+)分钟前|(\d+)小时前|(\d+)天前|(未知日期)/,
  41. /jpn|(\d+)分前|(\d+)時間前|(\d+)日前|(日付不明)/,
  42. ];
  43. $.each(languages_arr, function(ind, val){
  44. textdate_arr = text.match(val);
  45. if(textdate_arr){
  46. console.log(textdate_arr);
  47. if(textdate_arr[4]){
  48. date = new Date(0);
  49. }
  50. else {
  51. date = new Date(new Date()-(textdate_arr[1]||0)*60*1000-(textdate_arr[2]||0)*60*60*1000-(textdate_arr[3]||0)*24*60*60*1000);
  52. }
  53. console.log(date);
  54. }
  55. });
  56. }
  57. });
  58. });