Skip to content

Commit 63197ed

Browse files
committed
Optimizes speed applets
1 parent 4d5467f commit 63197ed

File tree

2 files changed

+42
-32
lines changed
  • disk-read-and-write-speed@cardsurf/files/disk-read-and-write-speed@cardsurf
  • download-and-upload-speed@cardsurf/files/download-and-upload-speed@cardsurf

2 files changed

+42
-32
lines changed

disk-read-and-write-speed@cardsurf/files/disk-read-and-write-speed@cardsurf/applet.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ if (typeof require !== 'undefined') {
2323
Compatibility = AppletDirectory.compatibility;
2424
}
2525

26+
const _KI = Math.pow(2, 10);
27+
const _MI = Math.pow(2, 20);
28+
const _GI = Math.pow(2, 30);
29+
const _TI = Math.pow(2, 40);
30+
2631
function _(str) {
2732
return Gettext.dgettext(uuid, str);
2833
}
@@ -977,17 +982,17 @@ MyApplet.prototype = {
977982

978983
convert_bytes_to_readable_unit: function (bytes) {
979984
if (this.is_binary === true) {
980-
if(bytes >= Math.pow(2, 40)) {
981-
return [bytes/Math.pow(2, 40), _(" TiB")];
985+
if(bytes >= _TI) {
986+
return [bytes/_TI, _(" TiB")];
982987
}
983-
if(bytes >= Math.pow(2, 30)) {
984-
return [bytes/Math.pow(2, 30), _(" GiB")];
988+
if(bytes >= _GI) {
989+
return [bytes/_GI, _(" GiB")];
985990
}
986-
if(bytes >= Math.pow(2, 20)) {
987-
return [bytes/Math.pow(2, 20), _(" MiB")];
991+
if(bytes >= _MI) {
992+
return [bytes/_MI, _(" MiB")];
988993
}
989-
if(bytes >= Math.pow(2, 10)) {
990-
return [bytes/Math.pow(2, 10), _(" kiB")];
994+
if(bytes >= _KI) {
995+
return [bytes/_KI, _(" kiB")];
991996
}
992997
return [bytes, _(" B")];
993998
}
@@ -1012,17 +1017,17 @@ MyApplet.prototype = {
10121017

10131018
convert_bits_to_readable_unit: function (bits) {
10141019
if (this.is_binary === true) {
1015-
if(bits >= Math.pow(2, 40)) {
1016-
return [bits/Math.pow(2, 40), _(" Tib")];
1020+
if(bits >= _TI) {
1021+
return [bits/_TI, _(" Tib")];
10171022
}
1018-
if(bits >= Math.pow(2, 30)) {
1019-
return [bits/Math.pow(2, 30), _(" Gib")];
1023+
if(bits >= _GI) {
1024+
return [bits/_GI, _(" Gib")];
10201025
}
1021-
if(bits >= Math.pow(2, 20)) {
1022-
return [bits/Math.pow(2, 20), _(" Mib")];
1026+
if(bits >= _MI) {
1027+
return [bits/_MI, _(" Mib")];
10231028
}
1024-
if(bits >= Math.pow(2, 10)) {
1025-
return [bits/Math.pow(2, 10), _(" kib")];
1029+
if(bits >= _KI) {
1030+
return [bits/_KI, _(" kib")];
10261031
}
10271032
return [bits, _(" b")];
10281033
}

download-and-upload-speed@cardsurf/files/download-and-upload-speed@cardsurf/applet.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ if (typeof require !== 'undefined') {
2626
Infos = AppletDirectory.infos;
2727
}
2828

29+
const _KI = Math.pow(2, 10);
30+
const _MI = Math.pow(2, 20);
31+
const _GI = Math.pow(2, 30);
32+
const _TI = Math.pow(2, 40);
33+
2934
function _(str) {
3035
return Gettext.dgettext(uuid, str);
3136
}
@@ -792,17 +797,17 @@ MyApplet.prototype = {
792797

793798
convert_bytes_to_readable_unit: function (bytes) {
794799
if (this.is_binary === true) {
795-
if(bytes >= Math.pow(2, 40)) {
796-
return [bytes/Math.pow(2, 40), _(" TiB")];
800+
if(bytes >= _TI) {
801+
return [bytes/_TI, _(" TiB")];
797802
}
798-
if(bytes >= Math.pow(2, 30)) {
799-
return [bytes/Math.pow(2, 30), _(" GiB")];
803+
if(bytes >= _GI) {
804+
return [bytes/_GI, _(" GiB")];
800805
}
801-
if(bytes >= Math.pow(2, 20)) {
802-
return [bytes/Math.pow(2, 20), _(" MiB")];
806+
if(bytes >= _MI) {
807+
return [bytes/_MI, _(" MiB")];
803808
}
804-
if(bytes >= Math.pow(2, 10)) {
805-
return [bytes/Math.pow(2, 10), _(" kiB")];
809+
if(bytes >= _KI) {
810+
return [bytes/_KI, _(" kiB")];
806811
}
807812
return [bytes, _(" B")];
808813
}
@@ -827,17 +832,17 @@ MyApplet.prototype = {
827832

828833
convert_bits_to_readable_unit: function (bits) {
829834
if (this.is_binary === true) {
830-
if(bits >= Math.pow(2, 40)) {
831-
return [bits/Math.pow(2, 40), _(" Tib")];
835+
if(bits >= _TI) {
836+
return [bits/_TI, _(" Tib")];
832837
}
833-
if(bits >= Math.pow(2, 30)) {
834-
return [bits/Math.pow(2, 30), _(" Gib")];
838+
if(bits >= _GI) {
839+
return [bits/_GI, _(" Gib")];
835840
}
836-
if(bits >= Math.pow(2, 20)) {
837-
return [bits/Math.pow(2, 20), _(" Mib")];
841+
if(bits >= _MI) {
842+
return [bits/_MI, _(" Mib")];
838843
}
839-
if(bits >= Math.pow(2, 10)) {
840-
return [bits/Math.pow(2, 10), _(" kib")];
844+
if(bits >= _KI) {
845+
return [bits/_KI, _(" kib")];
841846
}
842847
return [bits, _(" b")];
843848
}

0 commit comments

Comments
 (0)