From fad0f9d0326156b3754ec345b895d27867b22933 Mon Sep 17 00:00:00 2001 From: lifeadventurer Date: Thu, 21 Mar 2024 22:30:02 +0800 Subject: [PATCH] Fix: Gitroll scanned code smells --- dev/main.js | 12 +++--------- fortune_generator/js/fortune.js | 4 ++-- fortune_generator/js/matrix.js | 2 +- index.html | 2 -- quote_generator/js/matrix.js | 2 +- scripts.js | 4 ---- styles.css | 1 - 7 files changed, 7 insertions(+), 20 deletions(-) diff --git a/dev/main.js b/dev/main.js index bef00b9..72008e6 100644 --- a/dev/main.js +++ b/dev/main.js @@ -1,4 +1,4 @@ -var fs = require('fs') +const fs = require('fs') const goodFortunes = [ { @@ -167,9 +167,9 @@ const goodLen = goodFortunes.length; let num = null; const dates = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 30]; const statusLen = 8; -var buckets = {}; +let buckets = {}; let day = 0; -var run_cnt = 0; +let run_cnt = 0; while (run_cnt != 2000) { let n1 = parseInt(Math.random() * 255 + 1); @@ -180,7 +180,6 @@ while (run_cnt != 2000) { if (!check_ip_valid(n1, n2, n3, n4)) continue; let index = `${n1}.${n2}.${n3}.${n4}`; - // buckets[`${n1}.${n2}.${n3}.${n4}`] = [0, 0, 0, 0, 0, 0, 0, 0]; buckets[index] = [0, 0, 0, 0]; for (let i = 1; i <= 12; i++) { for (let j = 1; j <= dates[i - 1]; j++) { @@ -248,11 +247,6 @@ function run(year, month, date, day, ip) { let seed1 = (num[0] >> hashDate) * (num[1] >> Math.min(hashDate, 2)) + (num[2] << 1) * (num[3] >> 3) + (date << 3) * (month << hashDate) + ((year * day) >> 2); let seed2 = (num[0] << (hashDate + 2)) * (num[1] << hashDate) + (num[2] << 1) * (num[3] << 3) + (date << (hashDate - 1)) * (month << 4) + (year >> hashDate) + ((date * day) >> 1); - // decide the status - let status_index = ((seed1 + seed2) % statusLen + statusLen) % statusLen; - // buckets[index][Math.max(status_index - parseInt(day / Math.PI), 0)]++; // old hash - // buckets[index][status_index]++; // current hash - // make sure the events won't collide let set = new Set(); let l1 = (seed1 % goodLen + goodLen) % goodLen; diff --git a/fortune_generator/js/fortune.js b/fortune_generator/js/fortune.js index 7b075ea..9517e4a 100644 --- a/fortune_generator/js/fortune.js +++ b/fortune_generator/js/fortune.js @@ -26,7 +26,7 @@ fetch("https://api.ipify.org?format=json").then(response => { let goodFortunes = []; let badFortunes = []; let special_events = []; -var fortune_generated = false; +let fortune_generated = false; // using async and await to prevent fetching the data too late... async function fetch_data() { @@ -165,7 +165,7 @@ function Appear() { let seed1 = -1; let seed2 = -1; - if (fortune_generated == false) { + if (!fortune_generated) { // transform ip to four numbers let num = ip.split(".").map(num => parseInt(num)); diff --git a/fortune_generator/js/matrix.js b/fortune_generator/js/matrix.js index 34cc086..ac1260d 100644 --- a/fortune_generator/js/matrix.js +++ b/fortune_generator/js/matrix.js @@ -4,7 +4,7 @@ const context = canvas.getContext("2d") canvas.height = window.innerHeight + 100; canvas.width = window.innerWidth + 5; -const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./*-+#$%^@!~?><:;[]{}\」=_αβΓγΔδεζηΘθικΛλμΞξΠπρΣσςτυΦφχΨψΩω×≦≧≠∞≒≡~∩∠∪∟⊿∫∮∵∴$¥〒¢£℃€℉╩◢ⅩⅨⅧⅦⅥⅤⅣⅢⅡⅠあいうえおがぎぐげござじずぜぞだぢつでづどにぬのばひぴぶへぺぼみゃょァゐゎè"; +const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./*-+#$%^@!~?><:;[]{}=_αβΓγΔδεζηΘθικΛλμΞξΠπρΣσςτυΦφχΨψΩω×≦≧≠∞≒≡~∩∠∪∟⊿∫∮∵∴$¥〒¢£℃€℉╩◢ⅩⅨⅧⅦⅥⅤⅣⅢⅡⅠあいうえおがぎぐげござじずぜぞだぢつでづどにぬのばひぴぶへぺぼみゃょァゐゎè"; const fontSize = 16; const columns = canvas.width / fontSize; diff --git a/index.html b/index.html index 5dc76b1..ac3504e 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,6 @@
fortune generator example -

Fortune Generator

Get your daily fortune with just a click.

@@ -40,7 +39,6 @@
quote generator example -

Quote Generator

Generate inspiring and thought-provoking quotes effortlessly.

diff --git a/quote_generator/js/matrix.js b/quote_generator/js/matrix.js index 5adc251..cccfc70 100644 --- a/quote_generator/js/matrix.js +++ b/quote_generator/js/matrix.js @@ -4,7 +4,7 @@ const context = canvas.getContext("2d") canvas.height = window.innerHeight + 100; canvas.width = window.innerWidth + 5; -const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./*-+#$%^@!~?><:;[]{}\」=_αβΓγΔδεζηΘθικΛλμΞξΠπρΣσςτυΦφχΨψΩω×≦≧≠∞≒≡~∩∠∪∟⊿∫∮∵∴$¥〒¢£℃€℉╩◢ⅩⅨⅧⅦⅥⅤⅣⅢⅡⅠあいうえおがぎぐげござじずぜぞだぢつでづどにぬのばひぴぶへぺぼみゃょァゐゎè"; +const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./*-+#$%^@!~?><:;[]{}=_αβΓγΔδεζηΘθικΛλμΞξΠπρΣσςτυΦφχΨψΩω×≦≧≠∞≒≡~∩∠∪∟⊿∫∮∵∴$¥〒¢£℃€℉╩◢ⅩⅨⅧⅦⅥⅤⅣⅢⅡⅠあいうえおがぎぐげござじずぜぞだぢつでづどにぬのばひぴぶへぺぼみゃょァゐゎè"; const fontSize = 16; const columns = canvas.width / fontSize; diff --git a/scripts.js b/scripts.js index 50a296c..954af5a 100644 --- a/scripts.js +++ b/scripts.js @@ -6,19 +6,16 @@ async function fetch_folders() { .then(response => response.json()) .then(data => { folderPaths = data.folder_paths; - // console.log(folderPaths); }) } async function get_generator_card_footer() { await fetch_folders() - // console.log(folderPaths); const repoOwner = 'LifeAdventurer'; const repoName = 'generators'; for (let folderIndex = 1; folderIndex <= folderPaths.length; folderIndex++) { let folderPath = folderPaths[folderIndex - 1]; const apiUrl = `https://api.github.com/repos/${repoOwner}/${repoName}/commits?path=${folderPath}`; - console.log(apiUrl); fetch(apiUrl) .then(response => response.json()) @@ -29,7 +26,6 @@ async function get_generator_card_footer() { const currentTimeStamp = Math.floor(new Date().getTime() / 1000); const timeDifference = currentTimeStamp - commitTimeStamp; - // console.log(timeSinceLastUpdate); $(`#last-update-${folderIndex}`).html(`Last updated ${format_time_difference(timeDifference)} ago`) }) // .catch(error => console.error('Error fetching data:', error)); diff --git a/styles.css b/styles.css index 2f72b27..1864dd1 100644 --- a/styles.css +++ b/styles.css @@ -34,7 +34,6 @@ .btn:hover { background-color: var(--button-hover-color); - /* color: var(--button-text-color); */ } body {