diff --git a/app/electron/main.js b/app/electron/main.js index 014f3ce95..0e190a9ac 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -431,7 +431,7 @@ const initMainWindow = () => { }).then((response) => { setProxy(`${response.data.proxy.scheme}://${response.data.proxy.host}:${response.data.proxy.port}`, currentWindow.webContents).then(() => { // 加载主界面 - currentWindow.loadURL(getServer() + "/stage/build/app/?v=" + new Date().getTime()); + currentWindow.loadURL(getServer() + "/stage/build/app/?v=" + Date.now()); }); }); diff --git a/app/src/boot/globalEvent/event.ts b/app/src/boot/globalEvent/event.ts index ff37c1686..61db6c99a 100644 --- a/app/src/boot/globalEvent/event.ts +++ b/app/src/boot/globalEvent/event.ts @@ -127,7 +127,7 @@ export const initWindowEvent = (app: App) => { let time = 0; document.addEventListener("touchstart", (event) => { - time = new Date().getTime(); + time = Date.now(); // https://github.com/siyuan-note/siyuan/issues/6328 const target = event.target as HTMLElement; if (hasClosestByClassName(target, "protyle-icons") || @@ -147,7 +147,8 @@ export const initWindowEvent = (app: App) => { return; } // pad 端长按事件 - if (isIPad() && new Date().getTime() - time > 900) { + const currentTime = Date.now(); + if (isIPad() && currentTime - time > 900 && currentTime - time < 2000) { event.target.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, diff --git a/app/src/config/account.ts b/app/src/config/account.ts index 5864a0ce4..2a666d423 100644 --- a/app/src/config/account.ts +++ b/app/src/config/account.ts @@ -104,7 +104,7 @@ ${genSVGBG()} const renewHTML = `
${window.siyuan.languages.account6} - ${Math.max(0, Math.floor((window.siyuan.user.userSiYuanProExpireTime - new Date().getTime()) / 1000 / 60 / 60 / 24))} + ${Math.max(0, Math.floor((window.siyuan.user.userSiYuanProExpireTime - Date.now()) / 1000 / 60 / 60 / 24))} ${window.siyuan.languages.day} ${isIOS ? `${window.siyuan.languages.clickMeToRenew}` : `${window.siyuan.languages.clickMeToRenew}`}
`; @@ -392,7 +392,7 @@ ${renewHTML}
`; let token: string; let needCaptcha: string; captchaImgElement.addEventListener("click", () => { - captchaImgElement.setAttribute("src", getCloudURL("captcha") + `/login?needCaptcha=${needCaptcha}&t=${new Date().getTime()}`); + captchaImgElement.setAttribute("src", getCloudURL("captcha") + `/login?needCaptcha=${needCaptcha}&t=${Date.now()}`); }); const cloudRegionElement = element.querySelector("#cloudRegion") as HTMLSelectElement; diff --git a/app/src/layout/Model.ts b/app/src/layout/Model.ts index aed0ae80e..926925dba 100644 --- a/app/src/layout/Model.ts +++ b/app/src/layout/Model.ts @@ -90,7 +90,7 @@ export class Model { if (!this.ws) { // Inbox 无 ws return; } - this.reqId = process ? 0 : new Date().getTime(); + this.reqId = process ? 0 : Date.now(); this.ws.send(JSON.stringify({ cmd, reqId: this.reqId, diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.ts index 191473572..effef0dff 100644 --- a/app/src/menus/workspace.ts +++ b/app/src/menus/workspace.ts @@ -74,7 +74,7 @@ const editLayout = (layoutName?: string) => { window.siyuan.storage[Constants.LOCAL_LAYOUTS].find((layoutItem: ISaveLayout) => { if (layoutItem.name === layoutName) { layoutItem.name = value; - layoutItem.time = new Date().getTime(); + layoutItem.time = Date.now(); setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]); return true; } @@ -91,7 +91,7 @@ const editLayout = (layoutName?: string) => { window.siyuan.storage[Constants.LOCAL_LAYOUTS].find((layoutItem: ISaveLayout) => { if (layoutItem.name === layoutName) { layoutItem.name = value; - layoutItem.time = new Date().getTime(); + layoutItem.time = Date.now(); layoutItem.layout = getAllLayout(); layoutItem.filesPaths = window.siyuan.storage[Constants.LOCAL_FILESPATHS]; setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]); @@ -104,7 +104,7 @@ const editLayout = (layoutName?: string) => { if (item.name === value) { confirmDialog(window.siyuan.languages.save, window.siyuan.languages.exportTplTip, () => { item.layout = getAllLayout(); - item.time = new Date().getTime(); + item.time = Date.now(); item.filesPaths = window.siyuan.storage[Constants.LOCAL_FILESPATHS]; setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]); }); @@ -116,7 +116,7 @@ const editLayout = (layoutName?: string) => { } window.siyuan.storage[Constants.LOCAL_LAYOUTS].push({ name: value, - time: new Date().getTime(), + time: Date.now(), layout: getAllLayout(), filesPaths: window.siyuan.storage[Constants.LOCAL_FILESPATHS] }); diff --git a/app/src/mobile/settings/account.ts b/app/src/mobile/settings/account.ts index df6f83ef8..a5debe5dd 100644 --- a/app/src/mobile/settings/account.ts +++ b/app/src/mobile/settings/account.ts @@ -62,7 +62,7 @@ export const showAccountInfo = () => { const renewHTML = `
${window.siyuan.languages.account6} - ${Math.max(0, Math.floor((window.siyuan.user.userSiYuanProExpireTime - new Date().getTime()) / 1000 / 60 / 60 / 24))} + ${Math.max(0, Math.floor((window.siyuan.user.userSiYuanProExpireTime - Date.now()) / 1000 / 60 / 60 / 24))} ${window.siyuan.languages.day} ${isIOS ? `${window.siyuan.languages.clickMeToRenew}` : `${window.siyuan.languages.clickMeToRenew}`}
`; @@ -310,7 +310,7 @@ const bindLoginEvent = (modelMainElement: HTMLElement, deactive = false) => { }); } captchaImgElement.addEventListener("click", () => { - captchaImgElement.setAttribute("src", getCloudURL("captcha") + `/login?needCaptcha=${needCaptcha}&t=${new Date().getTime()}`); + captchaImgElement.setAttribute("src", getCloudURL("captcha") + `/login?needCaptcha=${needCaptcha}&t=${Date.now()}`); }); const cloudRegionElement = modelMainElement.querySelector("#cloudRegion") as HTMLSelectElement; diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 3ac2124f5..ebfe0c4d9 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -405,7 +405,7 @@ export class Title { this.element.querySelector(".protyle-attr").insertAdjacentHTML("beforeend", `
${response.data.refCount}
`); } // 存在设置新建文档名模板,不能使用 Untitled 进行判断,https://ld246.com/article/1649301009888 - if (this.editElement && new Date().getTime() - dayjs(response.data.id.split("-")[0]).toDate().getTime() < 2000) { + if (this.editElement && Date.now() - dayjs(response.data.id.split("-")[0]).toDate().getTime() < 2000) { const range = this.editElement.ownerDocument.createRange(); range.selectNodeContents(this.editElement); focusByRange(range); diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index 67c5264f7..31ce96ac7 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -72,7 +72,7 @@ export class Protyle { this.protyle = { getInstance: () => this, app, - transactionTime: new Date().getTime(), + transactionTime: Date.now(), id: genUUID(), disabled: false, updated: false, diff --git a/app/src/protyle/render/av/date.ts b/app/src/protyle/render/av/date.ts index 41d166789..32ab3bfc2 100644 --- a/app/src/protyle/render/av/date.ts +++ b/app/src/protyle/render/av/date.ts @@ -5,7 +5,7 @@ export const getDateHTML = (cellElements: HTMLElement[]) => { const cellValue = genCellValueByElement("date", cellElements[0]).date; const isNotTime = cellValue.isNotTime; let value = ""; - const currentDate = new Date().getTime(); + const currentDate = Date.now(); if (cellValue.isNotEmpty) { value = dayjs(cellValue.content).format(isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm"); const year = value.split("-")[0]; @@ -84,7 +84,7 @@ export const bindDateEvent = (options: { inputElements[2].addEventListener("change", () => { if (inputElements[2].checked) { if (!inputElements[1].dataset.value) { - const currentDate = new Date().getTime(); + const currentDate = Date.now(); inputElements[1].dataset.value = dayjs(currentDate).format("YYYY-MM-DD HH:mm"); inputElements[1].value = dayjs(currentDate).format(inputElements[3].checked ? "YYYY-MM-DD HH:mm" : "YYYY-MM-DD"); } diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index cbbf6a098..c453f7496 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -1380,7 +1380,7 @@ export const transaction = (protyle: IProtyle, doOperations: IOperation[], undoO const lastTransaction = window.siyuan.transactions[window.siyuan.transactions.length - 1]; let needDebounce = false; - const time = new Date().getTime(); + const time = Date.now(); if (lastTransaction && lastTransaction.doOperations.length === 1 && lastTransaction.doOperations[0].action === "update" && doOperations.length === 1 && doOperations[0].action === "update" && lastTransaction.doOperations[0].id === doOperations[0].id && diff --git a/app/src/search/util.ts b/app/src/search/util.ts index 587bc0bc9..fcb62415c 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -282,7 +282,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele } } let clickTimeout: number; - let lastClickTime = new Date().getTime(); + let lastClickTime = Date.now(); searchInputElement.value = config.k || ""; replaceInputElement.value = config.r || ""; @@ -803,7 +803,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele let isDblClick = event.detail === 2; /// #if BROWSER if (isIPad()) { // 需要进行 ipad 判断 https://github.com/siyuan-note/siyuan/issues/12704 - const newDate = new Date().getTime(); + const newDate = Date.now(); isClick = newDate - lastClickTime > Constants.TIMEOUT_DBLCLICK; isDblClick = !isClick; lastClickTime = newDate; diff --git a/app/src/util/fetch.ts b/app/src/util/fetch.ts index 5efb55539..2b1077762 100644 --- a/app/src/util/fetch.ts +++ b/app/src/util/fetch.ts @@ -17,7 +17,7 @@ export const fetchPost = ( if (data) { if (["/api/search/searchRefBlock", "/api/graph/getGraph", "/api/graph/getLocalGraph", "/api/block/getRecentUpdatedBlocks", "/api/search/fullTextSearchBlock"].includes(url)) { - window.siyuan.reqIds[url] = new Date().getTime(); + window.siyuan.reqIds[url] = Date.now(); if (data.type === "local" && url === "/api/graph/getLocalGraph") { // 当打开文档A的关系图、关系图、文档A后刷新,由于防止请求重复处理,文档A关系图无法渲染。 } else { @@ -26,7 +26,7 @@ export const fetchPost = ( } // 并发导出后端接受顺序不一致 if (url === "/api/transactions") { - data.reqId = new Date().getTime(); + data.reqId = Date.now(); } if (data instanceof FormData) { init.body = data;