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. let formattedTime = '"' + time + '"; ""; "' + date.toISOString() + '"\r\n';
  21. formattedList += formattedTime;
  22. });
  23.  
  24. let file = createFile(formattedList);
  25. $download.attr("href", file).show();
  26. });
  27.  
  28. function createFile(text) {
  29. let data = new Blob([text], {type: "octet/stream"});
  30. let file = window.URL.createObjectURL(data);
  31. return file;
  32. };