ac-standings-notifier

AtCoder のコンテスト中に順位表を開いておくと,順位を自動で通知します.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ac-standings-notifier
// @namespace    http://github.com/rsk0315
// @version      0.1.1
// @description  AtCoder のコンテスト中に順位表を開いておくと,順位を自動で通知します.
// @author       rsk0315
// @match        https://beta.atcoder.jp/contests/*/standings
// @match        https://beta.atcoder.jp/contests/*/standings/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // My code here...
    if (!('Notification' in window)) return;
    if (startTime === undefined) return;

    var permission = Notification.permission;
    if (permission === 'denied') return;
    Notification.requestPermission().then(function() {
        if (endTime.isBefore()) return;
        var jsonURL = window.location.href.replace(/\/+$/, '')+'/json';
        console.log(jsonURL);

        var id = setInterval(function() {
            if (startTime.isAfter()) return;
            if (endTime.isBefore()) {
                clearInterval(id);
                return;
            }

            $.ajax({
                type: 'GET',
                url: jsonURL,
                cache: false,
            }).done(function(data) {
                var standingsData = data.StandingsData;
                var numContestants = standingsData.length;
                var myRank = undefined;
                var lowestRank = data.StandingsData[numContestants-1].Rank;
                $.each(data.StandingsData, function(i, item) {
                    if (myRank !== undefined) return;
                    if (item.UserScreenName == userScreenName) {
                        myRank = item.Rank;
                    }
                });
                new Notification('current rank: '+myRank+' / '+lowestRank+' ('+numContestants+')');
            });
            // 5 分ごとに現在の順位,最低順位,参加人数を通知します.
        }, 5*60*1000);
    });
})();