AtCoderLeftShiftOverflowWarning

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

2025-05-18 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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", "");
        }
    });
})();