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

Add image search #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Selection = (function() {
copy: true,
speak: true,
translate: true,
image: true,
disable: false
};
const twitterConfig = {
Expand Down Expand Up @@ -102,6 +103,11 @@ const Selection = (function() {
'<path id="svg_19" d="m20,18c-0.121,0 -0.242,-0.043 -0.337,-0.131c-0.363,-0.332 -3.558,-3.283 -4.126,-4.681c-0.104,-0.256 0.02,-0.547 0.275,-0.651c0.253,-0.103 0.547,0.019 0.651,0.275c0.409,1.007 2.936,3.459 3.875,4.319c0.204,0.187 0.217,0.502 0.031,0.707c-0.099,0.107 -0.234,0.162 -0.369,0.162z"/>'+
'</svg>'
};
const imageConfig = {
url: 'https://www.google.com/search?tbm=isch&q=',
icon:
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="selection__icon"><path d="M 100 100 L 300 100 L 200 300 z"/><circle cx="10" cy="12" r="5"/></svg>'
};

let selection = '';
let text = '';
Expand Down Expand Up @@ -170,6 +176,14 @@ const Selection = (function() {
return tsbtn;
}

function imageButton() {
const tsbtn = new Button(imageConfig.icon, function() {
popupwindow(imageConfig.url + text, 'Image', 900, 540);
return false;
});
return tsbtn;
}

function IconStyle() {
const style = document.createElement('style');
style.innerHTML = `.selection__icon{fill:${iconcolor};}`;
Expand All @@ -178,7 +192,7 @@ const Selection = (function() {

function appendIcons() {
const myitems=[{feature:'twitter',call:twitterButton()},{feature:'facebook',call:facebookButton()},{feature:'search',call:searchButton()},{feature:'translate',call:translateButton()},
{feature:'copy',call:copyButton()},{feature:'speak',call:speakButton()}]
{feature:'copy',call:copyButton()},{feature:'speak',call:speakButton()},{feature:'image',call:imageButton()}]
const div = document.createElement('div');
let count = 0;
myitems.forEach((item)=>{
Expand Down Expand Up @@ -304,6 +318,7 @@ const Selection = (function() {
menu.translate = options.translate === undefined ? menu.translate : options.translate;
menu.copy = options.copy === undefined ? menu.copy : options.copy;
menu.speak = options.speak === undefined ? menu.speak : options.speak;
menu.image = options.image === undefined ? menu.image : options.image;
menu.disable = options.disable === undefined ? menu.disable : options.disable;

bgcolor = options.backgroundColor || '#333';
Expand Down