Skip to content

Commit

Permalink
Dynamic layout fix (#27)
Browse files Browse the repository at this point in the history
* feat: fix bug with new layout

* feat: fix bug with new layout

---------

Co-authored-by: Madhur <[email protected]>
  • Loading branch information
madhur and madhurgames authored Dec 24, 2023
1 parent 143ef72 commit 25dc76a
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"dartfmt": true,
"prettier": true,
"js_beautify": true,
"monaco": true
"monaco": true,
"chrome": true

},
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.14.0
v20.10.0
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ Use CTRL + ALT + F to trigger the format action through keyboard

Send your feedback and any bug reports [here](https://github.com/madhur/leetcode-format-chrome-extension/issues)

### Demo GIF

<img src="./images/format-demo.gif">

### Dynamic layout

<img src="./images/dynamic_layout.png">

### New UI

<img src="./images/new_ui.png">

### Old UI

<img src="./images/old_ui.png">
Binary file added images/dynamic_layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/new_ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/old_ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Leetcode format",
"version": "1.8",
"version": "1.9",
"manifest_version": 3,
"description": "Adds Format code button on leetcode to format the code using Prettier code formatter",
"homepage_url": "https://github.com/madhur/leetcode-format-chrome-extension",
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"name": "leetcode-format-chrome",
"version": "1.8",
"description": "",
"description": "LeetCode Code Format Google Chrome Extension",
"main": "content.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Madhur Ahuja",
"license": "ISC",
"dependencies": {
"prettier": "^2.2.1"
},
"devDependencies": {
"eslint": "^8.6.0",
"prettier": "^2.2.1",
"eslint-config-prettier": "^9.0.0",
"prettier-plugin-java": "^1.0.1"
}
Expand Down
7 changes: 5 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function startLoading() {

let button = getFormatButton();
uiVersion = 0;
console.debug("Ui version is 0");
addShortcutBinding(formatCodeMirror);
button.addEventListener('click', function () {
formatCodeMirror();
Expand All @@ -89,6 +90,7 @@ function checkAndLoadNewUI() {
document.querySelector(buttonLocation)
) {
uiVersion = 1;
console.debug("Ui version is 1");
btn = getFormatButtonNew();
document.querySelector(buttonLocation).appendChild(btn);
addShortcutBinding(formatCodeMonaco);
Expand All @@ -99,13 +101,14 @@ function checkAndLoadNewUI() {
function checkAndLoadNewUIv2() {


let buttonLocation = 'div.flex div.items-center div.mr-auto';
let buttonLocation = 'div.flex.flex-nowrap.items-center';

if (
!document.querySelector('.tool-button') &&
document.querySelector(buttonLocation)
) {
uiVersion = 2;
console.debug("Ui version is 2");
btn = getFormatButtonNew();
document.querySelector(buttonLocation).appendChild(btn);
addShortcutBinding(formatCodeMonacov2);
Expand All @@ -114,6 +117,7 @@ function checkAndLoadNewUIv2() {

}


function setupLanguageObserver() {
const languageObserver = '.relative.notranslate';
const languageSelector = '.relative.notranslate div div';
Expand Down Expand Up @@ -204,7 +208,6 @@ const getFormatButtonNew = function () {
function addShortcutBinding(func) {
window.addEventListener('keyup', (event) => {
if (event.ctrlKey && event.altKey && event.key == 'f')
//formatCodeMonaco();
func();
});
}
Expand Down

0 comments on commit 25dc76a

Please sign in to comment.