addons/firefox-addons/context-web-search

changeset 0:2050741e9711

Initial revision
author Guido Berhoerster <guido+cws@berhoerster.name>
date Tue Sep 18 22:57:18 2018 +0200 (20 months ago)
parents
children d994aa563372
files COPYING Makefile NEWS README _locales/de/messages.json _locales/en/messages.json background.js icons/context-web-search.svg manifest.json.in
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/COPYING	Tue Sep 18 22:57:18 2018 +0200
     1.3 @@ -0,0 +1,373 @@
     1.4 +Mozilla Public License Version 2.0
     1.5 +==================================
     1.6 +
     1.7 +1. Definitions
     1.8 +--------------
     1.9 +
    1.10 +1.1. "Contributor"
    1.11 +    means each individual or legal entity that creates, contributes to
    1.12 +    the creation of, or owns Covered Software.
    1.13 +
    1.14 +1.2. "Contributor Version"
    1.15 +    means the combination of the Contributions of others (if any) used
    1.16 +    by a Contributor and that particular Contributor's Contribution.
    1.17 +
    1.18 +1.3. "Contribution"
    1.19 +    means Covered Software of a particular Contributor.
    1.20 +
    1.21 +1.4. "Covered Software"
    1.22 +    means Source Code Form to which the initial Contributor has attached
    1.23 +    the notice in Exhibit A, the Executable Form of such Source Code
    1.24 +    Form, and Modifications of such Source Code Form, in each case
    1.25 +    including portions thereof.
    1.26 +
    1.27 +1.5. "Incompatible With Secondary Licenses"
    1.28 +    means
    1.29 +
    1.30 +    (a) that the initial Contributor has attached the notice described
    1.31 +        in Exhibit B to the Covered Software; or
    1.32 +
    1.33 +    (b) that the Covered Software was made available under the terms of
    1.34 +        version 1.1 or earlier of the License, but not also under the
    1.35 +        terms of a Secondary License.
    1.36 +
    1.37 +1.6. "Executable Form"
    1.38 +    means any form of the work other than Source Code Form.
    1.39 +
    1.40 +1.7. "Larger Work"
    1.41 +    means a work that combines Covered Software with other material, in 
    1.42 +    a separate file or files, that is not Covered Software.
    1.43 +
    1.44 +1.8. "License"
    1.45 +    means this document.
    1.46 +
    1.47 +1.9. "Licensable"
    1.48 +    means having the right to grant, to the maximum extent possible,
    1.49 +    whether at the time of the initial grant or subsequently, any and
    1.50 +    all of the rights conveyed by this License.
    1.51 +
    1.52 +1.10. "Modifications"
    1.53 +    means any of the following:
    1.54 +
    1.55 +    (a) any file in Source Code Form that results from an addition to,
    1.56 +        deletion from, or modification of the contents of Covered
    1.57 +        Software; or
    1.58 +
    1.59 +    (b) any new file in Source Code Form that contains any Covered
    1.60 +        Software.
    1.61 +
    1.62 +1.11. "Patent Claims" of a Contributor
    1.63 +    means any patent claim(s), including without limitation, method,
    1.64 +    process, and apparatus claims, in any patent Licensable by such
    1.65 +    Contributor that would be infringed, but for the grant of the
    1.66 +    License, by the making, using, selling, offering for sale, having
    1.67 +    made, import, or transfer of either its Contributions or its
    1.68 +    Contributor Version.
    1.69 +
    1.70 +1.12. "Secondary License"
    1.71 +    means either the GNU General Public License, Version 2.0, the GNU
    1.72 +    Lesser General Public License, Version 2.1, the GNU Affero General
    1.73 +    Public License, Version 3.0, or any later versions of those
    1.74 +    licenses.
    1.75 +
    1.76 +1.13. "Source Code Form"
    1.77 +    means the form of the work preferred for making modifications.
    1.78 +
    1.79 +1.14. "You" (or "Your")
    1.80 +    means an individual or a legal entity exercising rights under this
    1.81 +    License. For legal entities, "You" includes any entity that
    1.82 +    controls, is controlled by, or is under common control with You. For
    1.83 +    purposes of this definition, "control" means (a) the power, direct
    1.84 +    or indirect, to cause the direction or management of such entity,
    1.85 +    whether by contract or otherwise, or (b) ownership of more than
    1.86 +    fifty percent (50%) of the outstanding shares or beneficial
    1.87 +    ownership of such entity.
    1.88 +
    1.89 +2. License Grants and Conditions
    1.90 +--------------------------------
    1.91 +
    1.92 +2.1. Grants
    1.93 +
    1.94 +Each Contributor hereby grants You a world-wide, royalty-free,
    1.95 +non-exclusive license:
    1.96 +
    1.97 +(a) under intellectual property rights (other than patent or trademark)
    1.98 +    Licensable by such Contributor to use, reproduce, make available,
    1.99 +    modify, display, perform, distribute, and otherwise exploit its
   1.100 +    Contributions, either on an unmodified basis, with Modifications, or
   1.101 +    as part of a Larger Work; and
   1.102 +
   1.103 +(b) under Patent Claims of such Contributor to make, use, sell, offer
   1.104 +    for sale, have made, import, and otherwise transfer either its
   1.105 +    Contributions or its Contributor Version.
   1.106 +
   1.107 +2.2. Effective Date
   1.108 +
   1.109 +The licenses granted in Section 2.1 with respect to any Contribution
   1.110 +become effective for each Contribution on the date the Contributor first
   1.111 +distributes such Contribution.
   1.112 +
   1.113 +2.3. Limitations on Grant Scope
   1.114 +
   1.115 +The licenses granted in this Section 2 are the only rights granted under
   1.116 +this License. No additional rights or licenses will be implied from the
   1.117 +distribution or licensing of Covered Software under this License.
   1.118 +Notwithstanding Section 2.1(b) above, no patent license is granted by a
   1.119 +Contributor:
   1.120 +
   1.121 +(a) for any code that a Contributor has removed from Covered Software;
   1.122 +    or
   1.123 +
   1.124 +(b) for infringements caused by: (i) Your and any other third party's
   1.125 +    modifications of Covered Software, or (ii) the combination of its
   1.126 +    Contributions with other software (except as part of its Contributor
   1.127 +    Version); or
   1.128 +
   1.129 +(c) under Patent Claims infringed by Covered Software in the absence of
   1.130 +    its Contributions.
   1.131 +
   1.132 +This License does not grant any rights in the trademarks, service marks,
   1.133 +or logos of any Contributor (except as may be necessary to comply with
   1.134 +the notice requirements in Section 3.4).
   1.135 +
   1.136 +2.4. Subsequent Licenses
   1.137 +
   1.138 +No Contributor makes additional grants as a result of Your choice to
   1.139 +distribute the Covered Software under a subsequent version of this
   1.140 +License (see Section 10.2) or under the terms of a Secondary License (if
   1.141 +permitted under the terms of Section 3.3).
   1.142 +
   1.143 +2.5. Representation
   1.144 +
   1.145 +Each Contributor represents that the Contributor believes its
   1.146 +Contributions are its original creation(s) or it has sufficient rights
   1.147 +to grant the rights to its Contributions conveyed by this License.
   1.148 +
   1.149 +2.6. Fair Use
   1.150 +
   1.151 +This License is not intended to limit any rights You have under
   1.152 +applicable copyright doctrines of fair use, fair dealing, or other
   1.153 +equivalents.
   1.154 +
   1.155 +2.7. Conditions
   1.156 +
   1.157 +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
   1.158 +in Section 2.1.
   1.159 +
   1.160 +3. Responsibilities
   1.161 +-------------------
   1.162 +
   1.163 +3.1. Distribution of Source Form
   1.164 +
   1.165 +All distribution of Covered Software in Source Code Form, including any
   1.166 +Modifications that You create or to which You contribute, must be under
   1.167 +the terms of this License. You must inform recipients that the Source
   1.168 +Code Form of the Covered Software is governed by the terms of this
   1.169 +License, and how they can obtain a copy of this License. You may not
   1.170 +attempt to alter or restrict the recipients' rights in the Source Code
   1.171 +Form.
   1.172 +
   1.173 +3.2. Distribution of Executable Form
   1.174 +
   1.175 +If You distribute Covered Software in Executable Form then:
   1.176 +
   1.177 +(a) such Covered Software must also be made available in Source Code
   1.178 +    Form, as described in Section 3.1, and You must inform recipients of
   1.179 +    the Executable Form how they can obtain a copy of such Source Code
   1.180 +    Form by reasonable means in a timely manner, at a charge no more
   1.181 +    than the cost of distribution to the recipient; and
   1.182 +
   1.183 +(b) You may distribute such Executable Form under the terms of this
   1.184 +    License, or sublicense it under different terms, provided that the
   1.185 +    license for the Executable Form does not attempt to limit or alter
   1.186 +    the recipients' rights in the Source Code Form under this License.
   1.187 +
   1.188 +3.3. Distribution of a Larger Work
   1.189 +
   1.190 +You may create and distribute a Larger Work under terms of Your choice,
   1.191 +provided that You also comply with the requirements of this License for
   1.192 +the Covered Software. If the Larger Work is a combination of Covered
   1.193 +Software with a work governed by one or more Secondary Licenses, and the
   1.194 +Covered Software is not Incompatible With Secondary Licenses, this
   1.195 +License permits You to additionally distribute such Covered Software
   1.196 +under the terms of such Secondary License(s), so that the recipient of
   1.197 +the Larger Work may, at their option, further distribute the Covered
   1.198 +Software under the terms of either this License or such Secondary
   1.199 +License(s).
   1.200 +
   1.201 +3.4. Notices
   1.202 +
   1.203 +You may not remove or alter the substance of any license notices
   1.204 +(including copyright notices, patent notices, disclaimers of warranty,
   1.205 +or limitations of liability) contained within the Source Code Form of
   1.206 +the Covered Software, except that You may alter any license notices to
   1.207 +the extent required to remedy known factual inaccuracies.
   1.208 +
   1.209 +3.5. Application of Additional Terms
   1.210 +
   1.211 +You may choose to offer, and to charge a fee for, warranty, support,
   1.212 +indemnity or liability obligations to one or more recipients of Covered
   1.213 +Software. However, You may do so only on Your own behalf, and not on
   1.214 +behalf of any Contributor. You must make it absolutely clear that any
   1.215 +such warranty, support, indemnity, or liability obligation is offered by
   1.216 +You alone, and You hereby agree to indemnify every Contributor for any
   1.217 +liability incurred by such Contributor as a result of warranty, support,
   1.218 +indemnity or liability terms You offer. You may include additional
   1.219 +disclaimers of warranty and limitations of liability specific to any
   1.220 +jurisdiction.
   1.221 +
   1.222 +4. Inability to Comply Due to Statute or Regulation
   1.223 +---------------------------------------------------
   1.224 +
   1.225 +If it is impossible for You to comply with any of the terms of this
   1.226 +License with respect to some or all of the Covered Software due to
   1.227 +statute, judicial order, or regulation then You must: (a) comply with
   1.228 +the terms of this License to the maximum extent possible; and (b)
   1.229 +describe the limitations and the code they affect. Such description must
   1.230 +be placed in a text file included with all distributions of the Covered
   1.231 +Software under this License. Except to the extent prohibited by statute
   1.232 +or regulation, such description must be sufficiently detailed for a
   1.233 +recipient of ordinary skill to be able to understand it.
   1.234 +
   1.235 +5. Termination
   1.236 +--------------
   1.237 +
   1.238 +5.1. The rights granted under this License will terminate automatically
   1.239 +if You fail to comply with any of its terms. However, if You become
   1.240 +compliant, then the rights granted under this License from a particular
   1.241 +Contributor are reinstated (a) provisionally, unless and until such
   1.242 +Contributor explicitly and finally terminates Your grants, and (b) on an
   1.243 +ongoing basis, if such Contributor fails to notify You of the
   1.244 +non-compliance by some reasonable means prior to 60 days after You have
   1.245 +come back into compliance. Moreover, Your grants from a particular
   1.246 +Contributor are reinstated on an ongoing basis if such Contributor
   1.247 +notifies You of the non-compliance by some reasonable means, this is the
   1.248 +first time You have received notice of non-compliance with this License
   1.249 +from such Contributor, and You become compliant prior to 30 days after
   1.250 +Your receipt of the notice.
   1.251 +
   1.252 +5.2. If You initiate litigation against any entity by asserting a patent
   1.253 +infringement claim (excluding declaratory judgment actions,
   1.254 +counter-claims, and cross-claims) alleging that a Contributor Version
   1.255 +directly or indirectly infringes any patent, then the rights granted to
   1.256 +You by any and all Contributors for the Covered Software under Section
   1.257 +2.1 of this License shall terminate.
   1.258 +
   1.259 +5.3. In the event of termination under Sections 5.1 or 5.2 above, all
   1.260 +end user license agreements (excluding distributors and resellers) which
   1.261 +have been validly granted by You or Your distributors under this License
   1.262 +prior to termination shall survive termination.
   1.263 +
   1.264 +************************************************************************
   1.265 +*                                                                      *
   1.266 +*  6. Disclaimer of Warranty                                           *
   1.267 +*  -------------------------                                           *
   1.268 +*                                                                      *
   1.269 +*  Covered Software is provided under this License on an "as is"       *
   1.270 +*  basis, without warranty of any kind, either expressed, implied, or  *
   1.271 +*  statutory, including, without limitation, warranties that the       *
   1.272 +*  Covered Software is free of defects, merchantable, fit for a        *
   1.273 +*  particular purpose or non-infringing. The entire risk as to the     *
   1.274 +*  quality and performance of the Covered Software is with You.        *
   1.275 +*  Should any Covered Software prove defective in any respect, You     *
   1.276 +*  (not any Contributor) assume the cost of any necessary servicing,   *
   1.277 +*  repair, or correction. This disclaimer of warranty constitutes an   *
   1.278 +*  essential part of this License. No use of any Covered Software is   *
   1.279 +*  authorized under this License except under this disclaimer.         *
   1.280 +*                                                                      *
   1.281 +************************************************************************
   1.282 +
   1.283 +************************************************************************
   1.284 +*                                                                      *
   1.285 +*  7. Limitation of Liability                                          *
   1.286 +*  --------------------------                                          *
   1.287 +*                                                                      *
   1.288 +*  Under no circumstances and under no legal theory, whether tort      *
   1.289 +*  (including negligence), contract, or otherwise, shall any           *
   1.290 +*  Contributor, or anyone who distributes Covered Software as          *
   1.291 +*  permitted above, be liable to You for any direct, indirect,         *
   1.292 +*  special, incidental, or consequential damages of any character      *
   1.293 +*  including, without limitation, damages for lost profits, loss of    *
   1.294 +*  goodwill, work stoppage, computer failure or malfunction, or any    *
   1.295 +*  and all other commercial damages or losses, even if such party      *
   1.296 +*  shall have been informed of the possibility of such damages. This   *
   1.297 +*  limitation of liability shall not apply to liability for death or   *
   1.298 +*  personal injury resulting from such party's negligence to the       *
   1.299 +*  extent applicable law prohibits such limitation. Some               *
   1.300 +*  jurisdictions do not allow the exclusion or limitation of           *
   1.301 +*  incidental or consequential damages, so this exclusion and          *
   1.302 +*  limitation may not apply to You.                                    *
   1.303 +*                                                                      *
   1.304 +************************************************************************
   1.305 +
   1.306 +8. Litigation
   1.307 +-------------
   1.308 +
   1.309 +Any litigation relating to this License may be brought only in the
   1.310 +courts of a jurisdiction where the defendant maintains its principal
   1.311 +place of business and such litigation shall be governed by laws of that
   1.312 +jurisdiction, without reference to its conflict-of-law provisions.
   1.313 +Nothing in this Section shall prevent a party's ability to bring
   1.314 +cross-claims or counter-claims.
   1.315 +
   1.316 +9. Miscellaneous
   1.317 +----------------
   1.318 +
   1.319 +This License represents the complete agreement concerning the subject
   1.320 +matter hereof. If any provision of this License is held to be
   1.321 +unenforceable, such provision shall be reformed only to the extent
   1.322 +necessary to make it enforceable. Any law or regulation which provides
   1.323 +that the language of a contract shall be construed against the drafter
   1.324 +shall not be used to construe this License against a Contributor.
   1.325 +
   1.326 +10. Versions of the License
   1.327 +---------------------------
   1.328 +
   1.329 +10.1. New Versions
   1.330 +
   1.331 +Mozilla Foundation is the license steward. Except as provided in Section
   1.332 +10.3, no one other than the license steward has the right to modify or
   1.333 +publish new versions of this License. Each version will be given a
   1.334 +distinguishing version number.
   1.335 +
   1.336 +10.2. Effect of New Versions
   1.337 +
   1.338 +You may distribute the Covered Software under the terms of the version
   1.339 +of the License under which You originally received the Covered Software,
   1.340 +or under the terms of any subsequent version published by the license
   1.341 +steward.
   1.342 +
   1.343 +10.3. Modified Versions
   1.344 +
   1.345 +If you create software not governed by this License, and you want to
   1.346 +create a new license for such software, you may create and use a
   1.347 +modified version of this License if you rename the license and remove
   1.348 +any references to the name of the license steward (except to note that
   1.349 +such modified license differs from this License).
   1.350 +
   1.351 +10.4. Distributing Source Code Form that is Incompatible With Secondary
   1.352 +Licenses
   1.353 +
   1.354 +If You choose to distribute Source Code Form that is Incompatible With
   1.355 +Secondary Licenses under the terms of this version of the License, the
   1.356 +notice described in Exhibit B of this License must be attached.
   1.357 +
   1.358 +Exhibit A - Source Code Form License Notice
   1.359 +-------------------------------------------
   1.360 +
   1.361 +  This Source Code Form is subject to the terms of the Mozilla Public
   1.362 +  License, v. 2.0. If a copy of the MPL was not distributed with this
   1.363 +  file, You can obtain one at http://mozilla.org/MPL/2.0/.
   1.364 +
   1.365 +If it is not possible or desirable to put the notice in a particular
   1.366 +file, then You may include the notice in a location (such as a LICENSE
   1.367 +file in a relevant directory) where a recipient would be likely to look
   1.368 +for such a notice.
   1.369 +
   1.370 +You may add additional accurate notices of copyright ownership.
   1.371 +
   1.372 +Exhibit B - "Incompatible With Secondary Licenses" Notice
   1.373 +---------------------------------------------------------
   1.374 +
   1.375 +  This Source Code Form is "Incompatible With Secondary Licenses", as
   1.376 +  defined by the Mozilla Public License, v. 2.0.
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Tue Sep 18 22:57:18 2018 +0200
     2.3 @@ -0,0 +1,67 @@
     2.4 +#
     2.5 +# Copyright (C) 2018 Guido Berhoerster <guido+cws@berhoerster.name>
     2.6 +#
     2.7 +# Permission is hereby granted, free of charge, to any person obtaining
     2.8 +# a copy of this software and associated documentation files (the
     2.9 +# "Software"), to deal in the Software without restriction, including
    2.10 +# without limitation the rights to use, copy, modify, merge, publish,
    2.11 +# distribute, sublicense, and/or sell copies of the Software, and to
    2.12 +# permit persons to whom the Software is furnished to do so, subject to
    2.13 +# the following conditions:
    2.14 +#
    2.15 +# The above copyright notice and this permission notice shall be included
    2.16 +# in all copies or substantial portions of the Software.
    2.17 +#
    2.18 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    2.19 +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    2.20 +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    2.21 +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    2.22 +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    2.23 +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    2.24 +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    2.25 +#
    2.26 +
    2.27 +NAME =		context-web-search
    2.28 +VERSION =	1
    2.29 +EXT_NAME =	$(subst -,_,$(NAME))-$(VERSION)
    2.30 +
    2.31 +INKSCAPE := 	inkscape
    2.32 +INFOZIP :=	zip
    2.33 +SED :=		sed
    2.34 +
    2.35 +BITMAP_ICONS =	icons/context-web-search-48.png \
    2.36 +		icons/context-web-search-96.png
    2.37 +DIST_FILES =	manifest.json \
    2.38 +		background.js \
    2.39 +		COPYING \
    2.40 +		NEWS \
    2.41 +		README \
    2.42 +		$(wildcard _locales/*/messages.json) \
    2.43 +		$(BITMAP_ICONS)
    2.44 +
    2.45 +.DEFAULT_TARGET = all
    2.46 +
    2.47 +.PHONY: all extension clean clobber
    2.48 +
    2.49 +all: extension
    2.50 +
    2.51 +extension: $(EXT_NAME).zip
    2.52 +
    2.53 +$(EXT_NAME).zip: $(DIST_FILES)
    2.54 +	$(INFOZIP) $@ $^
    2.55 +
    2.56 +define generate-icon-rule
    2.57 +$1: $(1:%-$(lastword $(subst -, ,$1))=%.svg)
    2.58 +	size=$(lastword $(subst -, ,$(basename $1))); \
    2.59 +	    $(INKSCAPE) -w $$$${size} -h $$$${size} -e $$@ $$<
    2.60 +endef
    2.61 +
    2.62 +$(foreach icon,$(BITMAP_ICONS),$(eval $(call generate-icon-rule,$(icon))))
    2.63 +
    2.64 +manifest.json: manifest.json.in
    2.65 +	$(SED) 's|@VERSION@|$(VERSION)|g' $< >$@
    2.66 +
    2.67 +clean:
    2.68 +	-rm -f $(BITMAP_ICONS) manifest.json
    2.69 +
    2.70 +clobber: clean
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/NEWS	Tue Sep 18 22:57:18 2018 +0200
     3.3 @@ -0,0 +1,2 @@
     3.4 +News
     3.5 +====
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/README	Tue Sep 18 22:57:18 2018 +0200
     4.3 @@ -0,0 +1,43 @@
     4.4 +Context Web Search
     4.5 +==================
     4.6 +
     4.7 +Context Web Search is a Firefox Addon which enables searching for selected
     4.8 +text or link text with any one of the browser's configured search engines via
     4.9 +the page context menu.
    4.10 +
    4.11 +Usage
    4.12 +-----
    4.13 +
    4.14 +In order to search for the currently selected text, open the context menu on
    4.15 +the same page and choose the desired search engine in the submenu named
    4.16 +'Search "<term>" with...'.
    4.17 +
    4.18 +In order to search for the text of a link, make sure no other text is selected
    4.19 +on that page, open the context menu on top of the desired link text and choose
    4.20 +the desired search engine in the submenu named 'Search "<link text>" with...'.
    4.21 +
    4.22 +Contact
    4.23 +-------
    4.24 +
    4.25 +Please send any feedback, translations or bug reports via email to
    4.26 +<guido+cws@berhoerster.name>
    4.27 +
    4.28 +Bug Reports
    4.29 +-----------
    4.30 +
    4.31 +When sending bug reports, please always mention the exact version of the addon
    4.32 +with which the issue occurs as well as the version of Firefox and the operating
    4.33 +system you are using and make sure that you provide sufficient information to
    4.34 +reproduce the issue and include any error messages.
    4.35 +
    4.36 +License
    4.37 +-------
    4.38 +
    4.39 +Except otherwise noted, all files are Copyright (C) 2018 Guido Berhoerster and
    4.40 +distributed under the following license terms:
    4.41 +
    4.42 +Copyright (C) 2018 Guido Berhoerster <guido+cws@berhoerster.name>
    4.43 +
    4.44 +This Source Code Form is subject to the terms of the Mozilla Public
    4.45 +License, v. 2.0. If a copy of the MPL was not distributed with this
    4.46 +file, You can obtain one at http://mozilla.org/MPL/2.0/.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/_locales/de/messages.json	Tue Sep 18 22:57:18 2018 +0200
     5.3 @@ -0,0 +1,30 @@
     5.4 +{
     5.5 +    "extensionName": {
     5.6 +        "message": "Kontext-Websuche",
     5.7 +        "description": "Name of the extension."
     5.8 +    },
     5.9 +    "extensionDescription": {
    5.10 +        "message": "Suche nach dem ausgewählten Text oder Linktext mit einer der konfigurierten Suchmaschinen des Browsers über das Kontextmenü.",
    5.11 +        "description": "Description of the extension."
    5.12 +    },
    5.13 +    "searchSelectionWithEngine": {
    5.14 +        "message": "Suche mit $ENGINENAME$ nach \u201e%s\u201c",
    5.15 +        "description": "Menu item for searching the selected text with one of the browser's search engines",
    5.16 +        "placeholders": {
    5.17 +            "engineName": {
    5.18 +                "content": "$1",
    5.19 +                "example": "DuckDuckGo"
    5.20 +            }
    5.21 +        }
    5.22 +    },
    5.23 +    "searchLinkWithEngine": {
    5.24 +        "message": "Suche mit $ENGINENAME$",
    5.25 +        "description": "Menu item for searching the selected text with one of the browser's search engines",
    5.26 +        "placeholders": {
    5.27 +            "engineName": {
    5.28 +                "content": "$1",
    5.29 +                "example": "DuckDuckGo"
    5.30 +            }
    5.31 +        }
    5.32 +    }
    5.33 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/_locales/en/messages.json	Tue Sep 18 22:57:18 2018 +0200
     6.3 @@ -0,0 +1,30 @@
     6.4 +{
     6.5 +    "extensionName": {
     6.6 +        "message": "Context Web Search",
     6.7 +        "description": "Name of the extension."
     6.8 +    },
     6.9 +    "extensionDescription": {
    6.10 +        "message": "Search for selected text or link text with any one of the browser's configured search engines via the page context menu.",
    6.11 +        "description": "Description of the extension."
    6.12 +    },
    6.13 +    "searchSelectionWithEngine": {
    6.14 +        "message": "Search $ENGINENAME$ for \u201c%s\u201d",
    6.15 +        "description": "Menu item for searching the selected text with one of the browser's search engines",
    6.16 +        "placeholders": {
    6.17 +            "engineName": {
    6.18 +                "content": "$1",
    6.19 +                "example": "DuckDuckGo"
    6.20 +            }
    6.21 +        }
    6.22 +    },
    6.23 +    "searchLinkWithEngine": {
    6.24 +        "message": "Search $ENGINENAME$",
    6.25 +        "description": "Menu item for searching the selected text with one of the browser's search engines",
    6.26 +        "placeholders": {
    6.27 +            "engineName": {
    6.28 +                "content": "$1",
    6.29 +                "example": "DuckDuckGo"
    6.30 +            }
    6.31 +        }
    6.32 +    }
    6.33 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/background.js	Tue Sep 18 22:57:18 2018 +0200
     7.3 @@ -0,0 +1,114 @@
     7.4 +/*
     7.5 + * Copyright (C) 2018 Guido Berhoerster <guido+cws@berhoerster.name>
     7.6 + *
     7.7 + * This Source Code Form is subject to the terms of the Mozilla Public
     7.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     7.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7.10 + */
    7.11 +
    7.12 +'use strict';
    7.13 +
    7.14 +function encodeXML(str) {
    7.15 +    return str.replace(/[<>&'"]/g, c => {
    7.16 +        switch (c) {
    7.17 +            case '<': return '&lt;';
    7.18 +            case '>': return '&gt;';
    7.19 +            case '&': return '&amp;';
    7.20 +            case '\'': return '&apos;';
    7.21 +            case '"': return '&quot;';
    7.22 +        }
    7.23 +    });
    7.24 +}
    7.25 +
    7.26 +function createFavIcon(name) {
    7.27 +    let firstLetter = name.trim().charAt(0);
    7.28 +    if (firstLetter === '') {
    7.29 +        firstLetter = '?';
    7.30 +    }
    7.31 +    let svg = `<svg viewBox="0 0 16 16" ` +
    7.32 +            `xmlns="http://www.w3.org/2000/svg">` +
    7.33 +            `<defs>` +
    7.34 +            `<filter id="ds">` +
    7.35 +            `<feDropShadow dx="0" dy="0" stdDeviation=".5"/>` +
    7.36 +            `</filter>` +
    7.37 +            `</defs>` +
    7.38 +            `<rect width="16" height="16" rx="3" ry="3" fill="#ed00b5"/>` +
    7.39 +            `<text x="8" y="12" alignment-baseline="middle" fill="#fff" ` +
    7.40 +            `filter="url(#ds)" font-family="sans-serif" font-size="11px" ` +
    7.41 +            `font-weight="bold" text-anchor="middle">` +
    7.42 +            `${encodeXML(firstLetter)}</text>` +
    7.43 +            `</svg>`;
    7.44 +    return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`
    7.45 +}
    7.46 +
    7.47 +async function createMenu(isSelection) {
    7.48 +    let searchEngines = await browser.search.get();
    7.49 +    let menuItems = new Set();
    7.50 +    for (let engine of searchEngines) {
    7.51 +        let favIcon = typeof engine.favIconUrl !== 'undefined' ?
    7.52 +                engine.favIconUrl : createFavIcon(engine.name);
    7.53 +        let menuItemId = browser.menus.create({
    7.54 +            id: engine.name,
    7.55 +            title: browser.i18n.getMessage(isSelection ?
    7.56 +                    'searchSelectionWithEngine' : 'searchLinkWithEngine',
    7.57 +                    engine.name.trim()),
    7.58 +            icons: {16: favIcon},
    7.59 +            contexts: ['link', 'selection']
    7.60 +        }, async () => {
    7.61 +            if (browser.runtime.lastError) {
    7.62 +                console.log(`Failed to create menu item:` +
    7.63 +                        `${browser.runtime.lastError}`);
    7.64 +            }
    7.65 +
    7.66 +            // browser.menus.create does not return a promise that can be
    7.67 +            // awaited, thus collect the returned menu item IDs in a set and
    7.68 +            // remove them from this callback which is called when the
    7.69 +            // asynchronous creation function has finished; when the set is
    7.70 +            // empty all creation functions have finished and the menu can be
    7.71 +            // refreshed
    7.72 +            menuItems.delete(menuItemId);
    7.73 +            if (menuItems.size === 0) {
    7.74 +                try {
    7.75 +                    await browser.menus.refresh();
    7.76 +                } catch (e) {
    7.77 +                    console.log(`Failed to refresh menu: ${e.message}`);
    7.78 +                }
    7.79 +            }
    7.80 +        });
    7.81 +        menuItems.add(menuItemId);
    7.82 +    }
    7.83 +}
    7.84 +
    7.85 +browser.menus.onShown.addListener(async (info, tab) => {
    7.86 +    try {
    7.87 +        await createMenu(info.contexts.includes('selection'));
    7.88 +    } catch (e) {
    7.89 +        console.log(e);
    7.90 +    }
    7.91 +});
    7.92 +
    7.93 +browser.menus.onHidden.addListener(async () => {
    7.94 +    try {
    7.95 +        await browser.menus.removeAll();
    7.96 +    } catch (e) {
    7.97 +        console.log(`Failed to remove menu items: ${e.message}`);
    7.98 +    }
    7.99 +    try {
   7.100 +        await browser.menus.refresh();
   7.101 +    } catch (e) {
   7.102 +        console.log(`Failed to refresh menu: ${e.message}`);
   7.103 +    }
   7.104 +});
   7.105 +
   7.106 +browser.menus.onClicked.addListener(async (info, tab) => {
   7.107 +    let query = typeof info.selectionText !== 'undefined' ?
   7.108 +            info.selectionText.trim() : info.linkText.trim();
   7.109 +    try {
   7.110 +        await browser.search.search({
   7.111 +            query: query,
   7.112 +            engine: info.menuItemId
   7.113 +        });
   7.114 +    } catch (e) {
   7.115 +        console.log(`Failed to search for "${query}": ${e.message}`);
   7.116 +    }
   7.117 +});
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/icons/context-web-search.svg	Tue Sep 18 22:57:18 2018 +0200
     8.3 @@ -0,0 +1,14 @@
     8.4 +<!--
     8.5 +Copyright (C) 2018 Guido Berhoerster <guido+cws@berhoerster.name>
     8.6 +
     8.7 +This Source Code Form is subject to the terms of the Mozilla Public
     8.8 +License, v. 2.0. If a copy of the MPL was not distributed with this
     8.9 +file, You can obtain one at http://mozilla.org/MPL/2.0/.
    8.10 +-->
    8.11 +<svg version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
    8.12 +  <rect width="16" height="16" rx="3" ry="3" fill="#ed00b5"/>
    8.13 +  <g stroke="#ffffff" stroke-linecap="round" stroke-width="2" fill="none">
    8.14 +    <circle cx="7" cy="7" r="4"/>
    8.15 +    <path d="m10 10 3 3"/>
    8.16 +  </g>
    8.17 +</svg>
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/manifest.json.in	Tue Sep 18 22:57:18 2018 +0200
     9.3 @@ -0,0 +1,26 @@
     9.4 +{
     9.5 +    "manifest_version": 2,
     9.6 +    "name": "__MSG_extensionName__",
     9.7 +    "version": "@VERSION@",
     9.8 +    "description": "__MSG_extensionDescription__",
     9.9 +    "author": "Guido Berhoerster",
    9.10 +    "homepage_url": "https://code.guido-berhoerster.org/addons/firefox-addons/context-web-search/",
    9.11 +    "default_locale": "en",
    9.12 +    "applications": {
    9.13 +        "gecko": {
    9.14 +            "id": "context-web-search@code.guido-berhoerster.org",
    9.15 +            "strict_min_version": "63.0"
    9.16 +        }
    9.17 +    },
    9.18 +    "icons": {
    9.19 +        "48": "icons/context-web-search-48.png",
    9.20 +        "96": "icons/context-web-search-96.png"
    9.21 +    },
    9.22 +    "permissions": [
    9.23 +        "menus",
    9.24 +        "search"
    9.25 +    ],
    9.26 +    "background": {
    9.27 +        "scripts": [ "background.js" ]
    9.28 +    }
    9.29 +}