Skip to content

Commit

Permalink
feat: add back polyfills
Browse files Browse the repository at this point in the history
some browsers are alive, but already dead
  • Loading branch information
Candinya committed Sep 30, 2024
1 parent ebe76d5 commit a096755
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/js/kr-core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* 一些暴露给 DOM 交互使用的全局函数
*/
import scrollIntoView from "scroll-into-view-if-needed";

import "./kr-polyfill";

/**
* 核心的配置体,包一层防止全局变量命名导致的冲突
*/
Expand Down
24 changes: 24 additions & 0 deletions src/js/kr-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 2024 年快结束了, iOS 18 也升级了, Safari (Webkit) 依然不支持 requestIdleCallback() 。
*
* 需要注意的是,这不是一个完整意义上的实现,只是一个类似功能的简陋包装,以使运行在和这个函数有仇的浏览器内核上的网页的评论区能正常加载。
*/
// https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback
window.requestIdleCallback =
window.requestIdleCallback ||
function (handler) {
let startTime = Date.now();
return setTimeout(function () {
handler({
didTimeout: false,
timeRemaining: function () {
return Math.max(0, 50.0 - (Date.now() - startTime));
},
});
}, 1);
};
window.cancelIdleCallback =
window.cancelIdleCallback ||
function (id) {
clearTimeout(id);
};

0 comments on commit a096755

Please sign in to comment.