From b75b7421e180b7a75bcd9d1c7cf4af08abc480f2 Mon Sep 17 00:00:00 2001 From: oc Date: Sun, 6 Jan 2019 02:40:41 +0800 Subject: [PATCH] getCookie & default username --- libs/core.js | 4 ++++ libs/events.js | 2 +- libs/utils.js | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/core.js b/libs/core.js index 01509964..52ba9a4a 100644 --- a/libs/core.js +++ b/libs/core.js @@ -1403,6 +1403,10 @@ core.prototype.clamp = function (x, a, b) { return core.utils.clamp(x, a, b); } +core.prototype.getCookie = function (name) { + return core.utils.getCookie(name); +} + ////// Base64加密 ////// core.prototype.encodeBase64 = function (str) { return core.utils.encodeBase64(str); diff --git a/libs/events.js b/libs/events.js index b206e47f..0a1f4d00 100644 --- a/libs/events.js +++ b/libs/events.js @@ -301,7 +301,7 @@ events.prototype.gameOver = function (ending, fromReplay, norank) { doUpload(""); } else { - doUpload(prompt("请输入你的ID:")); + doUpload(prompt("请输入你的ID:", core.getCookie('id'))); } }, function () { if (main.isCompetition) diff --git a/libs/utils.js b/libs/utils.js index 9557c912..32dcbddb 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -520,6 +520,11 @@ utils.prototype.clamp = function (x, a, b) { return Math.min(Math.max(x||0, min), max); } +utils.prototype.getCookie = function (name) { + var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); + return match?match[2]:null; +} + ////// Base64加密 ////// utils.prototype.encodeBase64 = function (str) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {