Skip to content

Commit 0743f16

Browse files
committed
Merge branch 'dev'
2 parents af06c71 + aee298e commit 0743f16

28 files changed

+21134
-232
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
output
3+
*.zip

Gruntfile.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
module.exports = function(grunt) {
2+
grunt.initConfig({
3+
pkg: grunt.file.readJSON('package.json'),
4+
clean: ['output', '*.zip'],
5+
copy: {
6+
dist: {
7+
files: [{
8+
expand: true,
9+
cwd: 'src',
10+
src: ['**', '!**/*.psd'],
11+
dest: 'output'
12+
}]
13+
}
14+
},
15+
uglify: {
16+
dist: {
17+
files: [{
18+
expand: true,
19+
cwd: 'src',
20+
src: ['**/*.js', '!**/*.min.js'],
21+
dest: 'output'
22+
}]
23+
}
24+
},
25+
cssmin: {
26+
dist: {
27+
files: [{
28+
expand: true,
29+
cwd: 'src',
30+
src: ['**/*.css', '!**/*.min.css'],
31+
dest: 'output'
32+
}]
33+
}
34+
},
35+
jshint: {
36+
all: ['src/js/**/*.js', 'src/plugin/*.js']
37+
},
38+
'string-replace': {
39+
dist: {
40+
files: {
41+
'output/manifest.json': 'output/manifest.json'
42+
},
43+
options: {
44+
replacements: [{
45+
pattern: '0.0.0.0',
46+
replacement: '<%= grunt.template.today("yy.m.d") %>'
47+
}]
48+
}
49+
}
50+
},
51+
compress: {
52+
main: {
53+
options: {
54+
archive: 'show-me-the-data-<%= grunt.template.today("yy.m.d") %>.zip'
55+
},
56+
files: [{
57+
expand: true,
58+
cwd: 'output',
59+
src: '**'
60+
}]
61+
}
62+
}
63+
});
64+
65+
grunt.loadNpmTasks('grunt-contrib-clean');
66+
grunt.loadNpmTasks('grunt-contrib-copy');
67+
grunt.loadNpmTasks('grunt-contrib-uglify');
68+
grunt.loadNpmTasks('grunt-contrib-cssmin');
69+
grunt.loadNpmTasks('grunt-contrib-jshint');
70+
grunt.loadNpmTasks('grunt-string-replace');
71+
grunt.loadNpmTasks('grunt-contrib-compress');
72+
73+
grunt.registerTask('default', ['jshint', 'clean', 'copy', 'uglify', 'cssmin', 'string-replace']);
74+
grunt.registerTask('release', function() {
75+
grunt.task.run('default', 'compress');
76+
});
77+
};

package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "show-me-the-data",
3+
"description": "a chrome extension for bingo-view users",
4+
"version": "13.11.1",
5+
"devDependencies": {
6+
"grunt": "~0.4.2",
7+
"grunt-contrib-uglify": "~0.2.7",
8+
"grunt-contrib-cssmin": "~0.7.0",
9+
"grunt-contrib-copy": "~0.5.0",
10+
"grunt-contrib-clean": "~0.5.0",
11+
"grunt-contrib-jshint": "~0.8.0",
12+
"grunt-string-replace": "~0.2.7",
13+
"grunt-contrib-compress": "~0.5.3"
14+
},
15+
"dependencies": {
16+
"grunt": "~0.4.2"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/tbfe/show-me-the-data.git"
21+
}
22+
}

src/css/view.css

+29-25
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ body {
3636
}
3737
.code {
3838
flex: 1;
39+
position: relative;
3940
}
4041
.loading {
4142
position: fixed;
@@ -51,12 +52,13 @@ body {
5152
-webkit-filter: blur(3px);
5253
filter: blur(3px);
5354
}
55+
5456
/* style for php */
5557
.code[data-language=php] {
5658
flex: 1;
5759
display: flex;
5860
flex-direction: column;
59-
background: #272822;
61+
background: #272822; /* 处理代码前避免出现白底 */
6062
}
6163
.code[data-language=php] .code-wrapper {
6264
display: flex;
@@ -78,36 +80,38 @@ body {
7880
white-space: pre-wrap;
7981
word-break: break-all;
8082
}
81-
.word-wrap-control-wrapper {
82-
position: fixed;
83-
top: 44px; /* magic number*/
84-
right: 22px;
83+
84+
/* style for json */
85+
.code[data-language=json] .jsoneditor {
86+
position: absolute;
87+
border-width: 1px 0 0;
88+
}
89+
90+
.control-wrapper {
91+
position: absolute;
92+
bottom: 6px;
93+
right: 20px;
94+
opacity: .4;
95+
z-index: 99999;
96+
}
97+
.control-wrapper:hover {
98+
opacity: 1;
99+
}
100+
.code[data-language=php] .control-wrapper {
85101
background: rgba(0,0,0,.6);
86102
border-radius: 3px;
87103
color: #ccc;
88104
padding-left: 20px; /* magic number */
89-
opacity: .4;
90-
}
91-
.word-wrap-control-wrapper:hover {
92-
opacity: 1;
93105
}
94-
.word-wrap-control-wrapper label{
106+
.code[data-language=php] .word-wrap-control-wrapper label{
95107
padding: 6px;
96108
}
97-
/* style for json */
98-
.code[data-language=json] {
99-
display: flex;
100-
flex-direction: column;
101-
}
102-
.code[data-language=json] .jsoneditor {
103-
display: flex;
104-
flex-direction: column;
105-
flex: 1;
106-
border-width: 1px 0 0;
109+
.code[data-language=json] .control-wrapper .btn-group {
110+
margin-left: 6px;
107111
}
108-
.code[data-language=json] .jsoneditor div.outer {
109-
overflow: scroll;
110-
flex: 1;
111-
margin: 0;
112-
padding: 0;
112+
.code[data-language=json] iframe[name=preview] {
113+
position: absolute;
114+
width: 100%;
115+
height: 100%;
116+
border: none;
113117
}

src/image/icon_128.png

-67 Bytes
Loading

src/image/icon_128.psd

56.6 KB
Binary file not shown.

src/image/icon_48.png

-13 Bytes
Loading

src/js/background.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
var _timestamp;//上一次点击的时间
1+
var _timestamp; //上一次点击的时间
22

33
function checkForValidUrl(tabId, changeInfo, tab) {
44
if (tab.url.indexOf('baidu.com') > -1) {
55
chrome.pageAction.show(tabId);
66
}
7-
};
7+
}
88

99

1010
function showDataPage(tab) {
@@ -13,11 +13,13 @@ function showDataPage(tab) {
1313
};
1414
if (_timestamp > Date.now() - 500) {
1515
callback = function(key) {
16-
chrome.tabs.executeScript(null, {code: "(new View()).hide()"});
16+
chrome.tabs.executeScript(null, {
17+
code: "(new View()).hide()"
18+
});
1719
showDataPageInNewTab(key, tab);
1820
};
1921
}
20-
getKey(callback);
22+
Cache.getKey(callback);
2123
_timestamp = Date.now();
2224
}
2325

@@ -26,29 +28,37 @@ function showDataPageInNewTab(key, mix) {
2628
if (mix === undefined) return;
2729
if (typeof mix === 'string') {
2830
url = mix;
29-
}
30-
else {
31+
} else {
3132
//传入的是tab
3233
url = mix.url;
3334
}
34-
var url = new Uri(url);
35+
url = new Uri(url);
3536
url.replaceQueryParam(PARAM_KEY, key);
3637
window.open(url.toString());
3738
}
39+
3840
function showDataPageIframe(tab) {
39-
chrome.tabs.insertCSS(null, {file: "css/view_iframe.css"});
40-
chrome.tabs.executeScript(null, {file: "js/view_iframe_init.js"}, function(){
41-
chrome.tabs.executeScript(null, {code: "var view = new View('"+ tab.url +"');view.toggle();"});
41+
chrome.tabs.insertCSS(null, {
42+
file: "css/view_iframe.css"
43+
});
44+
chrome.tabs.executeScript(null, {
45+
file: "js/view_iframe_init.js"
46+
}, function() {
47+
chrome.tabs.executeScript(null, {
48+
code: "var view = new View('" + tab.url + "');view.toggle();"
49+
});
4250
});
4351
}
4452

4553
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
4654
switch (request.code) {
4755
case 'close':
48-
chrome.tabs.executeScript(null, {code: "(new View()).hide()"});
56+
chrome.tabs.executeScript(null, {
57+
code: "(new View()).hide()"
58+
});
4959
break;
5060
case 'newtab':
51-
getKey(function(key) {
61+
Cache.getKey(function(key) {
5262
showDataPageInNewTab(key, request.data.url);
5363
});
5464
break;

src/js/cache.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
var PARAM_KEY = '__qa',
2+
LANGUAGE_KEY = '__type';
3+
4+
(function() {
5+
6+
var KEY_URL = 'http://liye04.fe.baidu.com/key.php';
7+
8+
function _getKeyFromCache() {
9+
try {
10+
var value = localStorage.getItem(PARAM_KEY);
11+
if (value === "") {
12+
return false;
13+
} else {
14+
var time = localStorage.getItem('time');
15+
if ((new Date(Number(time))).toDateString() === (new Date()).toDateString()) {
16+
return value;
17+
} else {
18+
return false;
19+
}
20+
}
21+
} catch (e) {
22+
return false;
23+
}
24+
return false;
25+
}
26+
27+
function _cacheKeyFromServer(callback) {
28+
var xhr = new XMLHttpRequest();
29+
xhr.onreadystatechange = function handleStateChange(xhrpe) {
30+
if (xhrpe.srcElement.readyState !== 4) {
31+
return;
32+
}
33+
var response = xhrpe.srcElement.response;
34+
localStorage.setItem(PARAM_KEY, response);
35+
localStorage.setItem('time', Date.now());
36+
if (typeof callback === 'function') callback(response);
37+
};
38+
xhr.open("GET", KEY_URL, true);
39+
xhr.send();
40+
}
41+
42+
var Cache = {
43+
getKey: function(callback) {
44+
var key = _getKeyFromCache();
45+
if (key) {
46+
callback(key);
47+
} else {
48+
_cacheKeyFromServer(callback);
49+
}
50+
},
51+
getLanguage: function() {
52+
try {
53+
language = localStorage.getItem('language');
54+
} catch (e) {}
55+
return language || 'php';
56+
},
57+
setLanguage: function(language) {
58+
try {
59+
localStorage.setItem('language', language);
60+
} catch (e) {}
61+
}
62+
};
63+
64+
window.Cache = Cache;
65+
})();

src/js/key.js

-62
This file was deleted.

0 commit comments

Comments
 (0)