Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyeh committed Jan 10, 2014
2 parents af06c71 + aee298e commit 0743f16
Show file tree
Hide file tree
Showing 28 changed files with 21,134 additions and 232 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
output
*.zip
77 changes: 77 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: ['output', '*.zip'],
copy: {
dist: {
files: [{
expand: true,
cwd: 'src',
src: ['**', '!**/*.psd'],
dest: 'output'
}]
}
},
uglify: {
dist: {
files: [{
expand: true,
cwd: 'src',
src: ['**/*.js', '!**/*.min.js'],
dest: 'output'
}]
}
},
cssmin: {
dist: {
files: [{
expand: true,
cwd: 'src',
src: ['**/*.css', '!**/*.min.css'],
dest: 'output'
}]
}
},
jshint: {
all: ['src/js/**/*.js', 'src/plugin/*.js']
},
'string-replace': {
dist: {
files: {
'output/manifest.json': 'output/manifest.json'
},
options: {
replacements: [{
pattern: '0.0.0.0',
replacement: '<%= grunt.template.today("yy.m.d") %>'
}]
}
}
},
compress: {
main: {
options: {
archive: 'show-me-the-data-<%= grunt.template.today("yy.m.d") %>.zip'
},
files: [{
expand: true,
cwd: 'output',
src: '**'
}]
}
}
});

grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-contrib-compress');

grunt.registerTask('default', ['jshint', 'clean', 'copy', 'uglify', 'cssmin', 'string-replace']);
grunt.registerTask('release', function() {
grunt.task.run('default', 'compress');
});
};
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "show-me-the-data",
"description": "a chrome extension for bingo-view users",
"version": "13.11.1",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-jshint": "~0.8.0",
"grunt-string-replace": "~0.2.7",
"grunt-contrib-compress": "~0.5.3"
},
"dependencies": {
"grunt": "~0.4.2"
},
"repository": {
"type": "git",
"url": "https://github.com/tbfe/show-me-the-data.git"
}
}
54 changes: 29 additions & 25 deletions src/css/view.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ body {
}
.code {
flex: 1;
position: relative;
}
.loading {
position: fixed;
Expand All @@ -51,12 +52,13 @@ body {
-webkit-filter: blur(3px);
filter: blur(3px);
}

/* style for php */
.code[data-language=php] {
flex: 1;
display: flex;
flex-direction: column;
background: #272822;
background: #272822; /* 处理代码前避免出现白底 */
}
.code[data-language=php] .code-wrapper {
display: flex;
Expand All @@ -78,36 +80,38 @@ body {
white-space: pre-wrap;
word-break: break-all;
}
.word-wrap-control-wrapper {
position: fixed;
top: 44px; /* magic number*/
right: 22px;

/* style for json */
.code[data-language=json] .jsoneditor {
position: absolute;
border-width: 1px 0 0;
}

.control-wrapper {
position: absolute;
bottom: 6px;
right: 20px;
opacity: .4;
z-index: 99999;
}
.control-wrapper:hover {
opacity: 1;
}
.code[data-language=php] .control-wrapper {
background: rgba(0,0,0,.6);
border-radius: 3px;
color: #ccc;
padding-left: 20px; /* magic number */
opacity: .4;
}
.word-wrap-control-wrapper:hover {
opacity: 1;
}
.word-wrap-control-wrapper label{
.code[data-language=php] .word-wrap-control-wrapper label{
padding: 6px;
}
/* style for json */
.code[data-language=json] {
display: flex;
flex-direction: column;
}
.code[data-language=json] .jsoneditor {
display: flex;
flex-direction: column;
flex: 1;
border-width: 1px 0 0;
.code[data-language=json] .control-wrapper .btn-group {
margin-left: 6px;
}
.code[data-language=json] .jsoneditor div.outer {
overflow: scroll;
flex: 1;
margin: 0;
padding: 0;
.code[data-language=json] iframe[name=preview] {
position: absolute;
width: 100%;
height: 100%;
border: none;
}
Binary file modified src/image/icon_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/image/icon_128.psd
Binary file not shown.
Binary file modified src/image/icon_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 22 additions & 12 deletions src/js/background.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var _timestamp;//上一次点击的时间
var _timestamp; //上一次点击的时间

function checkForValidUrl(tabId, changeInfo, tab) {
if (tab.url.indexOf('baidu.com') > -1) {
chrome.pageAction.show(tabId);
}
};
}


function showDataPage(tab) {
Expand All @@ -13,11 +13,13 @@ function showDataPage(tab) {
};
if (_timestamp > Date.now() - 500) {
callback = function(key) {
chrome.tabs.executeScript(null, {code: "(new View()).hide()"});
chrome.tabs.executeScript(null, {
code: "(new View()).hide()"
});
showDataPageInNewTab(key, tab);
};
}
getKey(callback);
Cache.getKey(callback);
_timestamp = Date.now();
}

Expand All @@ -26,29 +28,37 @@ function showDataPageInNewTab(key, mix) {
if (mix === undefined) return;
if (typeof mix === 'string') {
url = mix;
}
else {
} else {
//传入的是tab
url = mix.url;
}
var url = new Uri(url);
url = new Uri(url);
url.replaceQueryParam(PARAM_KEY, key);
window.open(url.toString());
}

function showDataPageIframe(tab) {
chrome.tabs.insertCSS(null, {file: "css/view_iframe.css"});
chrome.tabs.executeScript(null, {file: "js/view_iframe_init.js"}, function(){
chrome.tabs.executeScript(null, {code: "var view = new View('"+ tab.url +"');view.toggle();"});
chrome.tabs.insertCSS(null, {
file: "css/view_iframe.css"
});
chrome.tabs.executeScript(null, {
file: "js/view_iframe_init.js"
}, function() {
chrome.tabs.executeScript(null, {
code: "var view = new View('" + tab.url + "');view.toggle();"
});
});
}

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
switch (request.code) {
case 'close':
chrome.tabs.executeScript(null, {code: "(new View()).hide()"});
chrome.tabs.executeScript(null, {
code: "(new View()).hide()"
});
break;
case 'newtab':
getKey(function(key) {
Cache.getKey(function(key) {
showDataPageInNewTab(key, request.data.url);
});
break;
Expand Down
65 changes: 65 additions & 0 deletions src/js/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var PARAM_KEY = '__qa',
LANGUAGE_KEY = '__type';

(function() {

var KEY_URL = 'http://liye04.fe.baidu.com/key.php';

function _getKeyFromCache() {
try {
var value = localStorage.getItem(PARAM_KEY);
if (value === "") {
return false;
} else {
var time = localStorage.getItem('time');
if ((new Date(Number(time))).toDateString() === (new Date()).toDateString()) {
return value;
} else {
return false;
}
}
} catch (e) {
return false;
}
return false;
}

function _cacheKeyFromServer(callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function handleStateChange(xhrpe) {
if (xhrpe.srcElement.readyState !== 4) {
return;
}
var response = xhrpe.srcElement.response;
localStorage.setItem(PARAM_KEY, response);
localStorage.setItem('time', Date.now());
if (typeof callback === 'function') callback(response);
};
xhr.open("GET", KEY_URL, true);
xhr.send();
}

var Cache = {
getKey: function(callback) {
var key = _getKeyFromCache();
if (key) {
callback(key);
} else {
_cacheKeyFromServer(callback);
}
},
getLanguage: function() {
try {
language = localStorage.getItem('language');
} catch (e) {}
return language || 'php';
},
setLanguage: function(language) {
try {
localStorage.setItem('language', language);
} catch (e) {}
}
};

window.Cache = Cache;
})();
62 changes: 0 additions & 62 deletions src/js/key.js

This file was deleted.

Loading

0 comments on commit 0743f16

Please sign in to comment.