Greasy Fork

来自缓存

Greasy Fork is available in English.

ACM Online Judge 评测状态自动刷新

在评测时监测,并在评测完成后自动刷新评测状态

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name ACM Online Judge 评测状态自动刷新
// @namespace https://ns.altk.org/userscript
// @description 在评测时监测,并在评测完成后自动刷新评测状态
// @include https://acm.sjtu.edu.cn/OnlineJudge/code*
// @version 0.1
// @grant none
// @license GPL-3.0
// ==/UserScript==

; {

const STATUS_SELECTOR = '#status_list tbody td:nth-child(4)'
const PENDING_REGEXP = /Running & Judging|Pending/i
const REFRESH_INTERVAL = 2000
const REFRESH_TIMEOUT = 5000

const isPending = (doc = document) => PENDING_REGEXP.test(doc.querySelector(STATUS_SELECTOR).innerText)
const delay = ms => new Promise(resolve => setTimeout(resolve, ms, true))

const monitor = async () => {
  while (true) {
    await delay(REFRESH_INTERVAL)
    const xhr = new XMLHttpRequest()
    xhr.open('GET', location.href)
    xhr.responseType = 'document'
    const response = new Promise((resolve, reject) => {
      setTimeout(reject, REFRESH_TIMEOUT, 'Timeout exceeded.')
      xhr.onload = () => resolve(xhr.responseXML)
      xhr.onerror = reject
    })
    xhr.send()
    try {
      const doc = await response
      if (!isPending(doc)) {
        location.reload()
        return
      }
    } catch (e) {
      sweetAlert('ACMOJ Helper: Network Error', `${e}`, 'error')
    }
  }
}

if (isPending()) monitor()
else console.log('[ACMOJ Helper] Not pending, not monitoring.')

}