Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2020 08 add pleco link4 firefox android #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ It also contains useful features for learners of the Chinese language.
queue.



## Installation

### Chrome
Expand All @@ -46,7 +47,7 @@ The Zhongwen Firefox extension is available via the Firefox Add-Ons site:
https://addons.mozilla.org/en-US/firefox/addon/zhongwen

Simply click on the "Add to Firefox" button to start the installation.

Note that the Addon works both on the PC and Android version of Firefox.

## How Does It Work?
Once Zhongwen is installed on your computer you'll see a little icon showing
Expand Down
37 changes: 27 additions & 10 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,35 @@ let isActivated = false;

let tabIDs = {};

let zhongwenOptions={};

let dict;

loadOptionsPreferences();


function loadOptionsPreferences(){
//need platform info for some features
chrome.runtime.getPlatformInfo(function(info){

zhongwenOptions = window.zhongwenOptions = {
css: localStorage['popupcolor'] || 'yellow',
tonecolors: localStorage['tonecolors'] || 'yes',
fontSize: localStorage['fontSize'] || 'small',
skritterTLD: localStorage['skritterTLD'] || 'com',
zhuyin: localStorage['zhuyin'] || 'no',
grammar: localStorage['grammar'] || 'yes',
simpTrad: localStorage['simpTrad'] || 'classic',
toneColorScheme: localStorage['toneColorScheme'] || 'standard',
platform: localStorage['platform'] || info.os
};

if(info.os=='android'){
zhongwenOptions.openInPlecoOnAndroid=window.zhongwenOptions.openInPlecoOnAndroid=localStorage['openInPlecoOnAndroid'] || 'yes';
}
});
}

let zhongwenOptions = window.zhongwenOptions = {
css: localStorage['popupcolor'] || 'yellow',
tonecolors: localStorage['tonecolors'] || 'yes',
fontSize: localStorage['fontSize'] || 'small',
skritterTLD: localStorage['skritterTLD'] || 'com',
zhuyin: localStorage['zhuyin'] || 'no',
grammar: localStorage['grammar'] || 'yes',
simpTrad: localStorage['simpTrad'] || 'classic',
toneColorScheme: localStorage['toneColorScheme'] || 'standard'
};

function activateExtension(tabId, showHelp) {

Expand Down
15 changes: 15 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,21 @@ function makeHtml(result, showToneColors) {
html += '&hellip;<br/>';
}

if (config.openInPlecoOnAndroid == 'yes') {
let plecoSymbol = document.createElement('span');
let img = document.createElement('IMG');
let url=chrome.runtime.getURL("images/pleco25.png");
img.src=url;
img.className='imgPleco';
let a = document.createElement('a');
a.className="surrImgPleco";
a.href = 'plecoapi://x-callback-url/s?q='+result.data[0][1];
a.appendChild(img);
plecoSymbol.appendChild(a);
html+=plecoSymbol.outerHTML;
}


savedSearchResults = texts;
savedSearchResults.grammar = result.grammar;

Expand Down
12 changes: 12 additions & 0 deletions css/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,15 @@
#zhongwen-window.tonecolor-hanping .tone5 {
color: #a0a0a0;
}

#zhongwen-window .imgPleco {
float:right;
margin-left:2em;
margin-top:2em;
margin-right:0.4em;
height:150%;
}

#zhongwen-window .surrImgPleco {
float:right;
}
Binary file added images/pleco25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ function loadVals() {

const skritterTLD = localStorage['skritterTLD'] || 'com';
document.querySelector(`input[name="skritterTLD"][value="${skritterTLD}"]`).checked = true;

//On Android display Open in Pleco feature
if(chrome.extension.getBackgroundPage().zhongwenOptions.platform == "android"){
const openInPlecoOnAndroid = localStorage['openInPlecoOnAndroid'] || 'yes';
document.querySelector('#openInPlecoOnAndroid').checked = openInPlecoOnAndroid !== 'no';
}
else {
document.querySelector('#openInPlecoOnAndroidContainer').style.display='none'
}
}

function setPopupColor(popupColor) {
Expand Down Expand Up @@ -99,6 +108,9 @@ window.addEventListener('load', () => {
input.addEventListener('change',
() => setOption('skritterTLD', input.getAttribute('value')));
});

document.querySelector('#openInPlecoOnAndroid').addEventListener('change',
(event) => setBooleanOption('openInPlecoOnAndroid', event.target.checked));
});

loadVals();
Expand Down
8 changes: 8 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ <h2 class="mb-3">Other Options</h2>
<label class="custom-control-label" for="skritterTLDcn">skritter.cn</label>
</div>
</div>

<div class="form-group mb-4" id="openInPlecoOnAndroidContainer">
<label>Redirect to Pleco </label>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="openInPlecoOnAndroid" name="openInPlecoOnAndroid">
<label class="custom-control-label" for="openInPlecoOnAndroid">Show the clickable Pleco symbol. A long click is needed to be redirected to the Pleco Application</label>
</div>
</div>
</div>
<script src="js/options.js" type="text/javascript"></script>
</body>
Expand Down