Skip to content

Commit

Permalink
add: Chrome插件 V1
Browse files Browse the repository at this point in the history
  • Loading branch information
wendal committed Nov 22, 2012
1 parent f004692 commit 47791f6
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 53 deletions.
2 changes: 0 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/log4j-1.2.16.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/nutz-1.b.46_X.jar"/>
<classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath>
74 changes: 74 additions & 0 deletions chrome/back.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

/* Init */
var textarea;

/* Init */
function init() {
textarea = document.getElementById('url');

chrome.browserAction.setBadgeBackgroundColor(
{
color: [100, 150, 250, 200]
}
);

chrome.browserAction.onClicked.addListener(req);
}

/* Copy */
function copy(obj) {
textarea.value = obj['id'];
textarea.select();
document.execCommand('Copy');
}

/* OK */
function ok() {
chrome.browserAction.setBadgeText(
{
text: 'OK'
}
);

setTimeout(
function() {
chrome.browserAction.setBadgeText(
{
text: ''
}
);
},
3000
);
}

/* Request */
function req(tab) {
/* Leer? */
if ( !tab.url ) return;

/* Init */

/* Request */
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://nutz.cn/api/create/url?data='+tab.url, false);

/* Responce */
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var obj = JSON.parse(xhr.responseText);

if ( obj.ok) {
obj['id'] = "http://nutz.cn/" + obj.code;
copy(obj);
ok();
}
}
};

/* Send */
xhr.send(null);
}

/* Init */
init();
6 changes: 6 additions & 0 deletions chrome/background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<textarea id="url"></textarea>
<script type="text/javascript" src="back.js"></script>
</body>
</html>
Binary file added chrome/icon128.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 chrome/icon16.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 chrome/icon48.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 removed chrome/icon_16.png
Binary file not shown.
16 changes: 11 additions & 5 deletions chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"name": "My First Extension",
"background": {
"page": "background.html"
},
"name": "短点!",
"version": "1.0",
"manifest_version": 2,
"description": "The first extension that I made.",
"description": "短点Chrome插件(nutz.cn)",
"browser_action": {
"default_icon": "icon_16.png",
"default_popup": "popup.html"
"default_name": "短点!",
"default_icon": "nutz-16.ico"
},
"permissions": [
"http://nutz.cn/"
]
],
"icons": { "16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png" }
}
Binary file added chrome/nutz-16.ico
Binary file not shown.
25 changes: 0 additions & 25 deletions chrome/popup.html

This file was deleted.

20 changes: 0 additions & 20 deletions chrome/popup.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/cn/nutz/shortit/module/ApiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static String _ok(long id) {
}

static String _fail(String str) {
return String.format("{'\"ok\":false,\"msg\":\"%s\"}", str);
return String.format("{\"ok\":false,\"msg\":\"%s\"}", str);
}

static final View HTTP_404 = new HttpStatusView(404);
Expand Down

0 comments on commit 47791f6

Please sign in to comment.