Skip to content

Commit

Permalink
Toggle Coach Mode in finder
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoRiether committed Jul 25, 2021
1 parent 0667ddf commit 315dd5e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cfpp",
"version": "2.2.1",
"version": "2.3.0",
"description": "Codeforces extension pack",
"main": "src/index.js",
"author": "Leonardo Riether <riether.leonardo@gmail.com>",
Expand Down
37 changes: 19 additions & 18 deletions src/ext/finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dom from '../helpers/dom';
import * as config from '../env/config';
import { safe, pipe, map, once, flatten } from '../helpers/Functional';
import { toggleCoachMode } from '../helpers/util';
import env from '../env/env';

let isOpen = false;
Expand Down Expand Up @@ -35,24 +36,24 @@ function Result(props) {

let extensions = {
common(handle) {
// TODO: consider changing to JSON.parse for performance reasons
return [
{ key: "contests", title: "Contests", href: "/contests" },
{ key: "problemset", title: "Problemset", href: "/problemset" },
{ key: "psetting", title: "Problemsetting", href: `/contests/with/${handle}` },
{ key: "subms", title: "Submissions", href: `/submissions/${handle}` },
{ key: "groups", title: "Groups", href: `/groups/with/${handle}` },
{ key: "profile", title: "Profile", href: `/profile/${handle}` },
{ key: "cfviz", title: "CfViz", href: "https://cfviz.netlify.com" },
{ key: "favs", title: "Favourites", href: "/favourite/problems" },
{ key: "teams", title: "Teams", href: `/teams/with/${handle}` },
{ key: "status", title: "Status", href: "/problemset/status" },
{ key: "fstatus", title: "Friends Status", href: "/problemset/status?friends=on" },
{ key: "gym", title: "Gym", href: "/gyms" },
{ key: "blog", title: "Blog", href: `/blog/handle/${handle}` },
{ key: "mashups", title: "Mashups", href: "/mashups" },
{ key: "rating", title: "Rating", href: "/ratings" },
{ key: "api", title: "API", href: "/apiHelp" }
{ key: "contests" , title: "Contests" , href: "/contests" } ,
{ key: "problemset" , title: "Problemset" , href: "/problemset" } ,
{ key: "psetting" , title: "Problemsetting" , href: `/contests/with/${handle}` } ,
{ key: "subms" , title: "Submissions" , href: `/submissions/${handle}` } ,
{ key: "groups" , title: "Groups" , href: `/groups/with/${handle}` } ,
{ key: "profile" , title: "Profile" , href: `/profile/${handle}` } ,
{ key: "cfviz" , title: "CfViz" , href: "https://cfviz.netlify.com" } ,
{ key: "favs" , title: "Favourites" , href: "/favourite/problems" } ,
{ key: "teams" , title: "Teams" , href: `/teams/with/${handle}` } ,
{ key: "status" , title: "Status" , href: "/problemset/status" } ,
{ key: "fstatus" , title: "Friends Status" , href: "/problemset/status?friends=on" } ,
{ key: "gym" , title: "Gym" , href: "/gyms" } ,
{ key: "blog" , title: "Blog" , href: `/blog/handle/${handle}` } ,
{ key: "mashups" , title: "Mashups" , href: "/mashups" } ,
{ key: "rating" , title: "Rating" , href: "/ratings" } ,
{ key: "api" , title: "API" , href: "/apiHelp" } ,
{ key: "togCoach" , title: "Toggle Coach Mode" , onClick: toggleCoachMode } ,
];
},

Expand Down Expand Up @@ -319,4 +320,4 @@ async function updateGroups() {
}
}

export { create, open, close, updateGroups };
export { create, open, close, updateGroups };
22 changes: 22 additions & 0 deletions src/helpers/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import env from '../env/env';

export function toggleCoachMode() {
let data = new URLSearchParams();
data.append("action", "toggleGymContestsManagerEnabled");
data.append("csrf_token",env.global.Codeforces.getCsrfToken());
data.append("_tta", env.global.Codeforces.tta());

return fetch("/gyms", {
method: "POST",
body: data,
})
.then(res => res.text())
.then(html => {
let doc = new DOMParser().parseFromString(html, "text/html");
let btn = doc.querySelector(".toggleGymContestsManagerEnabled input[type=submit]");
let status = btn && btn.value.startsWith("Disable") ? "enabled" : "disabled";

env.global.Codeforces.reloadAndShowMessage(`Coach mode is now ${status}`);
})
.catch(err => console.error("Codeforces++ couldn't toggle coach mode: ", err));
}

0 comments on commit 315dd5e

Please sign in to comment.