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++
- 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.
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.2.1/languages/{language of interest}.min.js
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;
}