Skip to content

Instantly share code, notes, and snippets.

@stattrak-dragonlore
Created May 25, 2010 06:05
Show Gist options
  • Save stattrak-dragonlore/412832 to your computer and use it in GitHub Desktop.
Save stattrak-dragonlore/412832 to your computer and use it in GitHub Desktop.
Index: background.html
===================================================================
--- background.html (revision 15)
+++ background.html (working copy)
@@ -4,6 +4,7 @@
<head><title>Youdao Dictionary Extension</title></head>
<body>
<script type="text/javascript">
+ var disabled = false;
var dictCache = {};
function queryYoudaoDict(word, callback){
var xhr = new XMLHttpRequest();
@@ -28,7 +29,10 @@
xhr.send();
}
function onRequest(request, sender, callback){
- if( request.action == 'query-dict' ){
+ if (request.action == 'query-dict' && disabled)
+ return;
+ if (request.action == 'query-dict' ||
+ request.action == 'query-dict2'){
if( dictCache[request.word] ){
callback(dictCache[request.word]);
}else{
Index: content.js
===================================================================
--- content.js (revision 15)
+++ content.js (working copy)
@@ -91,6 +91,7 @@
document.addEventListener('dblclick', showDict, true);
document.addEventListener('click', hideDict, true);
+/*
(function(){
var timer, prevC, prevO, prevWord;
var isAlpha = function(str){return /[a-zA-Z']+/.test(str)};
@@ -150,3 +151,4 @@
}
}, true);
})();
+*/
\ No newline at end of file
Index: popup.html
===================================================================
--- popup.html (revision 15)
+++ popup.html (working copy)
@@ -1,20 +1,40 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
- <head><title>Youdao Dictionary Extension</title></head>
+ <head><title>Youdao Dictionary Extension</title>
+ <script type="text/javascript">
+ function toggle_disable() {
+ var background = chrome.extension.getBackgroundPage();
+ background.disabled = !background.disabled;
+ if (background.disabled)
+ document.getElementById("disable").children[0].value = "开启";
+ else
+ document.getElementById("disable").children[0].value = "停用";
+ }
+ </script>
+ </head>
<body>
<form name="query-youdao-dict" action="#query" method="POST">
<input type="text" name="word" value=""/><button type="submit">GO</button>
</form>
+ <div id="disable">
+ <input type="button" value="开关" onclick="toggle_disable();"/>
+ </div>
<div style="max-width: 500px; min-width: 200px; height: auto;" id="result"></div>
<script type="text/javascript">
+ if (chrome.extension.getBackgroundPage().disabled)
+ document.getElementById("disable").children[0].value = "开启";
+ else
+ document.getElementById("disable").children[0].value = "停用";
+
+
document.forms[0].elements['word'].focus();
document.forms[0].onsubmit = function(){
var word = this.elements['word'].value;
if( !word ){
return false;
}
- chrome.extension.sendRequest({action: 'query-dict', word: word}, onQuery);
+ chrome.extension.sendRequest({action: 'query-dict2', word: word}, onQuery);
return false;
}
function onQuery(data){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment