AtCoder Better Highlighter

Better syntax highlighting for AtCoder using highlight.js.

As of 2020-10-18. See the latest version.

Author
shouth
Ratings
0 0 0
Version
0.5.3
Created
2020-10-10
Updated
2020-10-18
Size
4.87 KB
License
N/A
Applies to

AtCoder Better Highlighter

This is a script that replaces the code in the AtCoder submission results page with the highlighted one using highlight.js.

Language to be replaced by default

  • Bash
  • C
  • C++
  • C#
  • Go.
  • Java
  • JavaScript
  • Kotlin
  • Objective-C
  • PHP
  • Perl
  • Python
  • Ruby
  • Rust
  • Swift
  • TypeScript

To replace codes in a language other than the above

First, let's open the script's edit screen. There are two ways to do this.

Method 1: Adding a dependency library

Copy the URL of the script for the language you want to replace from the list at https://cdnjs.com/libraries/highlight.js. Next, find this line in the top of the script.

// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/highlight.min.js

Then add the line below after the line above. Replace {copied URL here} with the URL you just copied.

// @require {copied URL here}

Method 2 Using eval().

By this method, you can replace codes whose languages is supported by highlight.js. However, as is well known, there are dangers in the use of eval(). Be careful of using this method.

Find these lines near line 84.

    if (!hljs.getLanguage(name)) {
        // const response = await fetch(`https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/languages/${name}.min.js`);
        // eval(await response.text());
        return;
    }

Then rewrite them as follows.

    if (!hljs.getLanguage(name)) {
        const response = await fetch(`https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/languages/${name}.min.js`);
        eval(await response.text());
        // return;
    }

To use another themes

By default, default.css of highlight.js is used. To change the theme to another, copy the URL of the css of the theme you want to use from the list at https://cdnjs.com/libraries/highlight.js . Next, find this line in the top of the script.

// @resource css https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/styles/default.min.css

Then replace the line above with the line below. Replace {copied URL here} with the URL you just copied.

// @resource css {copied URL here}