From e6edd34c3ab74695aebcda1606c14dd52655c6a3 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Mon, 21 Oct 2024 00:52:49 -0400 Subject: [PATCH] clean: use vanilla JS instead of jQuery --- .github/workflows/auto format.yml | 17 +++-------------- .prettierignore | 12 +++++++++++- .prettierrc.json | 2 +- package-lock.json | 12 ++++++++---- package.json | 2 +- src/article_maker.cc | 15 +++++++++++---- src/scripts/gd-builtin.js | 12 +++++++----- src/scripts/gd-custom.js | 2 +- 8 files changed, 43 insertions(+), 31 deletions(-) diff --git a/.github/workflows/auto format.yml b/.github/workflows/auto format.yml index 2cc5467d..68fade99 100644 --- a/.github/workflows/auto format.yml +++ b/.github/workflows/auto format.yml @@ -29,8 +29,7 @@ jobs: eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" brew install clang-format (/home/linuxbrew/.linuxbrew/opt/clang-format/bin/git-clang-format --binary=/home/linuxbrew/.linuxbrew/opt/clang-format/bin/clang-format --style=file HEAD^) || true - - - uses: autofix-ci/action@89762f9c25dd85f6b78cd40e521232e403357ec0 + - uses: autofix-ci/action@ff86a557419858bb967097bfc916833f5647fa8c css-js-html-format: @@ -39,16 +38,6 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 2 - - uses: actions/setup-node@v4 - with: - node-version: 16 - - run: npm ci - - run: npx prettier --write src/stylesheets src/scripts/gd-*.js - # Optimize all PNGs with https://pngquant.org/ - # - run: sudo apt-get update && sudo apt-get install -y pngquant - # - name: Run pngquant - # run: | - # shopt -s globstar - # pngquant -f --ext .png --skip-if-larger -- **/*.png - - uses: autofix-ci/action@89762f9c25dd85f6b78cd40e521232e403357ec0 + - run: npx prettier . --write + - uses: autofix-ci/action@ff86a557419858bb967097bfc916833f5647fa8c diff --git a/.prettierignore b/.prettierignore index 1d1644cd..f019d35d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,12 @@ -**/.clang-format +# ignore all +/**/*.* +# unignore js and cssfiles +!**/*.js +!**/*.css + +# reignore other js files +**/*.min.js +**/iframe-defer.js +**/mark.js +**/darkreader.js diff --git a/.prettierrc.json b/.prettierrc.json index 8b137891..9e26dfee 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1 +1 @@ - +{} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0b2eaaf7..c49f34db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,19 +5,23 @@ "packages": { "": { "devDependencies": { - "prettier": "3.0.0" + "prettier": "3" } }, "node_modules/prettier": { - "version": "3.0.0", - "resolved": "https://registry.npmmirror.com/prettier/-/prettier-3.0.0.tgz", - "integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", "dev": true, + "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, "engines": { "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" } } } diff --git a/package.json b/package.json index 98061934..80758a8b 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "devDependencies": { - "prettier": "3.0.0" + "prettier": "3" } } diff --git a/src/article_maker.cc b/src/article_maker.cc index d0b10279..eab66e6c 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -50,7 +50,8 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word, QString const & // add jquery { result += R"()"; - result += R"()"; + result += R"()"; + result += R"()"; result += R"()"; } @@ -64,13 +65,19 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word, QString const & { result += R"( + }; + + if (document.readyState !== "loading") { + gd_init_QtWebChannel(); + } else { + document.addEventListener("DOMContentLoaded", gd_init_QtWebChannel); + }; + )"; } diff --git a/src/scripts/gd-builtin.js b/src/scripts/gd-builtin.js index 583ba0ce..530649fd 100644 --- a/src/scripts/gd-builtin.js +++ b/src/scripts/gd-builtin.js @@ -8,12 +8,14 @@ var gdAudioLinks = { var gdAudioMap = new Map(); function gdMakeArticleActive(newId, noEvent) { - var gdCurrentArticle = $_$(".gdactivearticle").attr("id"); + const gdCurrentArticle = + document.querySelector(".gdactivearticle").attributes.id; if (gdCurrentArticle !== "gdfrom-" + newId) { - $_$(".gdactivearticle").removeClass("gdactivearticle"); - var newFormId = "gdfrom-" + newId; - $_$("#" + newFormId).addClass("gdactivearticle"); - gdCurrentArticle = "gdfrom-" + newId; + document + .querySelector(".gdactivearticle") + .classList.remove("gdactivearticle"); + const newFormId = "gdfrom-" + newId; + document.querySelector(`#${newFormId}`).classList.add("gdactivearticle"); gdAudioLinks.current = newId; if (!noEvent) articleview.onJsActiveArticleChanged("gdfrom-" + newId); } diff --git a/src/scripts/gd-custom.js b/src/scripts/gd-custom.js index 1d9a989d..b41ce40a 100644 --- a/src/scripts/gd-custom.js +++ b/src/scripts/gd-custom.js @@ -65,4 +65,4 @@ autoResize: false, }); }); -})($_$); +})(jQuery);