From 06aacabff97b4927fb2c25103192ea183b3becd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Canek=20Pel=C3=A1ez=20Vald=C3=A9s?= Date: Sat, 26 Oct 2024 17:42:59 -0600 Subject: [PATCH] Move JavaScript to its own file. --- free-word-count.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ page.php | 45 +-------------------------------------------- 2 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 free-word-count.js diff --git a/free-word-count.js b/free-word-count.js new file mode 100644 index 0000000..3359cfe --- /dev/null +++ b/free-word-count.js @@ -0,0 +1,44 @@ +class WordCounter { + constructor(siteUrl, key, total) { + this.last = 0; + this.done = 0; + this.intervalId = -1; + this.progressValue = 0; + this.baseUrl = siteUrl + + '/wp-content/plugins/free-word-count/word-count-progress.php?' + + 'key=' + key + '&total=' + total; + this.relocateUrl = siteUrl + '/wp-admin/admin.php?page=free-word-count'; + } + + launchInterval() { + this.intervalId = setInterval(this.updateProgressBar.bind(this), 100); + } + + doUpdate() { + document.getElementById('wc-progress').value = this.progressValue; + document.getElementById('wc-progress').childNodes[0].nodeValue = + this.progressValue + '%'; + } + + updateProgressBar() { + if (this.progressValue < 100) { + let url = this.baseUrl + '&done=' + this.done + '&last=' + this.last + '?guard=X'; + var t = this; + fetch(url) + .then(res => res.json()) + .then(r => { t.progressValue = r['progress']; + t.done = r['done']; + t.last = r['last']; }); + this.doUpdate(); + } else { + this.doUpdate(); + clearInterval(this.intervalId); + window.location.replace(this.relocateUrl); + } + } +} + +let wc = new WordCounter("", + "", + ); +wc.launchInterval(); diff --git a/page.php b/page.php index 76d9a0e..1756c26 100644 --- a/page.php +++ b/page.php @@ -98,50 +98,7 @@ if (!$wc_options['words_counted'] && !$wc_options['counting_words']) {

-- GitLab