Export times from Cube Timer

Exports a list of times to import on Twisty Timer

当前为 2017-09-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Export times from Cube Timer
  3. // @namespace cubetimer
  4. // @description Exports a list of times to import on Twisty Timer
  5. // @include http://www.cubetimer.com/
  6. // @author SoKeT
  7. // @version 1
  8. // ==/UserScript==
  9.  
  10. let selector = "body > table:nth-child(3) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)";
  11. let $container = $(selector);
  12. let $button = $("<button id='export-times'>Export times</button>").appendTo($container);;
  13. let $download = $("<a id='download' download='times.txt' style='display: block'>Download</a>").appendTo($container).hide();
  14.  
  15. $button.click(function() {
  16. let formattedList = "";
  17. $.each(time_list, function(index, value) {
  18. let time = Math.floor((value / 1000) * 100) / 100;
  19. let date = new Date();
  20. date.setSeconds(date.getSeconds() - (time_list.length - index) * 30);
  21. let formattedTime = '"' + time + '"; ""; "' + date.toISOString() + '"\r\n';
  22. formattedList += formattedTime;
  23. });
  24.  
  25. let file = createFile(formattedList);
  26. $download.attr("href", file).show();
  27. console.log(formattedList);
  28. });
  29.  
  30. function createFile(text) {
  31. let data = new Blob([text], {type: "octet/stream"});
  32. let file = window.URL.createObjectURL(data);
  33. return file;
  34. };