AtCoderLeftShiftOverflowWarning

Warn you when you write `1 << x` on AtCoder.

Stan na 18-05-2025. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         AtCoderLeftShiftOverflowWarning
// @namespace    https://github.com/AwashAmityOak
// @version      0.1.0
// @description  Warn you when you write `1 << x` on AtCoder.
// @author       AwashAmityOak
// @license      MIT
// @match        https://atcoder.jp/contests/*/tasks/*
// @match        https://atcoder.jp/contests/*/submit*
// @grant        unsafeWindow
// @copyright    2025 AwashAmityOak (https://github.com/AwashAmityOak)
// ==/UserScript==

(function() {
    'use strict';

    const $ = unsafeWindow.$;

    ace.edit("editor").addEventListener("change", () => {
        const button = $("#submit");

        const lang = $("#select-lang select[name='data.LanguageId']");
        if (lang.find(":selected").text().indexOf("C++") == -1) return;

        const code = ace.edit("editor").getValue();

        if (/(?<!<<\s*)(?<![a-zA-Z_])\d+\s*<</.test(code)) {
            let br = $("<br>");
            let span = $("<span>⚠️左シフトオーバーフロー</span>");
            br.addClass("AtCoderLeftShiftOverflowNotifier");
            span.addClass("AtCoderLeftShiftOverflowNotifier");

            if (!$("br.AtCoderLeftShiftOverflowNotifier").length) button.append(br);
            if (!$("span.AtCoderLeftShiftOverflowNotifier").length) button.append(span);

            button.css("backgroundColor", "#cc3333");
            button.css("borderColor", "#cc3333");
        } else {
            $(".AtCoderLeftShiftOverflowNotifier").remove();
            button.css("backgroundColor", "");
            button.css("borderColor", "");
        }
    });
})();