-
Notifications
You must be signed in to change notification settings - Fork 53
added handle Cses submit and cses injected script to submit the cses… #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1917c6a
added handle Cses submit and cses injected script to submit the cses…
sachin-prmndani d905ce1
Fix id to key mapping for some langs
sachin-prmndani 368cd12
removed extra TABS permission from manifest.json and made it working …
sachin-prmndani d95fac7
Readme updated
sachin-prmndani a3e6102
fixed package and readme file and added alert in CSES script
sachin-prmndani 3d2bf8a
fixed readme
sachin-prmndani c08a5f2
final format check
sachin-prmndani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { ContentScriptData } from './types'; | ||
| import log from './log'; | ||
|
|
||
| declare const browser: any; | ||
| if (typeof browser !== 'undefined') { | ||
| self.chrome = browser; | ||
| } | ||
|
|
||
| log('cph-submit cses script injected'); | ||
|
|
||
| const extMap: Record<string, string> = { | ||
| cpp: 'solution.cpp', | ||
| c: 'solution.c', | ||
| java: 'solution.java', | ||
| python: 'solution.py', | ||
| rust: 'solution.rs', | ||
| javascript: 'solution.js', | ||
| ruby: 'solution.rb', | ||
| haskell: 'solution.hs', | ||
| scala: 'solution.scala', | ||
| pascal: 'solution.pas', | ||
| }; | ||
|
|
||
| const langMap: Record<string, string> = { | ||
| cpp: 'C++', | ||
| c: 'C', | ||
| java: 'Java', | ||
| python: 'Python3', | ||
| rust: 'Rust', | ||
| javascript: 'Node.js', | ||
| ruby: 'Ruby', | ||
| haskell: 'Haskell', | ||
| scala: 'Scala', | ||
| pascal: 'Pascal', | ||
| }; | ||
| const idToKey: Record<number, string> = { | ||
| 54: 'cpp', | ||
| 50: 'cpp', | ||
| 42: 'cpp', | ||
| 61: 'cpp', | ||
| 89: 'cpp', | ||
| 91: 'cpp', | ||
| 59: 'cpp', | ||
| 2: 'cpp', | ||
| 52: 'cpp', | ||
| 43: 'c', | ||
| 36: 'java', | ||
| 60: 'java', | ||
| 87: 'java', | ||
| 7: 'python', | ||
| 31: 'python', | ||
| 40: 'python', | ||
| 41: 'python', | ||
| 70: 'python', | ||
| 75: 'rust', | ||
| 98: 'rust', | ||
| 34: 'javascript', | ||
| 55: 'javascript', | ||
| 67: 'ruby', | ||
| 12: 'haskell', | ||
| 20: 'scala', | ||
| 3: 'pascal', | ||
| 4: 'pascal', | ||
| 51: 'pascal', | ||
| }; | ||
|
|
||
| chrome.runtime.onMessage.addListener((message) => { | ||
| if (message.type !== 'cph-submit-cses') return; | ||
|
|
||
| const { sourceCode, languageId } = message; | ||
|
|
||
| const form = document.querySelector('form'); | ||
| if (!form) { | ||
| alert('CSES form not found'); | ||
| log('CSES form not found'); | ||
| return; | ||
| } | ||
|
|
||
| const fileInput = form.querySelector( | ||
| 'input[type="file"]', | ||
| ) as HTMLInputElement; | ||
| if (fileInput) { | ||
| const langKey = idToKey[languageId] ?? 'cpp'; | ||
|
|
||
| const fileName = extMap[langKey] ?? 'solution.cpp'; | ||
| const file = new File([sourceCode], fileName, { type: 'text/plain' }); | ||
| const dt = new DataTransfer(); | ||
| dt.items.add(file); | ||
| fileInput.files = dt.files; | ||
| } | ||
|
|
||
| const langSelect = form.querySelector( | ||
| 'select[name="lang"]', | ||
| ) as HTMLSelectElement; | ||
| if (langSelect) { | ||
| const langKey = idToKey[languageId] ?? 'cpp'; | ||
| langSelect.value = langMap[langKey] ?? 'C++'; | ||
| } | ||
|
|
||
| form.submit(); | ||
| log('CSES form submitted'); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be an alert.