Export times from Cube Timer

Exports a list of times to import on Twisty Timer

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Export times from Cube Timer
// @namespace   cubetimer
// @description Exports a list of times to import on Twisty Timer
// @include     http://www.cubetimer.com/
// @author      SoKeT
// @version     1
// ==/UserScript==

let selector = "body > table:nth-child(3) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)";
let $container = $(selector);
let $button = $("<button id='export-times'>Export times</button>").appendTo($container);;
let $download = $("<a id='download' download='times.txt' style='display: block'>Download</a>").appendTo($container).hide();

$button.click(function() {
  let formattedList = "";
  
  $.each(time_list, function(index, value) {
    let time = Math.floor((value / 1000) * 100) / 100;
    let date = new Date();
    date.setSeconds(date.getSeconds() - (time_list.length - index) * 30);
    let formattedTime = '"' + time + '"; ""; "' + date.toISOString() + '"\r\n';
    formattedList += formattedTime;
  });

  let file = createFile(formattedList);
  $download.attr("href", file).show();
  console.log(formattedList);
});

function createFile(text) {
  let data = new Blob([text], {type: "octet/stream"});
  let file = window.URL.createObjectURL(data);
  return file;
};