Skip to content

Commit

Permalink
Disable or enable selection while changing tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
lingjf committed Apr 3, 2014
1 parent 7bc84ed commit 5a900cc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ A Chrome plugin for shanbay.com to recite English vocabulary.
| Backlog Item | Status |
| ------------- | ------------- |
| Refactoring with Backbone and Mustache | Ongoing |
| Forward and backward navigation | Ongoing |
| Disable or enable selection while changing tabs | Done |
| Add help page | Done |
| Query word by spelling similar in input box | Done |
| List out pronounce similar words | Done |
Expand Down
51 changes: 35 additions & 16 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@

var selectWord = null;
var Selected = {};
var Activity = null;

function getSelected() {
if (Activity) {
return Selected[Activity];
} else {
return null;
}
}

function ttsSpeak(utterance) {
if (utterance !== undefined && utterance !== null && utterance.length > 0) {
Expand All @@ -11,14 +19,11 @@ function ttsSpeak(utterance) {
}

function loadContentScriptInAllTabs() {
chrome.windows.getAll({'populate': true}, function(windows) {
for (var i = 0; i < windows.length; i++) {
var tabs = windows[i].tabs;
chrome.windows.getAll({'populate': true}, function(wins) {
for (var i = 0; i < wins.length; i++) {
var tabs = wins[i].tabs;
for (var j = 0; j < tabs.length; j++) {
chrome.tabs.executeScript(
tabs[j].id,
{file: 'content_script.js', allFrames: true}
);
chrome.tabs.executeScript(tabs[j].id, {file: 'content_script.js', allFrames: true});
}
}
});
Expand All @@ -27,22 +32,36 @@ function loadContentScriptInAllTabs() {
function initBackground() {
loadContentScriptInAllTabs();

chrome.windows.getAll({'populate' : true }, function(wins) {
wins.forEach(function(win) {
win.tabs.forEach(function(tab) {
if (tab != undefined && tab.url.indexOf('chrome') !== 0) {
if (tab.highlighted) {
Activity = tab.id;
}
}
});
});
});

chrome.tabs.onActivated.addListener(function(info) {
Activity = info.tabId;
});


chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request['select'] != undefined) {
selectWord = request['select'];
// console.log("background.js select : " + selectWord);
ttsSpeak(selectWord);
if (request['select'] != undefined && Activity) {
Selected[Activity] = request['select'];
// console.log("background.js select : " + Selected[Activity]);
ttsSpeak(Selected[Activity]);
}
});

chrome.runtime.onInstalled.addListener(function(details) {
if (details.reason == "install") {
// console.log("This is a first install!");
chrome.tabs.create({url : 'help.html', selected : true});
} else if (details.reason == "update") {
// var thisVersion = chrome.runtime.getManifest().version;
// console.log("Updated from " + details.previousVersion + " to " + thisVersion + "!");
// chrome.tabs.create({url : 'help.html', selected : true});
// console.log("Updated from " + details.previousVersion + " to " + chrome.runtime.getManifest().version);
}
});
}
Expand Down
8 changes: 6 additions & 2 deletions help.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h2> <span> 3- </span> 打开扇贝网的单词专页 </h2>
<div class='backlog'>
<h2> <span> 4- </span> 超链接中单词划词 </h2>
<p>
超链接中间的单词很难选中,因为一按鼠标网页就跳转了,导致无法选中。 <br>
超链接中间的单词很难选中,因为一点击鼠标网页就跳转了,导致无法选中。 解决方案如下:<br>
选中一段文字,再点击插件的图标<img src="https://raw.githubusercontent.com/lingjf/Shanbay-Plugin/master/image/shellfish-darkblue-19.png" /> ,各个单词会单独列出。 <br>
</p>
<img src="https://raw.githubusercontent.com/lingjf/Shanbay-Plugin/master/image/help-04-01.jpeg" />
Expand All @@ -87,7 +87,7 @@ <h2> <span> 4- </span> 超链接中单词划词 </h2>
<div class='backlog'>
<h2> <span> 5- </span> 单词的出现频率 </h2>
<p>
每 N 个网页出现该单词一次。 <br>
每 N 个网页出现该单词一次。 可以根据频率来决定要不要背诵。<br>
</p>
<img src="https://raw.githubusercontent.com/lingjf/Shanbay-Plugin/master/image/help-05-01.jpeg" />
</div>
Expand Down Expand Up @@ -170,6 +170,10 @@ <h2> <span> 13- </span> 查看读音相同或相似的单词 </h2>
<img src="https://raw.githubusercontent.com/lingjf/Shanbay-Plugin/master/image/help-14-01.jpeg" />
</div>

<div class='backlog'>
<h2> <span> 完毕 </span> </h2>
</div>

</body>

<script src="lib/jquery.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_application_title__",
"version": "1.12",
"version": "1.13",
"description": "A Shanbay plugin to add new word to Shanbay.com easily for reciting and memory. ",
"manifest_version": 2,
"default_locale": "en",
Expand Down
2 changes: 1 addition & 1 deletion popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ $(document).ready(function() {
$('#pronunciation').mouseenter(pronunceWord);

chrome.runtime.getBackgroundPage(function(backgroundPage) {
var words = backgroundPage.selectWord;
var words = backgroundPage.getSelected();
// $('#queryword').prop("placeholder", words);

if (words && words.length > 0) {
Expand Down

0 comments on commit 5a900cc

Please sign in to comment.