Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
x2rr committed Apr 16, 2020
1 parent 2e77d22 commit 78b704b
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 93 deletions.
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "choose-funds",
"version": "1.4.0",
"version": "1.4.1",
"description": "A Vue.js web extension",
"author": "Liu Rabt",
"license": "GPL",
Expand All @@ -18,8 +18,7 @@
},
"dependencies": {
"axios": "^0.19.0",
"vue": "^2.6.10",
"vuex": "^3.0.1"
"vue": "^2.6.10"
},
"devDependencies": {
"@babel/core": "^7.1.2",
Expand Down
96 changes: 45 additions & 51 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import store from './store'
import axios from 'axios';


var Interval;
Expand All @@ -14,9 +14,9 @@ var isDuringDate = () => {
endDateAM.setHours(11, 30, 0);
beginDatePM.setHours(13, 0, 0);
endDatePM.setHours(15, 0, 0);
if(curDate.getDay() == '6' || curDate.getDay() == '0'){
if (curDate.getDay() == '6' || curDate.getDay() == '0') {
return false;
}else if (curDate >= beginDateAM && curDate <= endDateAM) {
} else if (curDate >= beginDateAM && curDate <= endDateAM) {
return true;
} else if (curDate >= beginDatePM && curDate <= endDatePM) {
return true;
Expand All @@ -26,43 +26,37 @@ var isDuringDate = () => {
}

var setBadge = fundcode => {
let xhr = new XMLHttpRequest();
let url = 'http://fundgz.1234567.com.cn/js/' + fundcode + '.js?rt=' + new Date().getTime();
xhr.open("GET", url, true);
xhr.send();

xhr.onreadystatechange = () => {
let DONE = 4;
let OK = 200;
if (xhr.readyState === DONE) {
if (xhr.status === OK) {
let res = xhr.responseText.match(/\{(.+?)\}/);
let ress = JSON.parse(res[0]);
chrome.browserAction.setBadgeText({
text: ress.gszzl
});
let color = ress.gszzl > 0 ? '#ff0000' : '#008000'
chrome.browserAction.setBadgeBackgroundColor({
color: color
});

} else {
chrome.browserAction.setBadgeText({
text: ''
});
}
} else {

let url =
"http://fundgz.1234567.com.cn/js/" +
fundcode +
".js?rt=" +
new Date().getTime();
axios
.get(url)
.then(res => {
let val = res.data.match(/\{(.+?)\}/);
let ress = JSON.parse(val[0]);
chrome.browserAction.setBadgeText({
text: ''
text: ress.gszzl
});
}
if (!isDuringDate()) {
let color = ress.gszzl > 0 ? '#ff0000' : '#008000'
chrome.browserAction.setBadgeBackgroundColor({
color: [0, 0, 0, 0]
color: color
});
}

})
.catch(error => {
chrome.browserAction.setBadgeText({
text: ''
});
});

if (!isDuringDate()) {
chrome.browserAction.setBadgeBackgroundColor({
color: [0, 0, 0, 0]
});
}

}

var startInterval = RealtimeFundcode => {
Expand All @@ -71,12 +65,12 @@ var startInterval = RealtimeFundcode => {
Interval = setInterval(() => {
if (isDuringDate()) {
setBadge(RealtimeFundcode);
}else{
} else {
chrome.browserAction.setBadgeBackgroundColor({
color: [0, 0, 0, 0]
});
}
}, 3*60*1000)
}, 3 * 60 * 1000)

}

Expand All @@ -100,18 +94,18 @@ chrome.storage.sync.get('RealtimeFundcode', (res) => {


chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.type == "DuringDate"){
let DuringDate = isDuringDate();
sendResponse({farewell: DuringDate});
}
if (request.type == "endInterval"){
endInterval()
}
if (request.type == "startInterval"){
startInterval(request.id)
}

});

function (request, sender, sendResponse) {
if (request.type == "DuringDate") {
let DuringDate = isDuringDate();
sendResponse({
farewell: DuringDate
});
}
if (request.type == "endInterval") {
endInterval()
}
if (request.type == "startInterval") {
startInterval(request.id)
}

});
2 changes: 0 additions & 2 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Vue from 'vue'
import App from './App'
import store from '../store'
import axios from 'axios';

Vue.prototype.$axios = axios;

/* eslint-disable no-new */
new Vue({
el: '#app',
store,

render: h => h(App)
})
5 changes: 0 additions & 5 deletions src/store/actions.js

This file was deleted.

1 change: 0 additions & 1 deletion src/store/getters.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/store/index.js

This file was deleted.

1 change: 0 additions & 1 deletion src/store/mutation-types.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/store/mutations.js

This file was deleted.

0 comments on commit 78b704b

Please sign in to comment.