Git Product home page Git Product logo

competitive-companion's Introduction

Competitive Companion

Build Status
Chrome Web Store Version Chrome Web Store Users Chrome Web Store Rating
Mozilla Add-on Version Mozilla Add-on Users Mozilla Add-on Rating

A browser extension which parses competitive programming problems from various online judges (like AtCoder and Codeforces) and sends them to various tools (like CP Editor and CPH). Capable of parsing problems and contests and extracting data like the example testcases and the time and memory constraints.

Install

Supported tools

Supported websites

Website Problem parser Contest parser
A2 Online Judge
ACMP
AcWing
Aizu Online Judge
AlgoZenith
Anarchy Golf
AtCoder
Baekjoon Online Judge
BAPS OJ
beecrowd
Bloomberg CodeCon
BUCTOJ
CodeChef
CodeDrills
Codeforces
CodeMarshal
COJ
Contest Hunter
CPython.uz
CS Academy
CSES
CSU-ACM Online Judge
Daimayuan Online Judge
Dimik OJ
DMOJ
DOMjudge
Eolymp
ECNU Online Judge
FZU Online Judge
Google Coding Competitions
HackerEarth
HackerRank
HDOJ
HIT Online Judge
hihoCoder
HKOI Online Judge
Hrbust Online Judge
Hydro
ICPC Live Archive
ITCoder HUTECH
Jutge
Kattis
Lanqiao
Library Checker
LibreOJ
LightOJ
LSYOI
Luogu
Mendo
Meta Coding Competitions
MOI Arena
mrJudge
MSK Informatics
Neps Academy
Newton School
NOJ
NowCoder
NYTD Online Judge
omegaUp
OpenJudge
OTOG
Panda Online Judge
PEG Judge
POJ
PTA
Public Judge
QDUOJ
RoboContest
SDUT OnlineJudge
Sort Me
SPOJ
SSOIER
TheJobOverflow
Timus Online Judge
TLX
Toph
uDebug
UOJ
USACO
USACO Training
UVa Online Judge
Virtual Judge
Yandex
XXM
yukicoder
ZOJ
ZUFEOJ

Custom tools

Competitive Companion can send the parsed data in JSON format to your own tools. To do this, start an HTTP server listening for POST requests to / on any of the ports listed in ./src/hosts/hosts.ts. An example on how to accomplish this can be found in jmerle/competitive-companion-example.

If you want your own tool added to the released version of Competitive Companion, create an issue in this repository specifying the name and a link to the tool.

The format

Here's an example of the data sent when parsing Codeforces 954G:

{
    "name": "G. Castle Defense",
    "group": "Codeforces - Educational Codeforces Round 40 (Rated for Div. 2)",
    "url": "https://codeforces.com/problemset/problem/954/G",
    "interactive": false,
    "memoryLimit": 256,
    "timeLimit": 1500,
    "tests": [
        {
            "input": "5 0 6\n5 4 3 4 9\n",
            "output": "5\n"
        },
        {
            "input": "4 2 0\n1 2 3 4\n",
            "output": "6\n"
        },
        {
            "input": "5 1 1\n2 1 2 1 2\n",
            "output": "3\n"
        }
    ],
    "testType": "single",
    "input": {
        "type": "stdin"
    },
    "output": {
        "type": "stdout"
    },
    "languages": {
        "java": {
            "mainClass": "Main",
            "taskClass": "GCastleDefense"
        }
    },
    "batch": {
        "id": "123e67c8-03c6-44a4-a3f9-5918533f9fb2",
        "size": 1
    }
}

It's not required for a tool to parse all these options, since some of them are tool/language-specific. However, it is required for all extensions/tools that send data via this format to fill all required options.

Explanation

  • name: The full name of the problem. Can be used for display purposes.
  • group: Used to group problems together, which can be useful for archiving purposes. Follows the format <judge> - <category>, where the hyphen is discarded if the category is empty.
  • url: A link to the problem on the judge's website.
  • interactive (optional): Whether this is an interactive problem or not.
  • memoryLimit: The memory limit in MB.
  • timeLimit: The time limit in ms.
  • tests: An array of objects containing testcase data. The JSON objects in the array all have two keys: input and output. Both the input and the output need to end with a newline character.
  • testType: The type of the tests. Supports two options: "single" and "multiNumber". Explanation of these two can be found on the JHelper wiki.
  • input: An object which is used to configure how to receive input. Supported types:
    • stdin: Receive input via stdin. No additional options required.
    • file: Receive input via a file. The file name has to be given via the fileName option.
    • regex: Receive input via a file. The file to use is selected by taking the most recently modified that matches the given regex. The regex pattern to use has to be given via the pattern option.
  • output: An object which is used to configure how to send output. Supported types:
    • stdout: Send output to stdout. No additional options required.
    • file: Send output to a file. The file name has to be given via the fileName option.
  • languages: An object with language specific settings. At the moment this only contains Java settings, but since I don't think putting language specific settings as top-level options is a good idea, I decided to put them in an object. This also allows for other languages to have custom configuration added later on. Required keys:
    • java: An object with Java specific settings. Required options:
      • mainClass: The name of the outer class containing the solution.
      • taskClass: The classname-friendly version of the problem's full name. Cannot be the same as mainClass. Can also be useful for non-Java tools because a classname-friendly string is also a filename-friendly string.
  • batch: An object containing information about the batch of problems that this problem belongs to. Required options:
    • id: A UUIDv4 string which uniquely identifies a batch. All problems in a batch have the same batch id.
    • size: The size of the batch, which is 1 when using a problem parser and the amount of problems in the contest when using a contest parser.

Running locally

The following commands can be used to start working on Competitive Companion locally. Additionally, make sure you got Node.js and PNPM installed.

# Clone the repository
git clone https://github.com/jmerle/competitive-companion.git

# cd into the extension folder
cd competitive-companion

# Install the dependencies
pnpm install

# Decide what you want to do next

# Build the Chrome code to the build-chrome/ directory
pnpm build:chrome

# Build the Firefox code to the build-firefox/ directory
pnpm build:firefox

# Lint the extension for possible mistakes
pnpm lint

# Package the extension to ZIP files
pnpm package

# Does the same as dev:firefox but with Chrome, with the exception that the extension is not automatically reloaded
# You'll have to manually go to chrome://extensions and click on the reload button on the Competitive Companion entry
pnpm dev:chrome

# Launch a Firefox instance with Competitive Companion loaded into a temporary profile
# Automatically re-compiles the code when the source changes
# Automatically reloads the extension in the Firefox instance when the code is re-compiled
pnpm dev:firefox

Testing

To run the tests, use pnpm test, or pnpm test:no-headless to run tests with the Chrome instance visible. Append -- -t <pattern> to the command to only run tests with names matching the given pattern.

Mozilla reviewers

The information provided below is meant for Mozilla volunteers.

Software versions used:
Node.js: 20.12.1
PNPM: 8.15.6

Third-party libraries that can be found in the minified extension:

Package the extension by cd'ing into the source code submission directory, installing the dependencies with pnpm install and packaging with pnpm package:firefox. The result can be found in the dist/ directory.

competitive-companion's People

Contributors

adambenali avatar allenanswerzq avatar anandoza avatar anon-136 avatar champon1020 avatar chrisg661 avatar colazcy avatar dependabot[bot] avatar egorkulikov avatar entityplantt avatar fcottet avatar gandharvjain avatar jmerle avatar jvmusin avatar kessido avatar m1kit avatar mfornet avatar nabdulla1 avatar rogeryoungh avatar rohitzerofour avatar saurabh73 avatar smarttommyau avatar taodaling avatar tatsumack avatar thesobersobber avatar touhidurrr avatar user202729 avatar warshon avatar windyskr avatar zymooll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

competitive-companion's Issues

Adding support for kick start

Due it is supporting that new Code Jam interface , I don't think that should not complicate to add Google Kick Start.

please add https://algo.codemarshal.org/contests to this tool.

I have tried but that is not parsing the problem when I am clicking the '+' icon of 'Competitive Companion'.
Here is the code I have tried in CodeMarshalProblemParser.ts file in parsers/problem directory

import { Sendable } from '../../models/Sendable';
import { TaskBuilder } from '../../models/TaskBuilder';
import { htmlToElement } from '../../utils/dom';
import { Parser } from '../Parser';

export class CodeMarshalProblemParser extends Parser {
  public getMatchPatterns(): string[] {
    return ['https://algo.codemarshal.org/contests/*/problems/*'];
  }

  public async parse(url: string, html: string): Promise<Sendable> {
    const elem = htmlToElement(html);
    const task = new TaskBuilder().setUrl(url);

    const content = elem.querySelector('#main').querySelector('div').querySelector('div');

    task.setName(content.querySelector('div').textContent);

    const group = ['CodeMarshal'];

    task.setGroup(group.join(' - '));

    const scoreCpuTimeMemory = content.querySelector('p:first-of-type').textContent;
    let memory = scoreCpuTimeMemory.substr(scoreCpuTimeMemory.indexOf("Memory: ")+"Memory: ".length);
    memory = memory.substr(0, memory.length-2);
    const cpuTime = scoreCpuTimeMemory.substring(scoreCpuTimeMemory.indexOf("CPU: ")+"CPU: ".length, scoreCpuTimeMemory.indexOf("Memory: ")-1);

    task.setTimeLimit(parseInt(cpuTime, 10));
    task.setMemoryLimit(parseInt(memory, 10));

    const inputs = content.querySelectorAll(".sample-input");

    const outputs = content.querySelectorAll(".sample-output");

    for (let i = 0; i < inputs.length && i < outputs.length; i++) {
      const input = inputs[i].textContent;
      const output = outputs[i].textContent;

      task.addTest(input, output);
    }

    return task.build();
  }
}

Adding support for more than just CHelper

This issue is open to discussion, but is primarily meant to keep track of progress on this idea, and to serve as some sort of documentation.

CHelper Companion was originally designed to solely support CHelper, but it would be cool if it would be able to send tasks to other tools aswell. Therefore, I have been thinking about sending the task information as a JSON-encoded string. This makes it easier for other (private) tools to work with the extension, as long as it can parse JSON input from an HTTP request.

The format

Here's an example of possible input:

{
    "name": "The A + B problem",
    "group": "Educational Codeforces Round 42 (Rated for Div. 2)",
    "url": "http://codeforces.com/problemset/problem/962/G",
    "memoryLimit": 256,
    "timeLimit": 2000,
    "testType": "single",
    "input": {
        "type": "stdin"
    },
    "output": {
        "type": "stdout"
    },
    "languages": {
        "java": {
            "mainClass": "Main",
            "taskClass": "TheABProblem"
        }
    },
    "tests": [{
        "input": "1 2\n",
        "output": "3\n"
    }, {
        "input": "5 5\n",
        "output": "10\n"
    }]
}

It's not required for a tool to parse all these options, since some of them are tool/language-specific. However, it is required for all extensions/tools that send data via this format to fill all required options.

Explanation

  • name: The full name of the problem. Can be used for display purposes.
  • group: Used to group problems together, which can be useful for archiving purposes.
  • url: A link to the problem on the judge's website.
  • memoryLimit: The memory limit in MB.
  • timeLimit: The time limit in ms.
  • testType: The type of the tests. Supports three options: "single", "multiNumber" and "multiEOF". Explanation of these three can be found on the JHelper wiki. This is currently CHelper and JHelper specific.
  • input: An object which is used to configure how to receive input. Supported types:
    • stdin: Receive input via stdin. No additional options required.
    • file: Receive input via a file. The file name has to be given via the fileName option.
    • regex: Receive input via a file. The file to use is selected by taking the most recently modified that matches the given regex. The regex pattern to use has to be given via the pattern option.
  • output: An object which is used to configure how to send output. Supported types:
    • stdout: Send output to stdout. No additional options required.
    • file: Send output to a file. The file name has to be given via the fileName option.
  • languages: An object with language specific settings. At the moment this only contains Java settings, but since I don't think putting language specific settings as top-level options is a good idea, I decided to put them in an object. This also allows for other languages to have custom configuration added later on. Required keys:
    • java: An object with Java specific settings. Required options:
      • mainClass: The name of the outer class containing the solution.
      • taskClass: The classname-friendly version of the problem's full name. Cannot be the same as mainClass. Can also be useful for non-Java tools because a classname-friendly string is also a filename-friendly string.
  • tests: An array of objects containing testcase-data. The JSON objects in the array all have two keys: input and output. Both the input and the output need to end with a newline character.

Pro's

  • Being able to support more than just CHelper, even private tools as long as they can parse JSON input received via HTTP.
  • At the moment the extension would break if Egor changes the Kattis parser. A JSON parser would resolve this issue.

Cons

  • The extension would have to be renamed to something more general, since CHelper Companion implies it's only compatible with CHelper.

Tasks

  • Convert the problem and contest parsers that still rely on CHelper to a JavaScript implementation
  • Make all parsers parse the time limit of a problem
  • Add a JSON parser to CHelper
  • Add a JSON parser to JHelper
  • Add the functionality to Hightail to accept JSON input via HTTP and parse it
  • Make it possible to send the JSON data to multiple tools
  • Make it possible to send the JSON data to a custom port on localhost to support private tools
  • Create better documentation so it's easy for new tools to support the format
  • Create an example to show how to support receiving the JSON data in other (private) tools
  • Rename CHelper Companion to something more general (final step)

All changes on the extension relevant to this issue are done in the feature/universal branch.

2.8.0 broke AtCoder parsing for IntelliJ CHelper

Hi, during the AGC this morning, I was unable to use this extension to parse problems to CHelper. In IntelliJ, the Event Log said "CHelper: Unknown task type from Chrome parser: null"

After the contest I looked into it and saw there was an update recently, and installed 2.7.3 from this github -- and it worked again.

Add parser for Libre Online Judge

URL: https://loj.ac

Sample problem: 「IOI2019」Arranging Shoes

The sample tests are written in the <pre></pre> tags, I think it's usually safe to regard the first <pre></pre> tag as the first input, the second as the first output, the third as the second input…etc.

It will be better if only <pre></pre> in <h4 class="ui top attached block header">样例</h4> are considered.

Time limit: <span class="ui label">时间限制:1000 ms</span>

Memory limit: <span class="ui label">内存限制:1024 MiB</span>

Add parser for Luogu Online Judge

URL: https://www.luogu.com.cn/

Sample problem: [IOI2019]Arranging Shoes

Sample tests:

  • <div data-v-36768c72="" data-v-af321868="" class="sample-wrap sample" show-idx="true">
    • <div data-v-52f2d52f="" data-v-36768c72="" class="input">
    • <div data-v-52f2d52f="" data-v-36768c72="" class="output">

Time limit: <span data-v-83303c00="" class="value lfe-caption">1.00s</span>

Memory limit: <span data-v-83303c00="" class="value lfe-caption">125.00MB</span>

Unable to parse task on CodeJam new Platform

After the recent changes in the CodeJam environment, parser is not working at all. Can you please fix the issue as the new season of KickStart is starting on 24 March? Thanking You.

Add parser for Universal Online Judge

Problem example: http://uoj.ac/problem/3

The examples follow this format:

<h4>input</h4>
<pre>example</pre>
<h4>output</h4>
<pre>example</pre>

The TL and ML are a bit annoying, they are in MathJax:

时间限制:$3\texttt{s}$
空间限制:$512\texttt{MB}$

In http://uoj.ac/problem/492, the ML is 空间限制:$1\texttt{GB}$.

Hope you can solve this problem.

Also the contest: http://uoj.ac/contest/49

Problem in contest: http://uoj.ac/contest/49/problem/484

Parsing problems for HackerRank interview problems

It seems that the tool is having issues detecting the input for the problems in the interview preparation kit in HackerRank. The button in my Chrome browser does not even light up for such problems.

Here is a link to one such problem.

CodeJam parsing issue

I tried two problems during GCJ qual and both of them had equal name QualificationRound2019GoogleCodeJam2019 so I couldn't have two of them parsed in the same time.

Fails to read HackerRank multiple test cases

Hacker Rank - 30-conditional-statements/problem

{
  "group": "",
  "input": {
    "type": "stdin"
  },
  "languages": {
    "java": {
      "mainClass": "Main",
      "taskClass": "HackerRankTutorials30DaysOfCode"
    }
  },
  "memoryLimit": 512,
  "name": "HackerRank - Tutorials - 30 Days of Code",
  "output": {
    "type": "stdout"
  },
  "testType": "single",
  *"tests": []*,
  "timeLimit": 4000,
  "url": "https://www.hackerrank.com/challenges/30-conditional-statements/problem"
}

As the result provided above shows, it doesn't parse multiple test cases. This is because of css query used in HackerRank Parser.

I guess [class*="challenge-body-html"] pre query should work.

Small issue with the virtual judge parser for zoj problems

Hi!, first of all, thanks for your efforts to build this awesome extension, really saved a lot copy-pasting time.

My issue here is that the parser for zoj problems in vritual judge platform seems not working sometime. here is a picture showing this issue.

Add following links for you to verify, I was planning to fix by myself then to pull a request, but i didn't have any experience with node.js, so sad. :-) Have a nice day!
https://vjudge.net/problem/ZOJ-1586
https://vjudge.net/problem/ZOJ-1610
https://vjudge.net/problem/ZOJ-3209
https://vjudge.net/problem/ZOJ-3496

image

UVA Parsing not working

Problems from UVA OJ are not being parsed. The plugin lights up when I open a problem on UVA OJ. When I click on it, it turns grey but nothing happens. The plugin works for other sites though.

Here are examples of 2 problems where this problem occur:

Problem1

Problem2

I am using the Google Chrome browser with the plugin.

Contests are not parsed in full

First of all I wasn't sure whether to make this issue here or in CHelper/JHelper repo, as there seems to be a problem with both.

The problem

When parsing a full contest, I've noticed that the parsing stops after a number of tasks. It's not a problem with the parsing itself as the debug mode shows that they are all correctly parsed.

At first, it seemed like the problem happened with Google Chrome and on Windows only. Not on Firefox, and not on Linux. Using Chrome and Windows, the parsing always stops after exactly 6 tasks. But then, after some investigation, I've come to the conclusion that it depends on the number of problems to parse. I was able to reproduce these symptoms on Linux with Chrome as well with a large enough contest.

Fastest way to reproduce it: Try to parse a contest with more than 6 tasks on Windows using Chrome.

The cause

So I've done some investigation and for me there are two reasons for this.

  • First, the simple servers created by CHelper/JHelper do not make a response, so after acquiring the data from competitive companion, they sort of "hang".
  • Second, there is a timeout of 500ms set to the AJAX requests made to the server, which, on Chrome, results in all the requests still blocked after 500ms, to be canceled.

Why stop after exactly 6 tasks ? Because the maximum number of concurrent HTTP connections per hostname in Chrome and Firefox is 6. So the server processes the first 6 requests, and the subsequent ones are cancelled.

My suggestion

Ideally, the solution would be to make fewer AJAX calls by making one JSON with all the contest data, but that would break compatibility with the tools.
Otherwise, I would suggest to either remove the timeout of 500ms, provided that the tool's server always responds, or to increase it significantly. In both cases, the server has to respond in order not to block the following requests.

Why is the problem more explicit on Windows using Chrome ? Chrome on Windows seems to process AJAX calls slower than other browsers, something I still cannot understand. Maybe a bug ?
Here is a comparison between what happens making 10 AJAX requests on Chrome, on Windows and Linux. (The timeout for the calls is set to 5000ms)

Windows :
image

Linux :
image

Notice how the last 4 requests take more than 500ms to be processed. They would just be cancelled if I set the timeout to 500ms.

Offline distribution of the extension

Hi, I'd like to use this extension during the contest where I will not have access to the Internet but where I an prepare archive with data

Can you explain how to create extension to Chrome/FF and how to install it offline later?

Thanks.

Codeforces greater and less symbols do not parse correctly

I just found that when a problem's inputs have symbols like greater('>') or less('<'), they will be parsed into &gt, &lt respectively.

For example this link

POC:
image

Possible place to fix:
image

Here innerHtml doesn't parse &gt and &lt to '>' and '<', I tried to replace this function to innerText, but it gave me an error. so sad :-(

Parse Topcoder

Hi!

I am using this plugin + clion. You know it's so cool. I can actually parse contest in one click. It will nice if add topcoder too.

The parser is not working in my case.

When I try to click on the extension + icon, it just doesn't show up. Not a pop up nor eventlog nothing.
Please help me. I have installed CHelper plugin on intellJ. Thanks in advanced.

Is it broken for AtCoder ?

Looks like it is not working for AtCoder. It used to work couple of days back. I have tried using it on Mac/Chrome as well as on Windows/Chrome. It does work for other sites though such as CodeForeces, CSAcademy, etc.

Extention not Working

Hey, I am tried using this extension for both CHelper (IntelliJ Idea) and JHelper(Clion) But it is not parsing any Problem to the IDE.
I am using Linux and my internet is behind a proxy.

USACO Parser is still not working.

The error message is:

content.js:1785 TypeError: Cannot read property 'textContent' of null
    at USACOTrainingProblemParser.<anonymous> (content.js:3990)
    at Generator.next (<anonymous>)
    at content.js:3964
    at new Promise (<anonymous>)
    at __awaiter (content.js:3960)
    at USACOTrainingProblemParser.parse (content.js:3976)
    at content.js:1780
    at Generator.next (<anonymous>)
    at content.js:1749
    at new Promise (<anonymous>)

And I found this code in source:

task.setName(elem.querySelector('center > h1').textContent);

But in https usaco, the task name is embraced with

<center><b><font size="7"></font></b></center>

And the diff causes the error above.

AtCoder task is not being parsed (version - 2.9.1)

I am using version 2.9.1 on Chrome.
Tried parsing CodeForces task and CSAcademy and those worked fine.

Here is the error (looking from developer tool) :

content.js:1874 TypeError: Cannot read property '1' of null
at AtCoderProblemParser. (content.js:591)
at Generator.next ()
at content.js:570
at new Promise ()
at __awaiter (content.js:566)
at AtCoderProblemParser.parse (content.js:582)
at content.js:1869
at Generator.next ()
at content.js:1838
at new Promise ()

[CodeForces] Parsing issue

Hi,

Thanks for developing the competitive-companion plugin. Its amazing! ❤️

I found an issue while parsing this problem from codeforces.com.

Special characters like > and < in the test cases are not parsed properly

I expected the parsed output to be:

3
2
<>
3
><<
1
>

Actual parsed output:

3
2
&lt;&gt;
3
&gt;&lt;&lt;
1
&gt;

P.S: I'm using Highttail along with competitive-companion plugin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.