MCPcopy Create free account
hub / github.com/codecombat/codecombat / getScreenRefreshRate

Function getScreenRefreshRate

app/core/utils.js:1660–1691  ·  view source on GitHub ↗
(callback, runIndefinitely)

Source from the content-addressed store, hash-verified

1658 */
1659// https://ourcodeworld.com/articles/read/1390/how-to-determine-the-screen-refresh-rate-in-hz-of-the-monitor-with-javascript-in-the-browser
1660const getScreenRefreshRate = function (callback, runIndefinitely) {
1661 let requestId = null
1662 let callbackTriggered = false
1663 if (window.requestAnimationFrame == null) { window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame }
1664 const DOMHighResTimeStampCollection = []
1665
1666 const triggerAnimation = function (DOMHighResTimeStamp) {
1667 DOMHighResTimeStampCollection.unshift(DOMHighResTimeStamp)
1668 if (DOMHighResTimeStampCollection.length > 10) {
1669 const t0 = DOMHighResTimeStampCollection.pop()
1670 const fps = Math.floor((1000 * 10) / (DOMHighResTimeStamp - t0))
1671 if (!callbackTriggered) {
1672 callback.call(undefined, fps, DOMHighResTimeStampCollection)
1673 }
1674 if (runIndefinitely) {
1675 callbackTriggered = false
1676 } else {
1677 callbackTriggered = true
1678 }
1679 }
1680 requestId = window.requestAnimationFrame(triggerAnimation)
1681 }
1682
1683 window.requestAnimationFrame(triggerAnimation)
1684 // Stop after half second if it shouldn't run indefinitely
1685 if (!runIndefinitely) {
1686 window.setTimeout(function () {
1687 window.cancelAnimationFrame(requestId)
1688 return requestId = null
1689 }, 500)
1690 }
1691}
1692
1693const getProductUrl = function (product, url) {
1694 if ((product !== 'COCO') && (product !== 'OZ')) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected