Skip to content

Commit c480736

Browse files
authored
[refactor] Better version check and compare
1 parent 37e95f8 commit c480736

File tree

7 files changed

+81
-40
lines changed

7 files changed

+81
-40
lines changed

‎images/icon-128.png‎

20.5 KB
Loading

‎images/icon-16.png‎

18.9 KB
Loading

‎images/icon-48.png‎

19.3 KB
Loading

‎images/icon.psd‎

24.3 KB
Binary file not shown.

‎js/update.js‎

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -155,45 +155,59 @@ var update = (function(){
155155
console.log("\t -- running update",1.00);
156156
data=_update_100(data);
157157
};
158-
if(data.version<2.00){
159-
console.log("\t -- running update",2.00);
160-
data=_update_200(data);
161-
};
162-
if(data.version<2.10){
163-
console.log("\t -- running update",2.10);
164-
data=_update_210(data);
165-
};
166-
if(data.version<2.30){
167-
console.log("\t -- running update",2.30);
168-
data=_update_230(data);
169-
};
170-
if(data.version<2.40){
171-
console.log("\t -- running update",2.40);
172-
data=_update_240(data);
173-
};
174-
if(data.version<2.50){
175-
console.log("\t -- running update",2.50);
176-
data=_update_250(data);
177-
};
178-
if(data.version<2.70){
179-
console.log("\t -- running update",2.70);
180-
data=_update_270(data);
181-
};
182-
if(data.version<2.80){
183-
console.log("\t -- running update",2.80);
184-
data=_update_280(data);
185-
};
186-
if(data.version<2.90){
187-
console.log("\t -- running update",2.90);
188-
data=_update_290(data);
189-
};
190-
if(data.version<2.91){
191-
console.log("\t -- running update",2.91);
192-
data.version=2.91;
158+
if(typeofdata.version=="number"){
159+
if(data.version<2.00){
160+
console.log("\t -- running update",2.00);
161+
data=_update_200(data);
162+
};
163+
if(data.version<2.10){
164+
console.log("\t -- running update",2.10);
165+
data=_update_210(data);
166+
};
167+
if(data.version<2.30){
168+
console.log("\t -- running update",2.30);
169+
data=_update_230(data);
170+
};
171+
if(data.version<2.40){
172+
console.log("\t -- running update",2.40);
173+
data=_update_240(data);
174+
};
175+
if(data.version<2.50){
176+
console.log("\t -- running update",2.50);
177+
data=_update_250(data);
178+
};
179+
if(data.version<2.70){
180+
console.log("\t -- running update",2.70);
181+
data=_update_270(data);
182+
};
183+
if(data.version<2.80){
184+
console.log("\t -- running update",2.80);
185+
data=_update_280(data);
186+
};
187+
if(data.version<2.90){
188+
console.log("\t -- running update",2.90);
189+
data=_update_290(data);
190+
};
191+
if(data.version<2.91){
192+
console.log("\t -- running update",2.91);
193+
data.version=2.91;
194+
};
195+
if(data.version<2.96){
196+
// introduction of a new semantic version check function so the version is being bumped to 2.10.0 and changed to a string
197+
console.log("\t -- running update","2.10.0");
198+
data.version="2.10.0";
199+
};
200+
}elseif(typeofdata.version=="string"){
201+
// new updates will go here
202+
// example update compare check
203+
// if (version.compare(data.version, "2.11.0") == -1){
204+
// console.log("\t -- running update", "2.11.0");
205+
// data.version = "2.11.0"
206+
// };
193207
};
194208
// if no update is needed
195209
// version bump
196-
if(data.version<version.get()){
210+
if(version.compare(data.version,version.get())==-1){
197211
console.log("\t -- nothing to update, version bump to",version.get());
198212
data.version=version.get();
199213
};

‎js/version.js‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
varversion=(function(){
22

33
// version is normally bumped when the state needs changing or any new functionality is added
4-
varcurrent="2.9.5";
4+
varcurrent="2.10.0";
5+
6+
varcompare=function(a,b){
7+
varpa=a.split(".");
8+
varpb=b.split(".");
9+
for(vari=0;i<3;i++){
10+
varna=Number(pa[i]);
11+
varnb=Number(pb[i]);
12+
if(na>nb){
13+
return1;
14+
};
15+
if(nb>na){
16+
return-1;
17+
};
18+
if(!isNaN(na)&&isNaN(nb)){
19+
return1;
20+
};
21+
if(isNaN(na)&&!isNaN(nb)){
22+
return-1;
23+
};
24+
}
25+
return0;
26+
};
527

628
varget=function(){
7-
varnumber=current.split(".");
8-
returnparseFloat(number.shift()+"."+number.join(""));
29+
returncurrent;
930
};
1031

1132
// exposed methods
1233
return{
13-
get: get
34+
get: get,
35+
compare: compare
1436
};
1537

1638
})();

‎manifest.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
"manifest_version": 2,
66
"chrome_url_overrides":{
77
"newtab": "index.html"
8+
},
9+
"icons":{
10+
"16": "images/icon-16.png",
11+
"48": "images/icon-48.png",
12+
"128": "images/icon-128.png"
813
}
914
}

0 commit comments

Comments
(0)