├── .deepsource.toml ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .jshintrc ├── .prettierignore ├── .prettierrc ├── .stylelintrc.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── background.js ├── changelog ├── changelog.css ├── changelog.html └── img │ ├── v1.0-add-custom-bang.png │ ├── v1.0-backup-recover.png │ └── v1.0-options.png ├── icons ├── icon-128.png ├── icon-256.png ├── icon-32.png ├── icon-64.png └── icon.svg ├── img ├── firefox-banner.svg ├── promo-1.png ├── promo-1.svg ├── promo-2.png ├── promo-2.svg ├── promo-3.png ├── promo-3.svg ├── promo-4.png ├── promo-4.svg ├── promo-5.png └── promo-5.svg ├── manifest.json ├── options ├── add_edit_bang.css ├── add_edit_bang.html ├── add_edit_bang.js ├── export_import.js ├── fonts │ └── Inter-4.0 │ │ ├── InterVariable.woff2 │ │ └── LICENSE.txt ├── options.css ├── options.html ├── options.js ├── settings.css ├── settings.html └── settings.js ├── utils.js ├── web-ext-config.mjs └── yang.xpi /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "javascript" 5 | 6 | [analyzers.meta] 7 | environment = ["browser"] -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | **Describe the bug** 10 | A clear and concise description of what the bug is. 11 | 12 | **To Reproduce** 13 | Steps to reproduce the behavior: 14 | 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | 28 | - OS: [e.g. Linux 6.10.6] 29 | - Browser [e.g. Firefox] 30 | - Version [e.g. 129.0.2] 31 | 32 | **Smartphone (please complete the following information):** 33 | 34 | - Device: [e.g. Fairphone 4] 35 | - OS: [e.g. Android 14] 36 | - Browser [e.g. Firefox] 37 | - Version [e.g. 129.0.2] 38 | 39 | **Additional context** 40 | Add any other context about the problem here. 41 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "" 5 | labels: feature request 6 | assignees: "" 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 11 | 12 | **Describe the solution you'd like** 13 | A clear and concise description of what you want to happen. 14 | 15 | **Describe alternatives you've considered** 16 | A clear and concise description of any alternative solutions or features you've considered. 17 | 18 | **Additional context** 19 | Add any other context or screenshots about the feature request here. 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.zip 2 | **/.DS_Store 3 | .vscode/ 4 | node_modules/ 5 | package-lock.json 6 | package.json 7 | 8 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esversion": 11 3 | } 4 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | README.md 2 | 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /.stylelintrc.json: -------------------------------------------------------------------------------- 1 | { "extends": ["stylelint-config-standard"] } 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Steps 2 | 3 | 1. Please, **take a look at the** [**open pull 4 | Requests**](https://github.com/dmlls/yang/pulls) and make sure that your 5 | changes haven't been already proposed. 6 | 2. **Communication is key**: Before investing your time on any changes or 7 | implementation, [**start a 8 | discussion**](https://github.com/dmlls/yang/discussions/new?category=ideas) 9 | describing your idea and implementation details. We want to avoid anyone 10 | being hurt because they felt they "wasted their time" implementing a rejected 11 | feature. 12 | 3. Once you have implemented your changes: 13 | 1. Run the JavaScript linter (Node.js is required): 14 | ```console 15 | npx jshint *.js options/*.js 16 | ``` 17 | 2. Run the CSS linter: 18 | ```console 19 | npx stylelint options/*.css 20 | ``` 21 | 3. Lint the entire extension: 22 | ```console 23 | npx web-ext lint 24 | ``` 25 | 4. Format the code: 26 | ```console 27 | npx prettier . --write 28 | ``` 29 | 4. **Test the extension** thoroughly on both desktop and Android. 30 | 5. Finally, open a pull request. Congratulations, you made it! 🥳 31 | 32 |
33 | 34 | ## Useful links 35 | 36 | - [Debugging on Firefox 37 | Desktop](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension#installing) 38 | - [Debugging on Firefox 39 | Android](https://extensionworkshop.com/documentation/develop/developing-extensions-for-firefox-for-android/) 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Yang! - Yet Another Bangs anywhere Firefox extension 4 | 5 |

6 |

7 | 8 |

9 |

Yang!

10 |

Yet Another Bangs anywhere extension

11 |
12 |

13 | 14 | 15 | 16 | 17 | Available in the Chrome Web Store 18 | 19 |

20 | 21 |

22 | 23 | ## 1. What is a Bang? 24 | 25 | Citing DuckDuckGo, who first introduced them back in 2008: 26 | > **Bangs are shortcuts that quickly take you to search results on other 27 | > sites.** For example, when you know you want to search on another site like 28 | > Wikipedia or Amazon, our bangs get you there fastest. A search for [`!w filter 29 | > bubble`](https://duckduckgo.com/?q=!w+filter+bubble) will take you directly to 30 | > Wikipedia. 31 | 32 |
33 | 34 | ## 2. How does the extension work? 35 | 36 | Simply install the extension and use any of the supported [Kagi 37 | Bangs](https://kbe.smaertness.net/). 38 | 39 |
40 | 41 | Bangs can be used at the beginning or at the end of the query, e.g.: 42 | 43 | ```console 44 | !gm here to closest restaurant 45 | ``` 46 | 47 | is equivalent to 48 | 49 | ```console 50 | here to closest restaurant !gm 51 | ``` 52 | 53 |
54 | 55 | Bangs can also be triggered without any query, serving as a bookmark shortcut: 56 | 57 | ```console 58 | !bbc 59 | ``` 60 | 61 |
62 | 63 | ## 3. Features 64 | 65 | |Done? | Feature| Description | 66 | |:-:|:-|:-| 67 | |✅|**Kagi Bangs**| More than 13,500 default bangs included. | 68 | |✅|**Custom Bangs**| You can create your own bangs or override defaults. | 69 | |✅|**Custom Bang Symbol**| Define your own custom symbol(s) to trigger the bangs. | 70 | |✅|**Multiple Target URLs**| Open multiple websites with a single bang. | 71 | |✅|**Custom Base URL**| Specify which URL to open when the bang is triggered without arguments. | 72 | |✅|**Fast Redirections**| Bangs are resolved locally, without Kagi as intermediary1. | 73 | |✅|**Address Bar Trigger**| You can use bangs directly in the URL bar. | 74 | |✅|**Search Engine Trigger**| Bangs also work from the search bar of your favorite search engine. | 75 | |✅|**Backup and Restore**| Never lose your bangs. | 76 | |✅|**Mobile Support**| Yang! is also available on [Firefox Android](https://addons.mozilla.org/en-US/android/addon/yang-addon/). | 77 | |🔜|**Custom Search Engines**| Soon you will be able to add your own custom search engines. | 78 | 79 | 1 This greatly reduces the redirection times, as shown by 80 | [DuckDuckGo !Bangs but 81 | Faster](https://bangs-but-faster.inclushe.com/). 82 | 83 |
84 | 85 |
86 | 87 | ## 4. Supported Engines 88 | 89 | Yang! will be triggered directly from your **address bar** and the **following 90 | sites**: 91 | 92 | | Name | URL | 93 | |-|-| 94 | | Google | https://www.google.com/ 95 | | Bing | https://www.bing.com/ 96 | | Yahoo | https://www.yahoo.com/ 97 | | Ecosia | https://www.ecosia.org/ 98 | | DuckDuckGo | https://duckduckgo.com/ 99 | | Brave Search | https://search.brave.com/ 100 | | Startpage | https://www.startpage.com/ 101 | | Swisscows | https://swisscows.com/ 102 | | SearX(NG) | https://searx.space/ 103 | | Mojeek | https://www.mojeek.com/ 104 | | Qwant | https://www.qwant.com/ 105 | | Kagi | https://kagi.com/ 106 | | You.com | https://you.com/ 107 | | Perplexity AI | https://www.perplexity.ai/ 108 | | Naver | https://www.naver.com/ 109 | | Baidu | https://www.baidu.com/ 110 | | Yandex | https://yandex.com/ 111 | | AOL | https://www.aol.com/ 112 | | Murena | https://spot.ecloud.global/
https://spot.murena.io/ 113 | | MetaGer | https://metager.de/ 114 | | Dogpile | https://www.dogpile.com/ 115 | | Ask.com | https://www.ask.com/ 116 | | Seznam.cz | https://search.seznam.cz/ 117 | | Karma Search | https://karmasearch.org/ 118 | | Mullvad Leta | https://leta.mullvad.net/ 119 | | Good Search | https://good-search.org/ 120 | 121 | Is your favorite search engine not on the list? [Open an 122 | issue](https://github.com/dmlls/yang/issues/new/choose) and we'll add it! 123 | 124 |
125 | 126 | ## 5. FAQs 127 | 128 |
129 | Do bangs sync across devices? 130 |

Yes... and no. Bangs will sync across all the Firefox desktop browsers in which you are logged in with your Firefox account. However, the sync between desktop and mobile is currently unsupported. As a workaround, you can create a backup on desktop and restore it on Android (or vice versa).

131 |
132 | 133 |
134 | Why does Yang! need permissions on a 300+ sites? 135 |

Instead of requesting data access on all sites, we granularly 136 | specify the search-engine sites that Yang! supports (which yeah, they're quite 137 | a few). You can find which sites we request permissions for in the 138 | 139 | manifest.json.

140 |
141 | 142 |
143 | 144 | ## 6. Contributing 145 | 146 | Contributions are always welcome! However, before getting started, please 147 | carefully read the [contribution 148 | guidelines](https://github.com/dmlls/yang/blob/main/CONTRIBUTING.md). 149 | 150 |
151 | 152 | ## 7. Related Extensions 153 | 154 | If you don't like Yang!, there are many [other 155 | options](https://addons.mozilla.org/en-US/firefox/search/?q=bangs), but these 156 | were the most inspiring in the early development of Yang!: 157 | 158 | - [`sophie-glk/bang`](https://github.com/sophie-glk/bang) 159 | - [`Inclushe/duckduckgo-bangs-but-faster`](https://gitlab.com/Inclushe/duckduckgo-bangs-but-faster) 160 | - [`vantezzen/bangs-for-google`](https://github.com/vantezzen/bangs-for-google) 161 | 162 |
163 |

-

164 |
165 | 166 | Yang! logo is a modification of the original DuckDuckGo logo. Its use is 167 | solely transformative, i.e., intended with a further purpose or different 168 | character, and does not substitute under any circumstance for the original use 169 | of the work. 170 | -------------------------------------------------------------------------------- /background.js: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2023-2024 Diego Miguel Lozano 2 | * 3 | * This program is free software: you can redistribute it and//or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | * 16 | * For license information on the libraries used, see LICENSE. 17 | */ 18 | 19 | import { 20 | PreferencePrefix, 21 | Defaults, 22 | fetchSettings, 23 | getBangKey, 24 | } from "./utils.js"; 25 | 26 | // Support for Chromium. 27 | if (typeof browser === "undefined") { 28 | globalThis.browser = chrome; 29 | } 30 | 31 | (async () => { 32 | await fetchSettings(false); 33 | })(); 34 | 35 | browser.runtime.onStartup.addListener(async () => { 36 | await fetchSettings(false); 37 | }); 38 | 39 | browser.webRequest.onBeforeRequest.addListener( 40 | async (details) => { 41 | const url = new URL(details.url); 42 | // Only consider certain requests. 43 | const include = [ 44 | "/search", 45 | "duckduckgo.com/", 46 | "/dsearch", // Startpage add-on 47 | "/web", // swisscows & ask.com 48 | "qwant.com/", 49 | "/entry/should-show-feedback", // perplexity 50 | "/s", // Baidu 51 | "/meta", // metaGer 52 | "/serp", // dogpile 53 | "/search.seznam.cz", 54 | "leta.mullvad.net/", 55 | ].some((value) => url.href.includes(value)); 56 | if (!include) { 57 | return null; 58 | } 59 | // Skip requests for suggestions. 60 | const skip = 61 | [ 62 | "/ac", 63 | "suggest", 64 | "/autosuggest", 65 | "/complete", 66 | "/autocompleter", 67 | "/autocomplete", 68 | "/sugrec", 69 | ].some((path) => url.pathname.includes(path)) || 70 | url.searchParams.get("mod") === "1"; // hack for Baidu 71 | if (skip) { 72 | return null; 73 | } 74 | // Different search engines use different params for the query. 75 | const params = ["q", "p", "query", "text", "eingabe", "wd"]; 76 | let searchQuery = null; 77 | for (const param of params) { 78 | searchQuery = url.searchParams.get(param); 79 | // Some search engines include the query in the request body. 80 | if (!searchQuery) { 81 | const form = details?.requestBody?.formData; 82 | if (form != null && Object.hasOwn(form, param)) { 83 | searchQuery = form[param][0]; 84 | } else if (details?.requestBody?.raw) { 85 | const decodedBody = JSON.parse( 86 | decodeURIComponent( 87 | String.fromCharCode.apply( 88 | null, 89 | new Uint8Array(details.requestBody.raw[0].bytes), 90 | ), 91 | ), 92 | ); 93 | if (Object.hasOwn(decodedBody, param)) { 94 | searchQuery = decodedBody[param]; 95 | } 96 | } 97 | } 98 | if (searchQuery != null) { 99 | break; 100 | } 101 | } 102 | if (!searchQuery) { 103 | return null; 104 | } 105 | browser.storage.session.get(PreferencePrefix.BANG_SYMBOL).then( 106 | function onGot(item) { 107 | const bangSymbol = 108 | item[PreferencePrefix.BANG_SYMBOL] || Defaults.BANG_SYMBOL; 109 | let bang = null; 110 | let query = null; 111 | const searchTerms = searchQuery.split(" "); 112 | if (searchTerms) { 113 | const firstTerm = searchTerms[0].trim(); 114 | const lastTerm = searchTerms[searchTerms.length - 1].trim(); 115 | if (firstTerm.startsWith(bangSymbol)) { 116 | bang = firstTerm.substring(bangSymbol.length); 117 | query = searchTerms.slice(1).join(" "); 118 | } else if (lastTerm.startsWith(bangSymbol)) { 119 | bang = lastTerm.substring(bangSymbol.length); 120 | query = searchTerms.slice(0, -1).join(" "); 121 | } 122 | } 123 | if (bang) { 124 | const bangKey = getBangKey(bang); 125 | browser.storage.session.get(bangKey).then( 126 | function onGot(item) { 127 | // Any matches? 128 | if (Object.hasOwn(item, bangKey)) { 129 | const bangTargets = item[bangKey]; 130 | let targetUrl; 131 | bangTargets.forEach((target, index) => { 132 | if (query.length === 0 && target.baseUrl != null) { 133 | targetUrl = target.baseUrl; 134 | } else { 135 | if (target.urlEncodeQuery) { 136 | query = encodeURIComponent(query); 137 | } 138 | targetUrl = new URL( 139 | target.url.replace("{{{s}}}", query), 140 | ).toString(); 141 | } 142 | // Open first target URL in current tab... 143 | if (index === 0) { 144 | updateTab(details.tabId, targetUrl); 145 | } else { 146 | // ...and the rest in new tabs. 147 | browser.tabs.create({ url: targetUrl, active: false }); 148 | } 149 | }); 150 | } 151 | }, 152 | function onError(error) { 153 | // TODO: Handle error. 154 | }, 155 | ); 156 | } 157 | }, 158 | function onError(error) { 159 | // TODO: Handle error. 160 | }, 161 | ); 162 | return null; 163 | }, 164 | { 165 | urls: [""], 166 | }, 167 | ["requestBody"], 168 | ); 169 | 170 | function updateTab(tabId, url) { 171 | const updateProperties = { url }; 172 | if (tabId != null) { 173 | browser.tabs.update(tabId, updateProperties); 174 | } else { 175 | browser.tabs.update(updateProperties); 176 | } 177 | } 178 | 179 | browser.action.onClicked.addListener(() => { 180 | browser.tabs.create({ 181 | url: browser.runtime.getURL("options/options.html"), 182 | }); 183 | }); 184 | 185 | // Temporal function to migrate storage schema. 186 | async function updateStorageSchema() { 187 | const customBangs = await browser.storage.sync.get(); 188 | if (Object.keys(customBangs).length > 0) { 189 | const sortedBangs = Object.fromEntries( 190 | Object.entries(customBangs) 191 | .sort(([, a], [, b]) => a.order - b.order) 192 | .map(([bangKey, bang], index) => { 193 | if ( 194 | !bangKey.startsWith(PreferencePrefix.BANG) && 195 | !bangKey.startsWith(PreferencePrefix.BANG_SYMBOL) && 196 | !bangKey.startsWith(PreferencePrefix.SEARCH_ENGINE) 197 | ) { 198 | bangKey = getBangKey(bang.bang); 199 | } 200 | if ( 201 | !bangKey.startsWith(PreferencePrefix.BANG_SYMBOL) && 202 | !bangKey.startsWith(PreferencePrefix.SEARCH_ENGINE) 203 | ) { 204 | bang.order = index; 205 | } 206 | // v1.0.0 207 | if (bang.url != null && !Array.isArray(bang.url)) { 208 | bang.targets = [ 209 | { 210 | url: bang.url, 211 | baseUrl: bang.openBaseUrl ? new URL(bang.url).origin : null, 212 | urlEncodeQuery: bang.urlEncodeQuery, 213 | }, 214 | ]; 215 | delete bang.url; 216 | delete bang.openBaseUrl; 217 | delete bang.urlEncodeQuery; 218 | } 219 | return [bangKey, bang]; 220 | }), 221 | ); 222 | if (!Object.hasOwn(customBangs, PreferencePrefix.BANG_SYMBOL)) { 223 | customBangs[PreferencePrefix.BANG_SYMBOL] = "!"; 224 | } 225 | await browser.storage.sync.clear().then( 226 | async function onCleared() { 227 | await browser.storage.sync.set(sortedBangs).then( 228 | async function onSet() { 229 | await fetchSettings(true); 230 | }, 231 | async function onError(error) { 232 | await browser.storage.sync.set(sortedBangs); // Retry 233 | await fetchSettings(true); 234 | }, 235 | ); 236 | }, 237 | function onError(error) { 238 | // TODO: Handle errors. 239 | }, 240 | ); 241 | } 242 | } 243 | 244 | browser.runtime.onInstalled.addListener(async ({ reason, temporary }) => { 245 | // if (temporary) return; // skip during development 246 | switch (reason) { 247 | case "update": 248 | updateStorageSchema(); 249 | break; 250 | default: 251 | break; 252 | } 253 | }); 254 | -------------------------------------------------------------------------------- /changelog/changelog.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: InterVariable; 3 | font-style: normal; 4 | font-weight: 100 900; 5 | font-display: swap; 6 | src: url("../options/fonts/Inter-4.0/InterVariable.woff2") format("woff2"); 7 | } 8 | 9 | body { 10 | font-family: InterVariable, sans-serif; 11 | font-size: 1.1em; 12 | margin: 0; 13 | padding: 0; 14 | background-color: #f5f5f5; 15 | } 16 | 17 | .container { 18 | max-width: 60%; 19 | margin: 50px auto; 20 | text-align: center; 21 | background-color: #fff; 22 | box-shadow: 0 0 10px rgba(0 0 0 0.1); 23 | border-radius: 8px; 24 | padding: 2em; 25 | overflow-x: hidden; 26 | } 27 | 28 | h1, 29 | h3 { 30 | color: #333; 31 | font-weight: normal; 32 | } 33 | 34 | h2 { 35 | color: #7914ad; 36 | } 37 | 38 | p { 39 | text-align: justify; 40 | line-height: 1.5em; 41 | } 42 | 43 | li { 44 | text-align: justify; 45 | line-height: 1.2em; 46 | margin-bottom: 1em; 47 | } 48 | 49 | hr { 50 | width: 30%; 51 | border: none; 52 | height: 1px; 53 | background-color: #6a6a6a; 54 | } 55 | 56 | code { 57 | font-family: monospace; 58 | background-color: #f4f4f4; 59 | padding: 0.2em; 60 | border: 1px solid #ccc; 61 | border-radius: 4px; 62 | font-weight: bold; 63 | } 64 | 65 | img { 66 | width: 95%; 67 | display: block; 68 | margin: 50px auto; 69 | margin-bottom: 100px; 70 | filter: drop-shadow(0 12px 20px #5858584d); 71 | } 72 | 73 | #v1-0-add-custom-bang, 74 | #v1-0-backup-recover { 75 | width: 70%; 76 | } 77 | 78 | .header { 79 | display: flex; 80 | justify-content: end; 81 | padding: 20px; 82 | } 83 | 84 | #homepage { 85 | display: flex; 86 | align-items: center; 87 | gap: 8px; 88 | text-decoration: none; 89 | font-size: 0.9em; 90 | } 91 | 92 | .logo-container { 93 | margin-top: 50px; 94 | margin-bottom: 100px; 95 | } 96 | 97 | #github-logo { 98 | margin-bottom: 2px; 99 | } 100 | 101 | #yang-logo { 102 | width: 15%; 103 | margin: 0 auto; 104 | } 105 | 106 | .update { 107 | width: 75%; 108 | text-align: start; 109 | margin: 50px auto; 110 | font-size: medium; 111 | } 112 | 113 | @media screen and (width < 1000px) { 114 | .container { 115 | max-width: 100%; 116 | height: 100vh; 117 | margin: 0; 118 | padding: 0; 119 | } 120 | 121 | .update { 122 | width: 85%; 123 | } 124 | 125 | p, 126 | li { 127 | text-align: start; 128 | } 129 | 130 | #yang-logo { 131 | width: 25%; 132 | margin-top: 20px; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /changelog/changelog.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Yang! – Changelog 8 | 9 | 10 | 11 |
12 | 37 |
38 | 39 |

Yang!

40 |

Yet Another Bangs anywhere extension

41 |
42 |
43 |
44 |

v1.0 – Custom Bangs are here! (2024-01)

45 |

46 | Yang now allows you to specify your own bangs. Bangs are synced 48 | across devices! 🥳 50 |

51 |

52 | To create your own bangs, click on the extension and you'll be taken 53 | to the options page with your custom bangs (initially empty). 54 |

55 | Custom Bangs screen. 60 |

61 | In order to add a new custom bang, click on + Add Bang. 62 | Then input: 63 |

64 |
    65 |
  • 66 | Name: How you want to call the bang. This is just for you to 67 | quickly identify bangs. 68 |
  • 69 |
  • 70 | URL: The URL that the bang targets. Don't forget to specify 71 | the part that should be replace with {{{s}}}. 72 |
  • 73 |
  • 74 | Bang: The bang (shortcut) itself. If a bang is already 75 | defined by DuckDuckGo, this one will have preference. 76 |
  • 77 |
  • 78 | URL Encode Query: Whether the query (i.e., what comes after 79 | the bang) must be 80 | encoded 81 | or not. It is recommended to only turn it on when a bang doesn't 82 | work well without this setting. 83 |
  • 84 |
85 | Add custom bangs screen. 90 |

91 | Furthermore, you can back up or restore your bangs at any point. For 92 | that, scroll down and click on Backup / Restore. 93 |

94 |

95 | Once there, click on ⟳ Load Bangs to restore your custom 96 | bangs from a backup file, or ↓ Save Bangs to create a new 97 | backup file. 98 |

99 |

100 | Existent bangs will not be deleted when loading a backup, although any 101 | common bangs will be overwritten by the backup. 102 |

103 | Add custom bangs screen. 108 |
109 |
110 | 111 | 112 | -------------------------------------------------------------------------------- /changelog/img/v1.0-add-custom-bang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/changelog/img/v1.0-add-custom-bang.png -------------------------------------------------------------------------------- /changelog/img/v1.0-backup-recover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/changelog/img/v1.0-backup-recover.png -------------------------------------------------------------------------------- /changelog/img/v1.0-options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/changelog/img/v1.0-options.png -------------------------------------------------------------------------------- /icons/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/icons/icon-128.png -------------------------------------------------------------------------------- /icons/icon-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/icons/icon-256.png -------------------------------------------------------------------------------- /icons/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/icons/icon-32.png -------------------------------------------------------------------------------- /icons/icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/icons/icon-64.png -------------------------------------------------------------------------------- /icons/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 112 | -------------------------------------------------------------------------------- /img/promo-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/img/promo-1.png -------------------------------------------------------------------------------- /img/promo-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/img/promo-2.png -------------------------------------------------------------------------------- /img/promo-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/img/promo-3.png -------------------------------------------------------------------------------- /img/promo-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/img/promo-4.png -------------------------------------------------------------------------------- /img/promo-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/img/promo-5.png -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "Yang! - Yet Another Bangs anywhere extension", 4 | "description": "An open-source, lightweight extension that allows using DuckDuckGo-like bangs anywhere.", 5 | "homepage_url": "https://github.com/dmlls/yang", 6 | "version": "1.0.4", 7 | 8 | "browser_specific_settings": { 9 | "gecko": { 10 | "id": "{0a3250b1-58e0-48cb-9383-428f5adc3dc1}", 11 | "strict_min_version": "115.0" 12 | }, 13 | "gecko-android": { 14 | "strict_min_version": "120.0" 15 | } 16 | }, 17 | 18 | "icons": { 19 | "32": "icons/icon-32.png", 20 | "64": "icons/icon-64.png", 21 | "128": "icons/icon-128.png", 22 | "256": "icons/icon-256.png" 23 | }, 24 | 25 | "permissions": ["webRequest", "activeTab", "storage"], 26 | 27 | "host_permissions": [ 28 | "*://www.google.com/search*", 29 | "*://www.google.ad/search*", 30 | "*://www.google.ae/search*", 31 | "*://www.google.com.af/search*", 32 | "*://www.google.com.ag/search*", 33 | "*://www.google.com.ai/search*", 34 | "*://www.google.al/search*", 35 | "*://www.google.am/search*", 36 | "*://www.google.co.ao/search*", 37 | "*://www.google.com.ar/search*", 38 | "*://www.google.as/search*", 39 | "*://www.google.at/search*", 40 | "*://www.google.com.au/search*", 41 | "*://www.google.az/search*", 42 | "*://www.google.ba/search*", 43 | "*://www.google.com.bd/search*", 44 | "*://www.google.be/search*", 45 | "*://www.google.bf/search*", 46 | "*://www.google.bg/search*", 47 | "*://www.google.com.bh/search*", 48 | "*://www.google.bi/search*", 49 | "*://www.google.bj/search*", 50 | "*://www.google.com.bn/search*", 51 | "*://www.google.com.bo/search*", 52 | "*://www.google.com.br/search*", 53 | "*://www.google.bs/search*", 54 | "*://www.google.bt/search*", 55 | "*://www.google.co.bw/search*", 56 | "*://www.google.by/search*", 57 | "*://www.google.com.bz/search*", 58 | "*://www.google.ca/search*", 59 | "*://www.google.cd/search*", 60 | "*://www.google.cf/search*", 61 | "*://www.google.cg/search*", 62 | "*://www.google.ch/search*", 63 | "*://www.google.ci/search*", 64 | "*://www.google.co.ck/search*", 65 | "*://www.google.cl/search*", 66 | "*://www.google.cm/search*", 67 | "*://www.google.cn/search*", 68 | "*://www.google.com.co/search*", 69 | "*://www.google.co.cr/search*", 70 | "*://www.google.com.cu/search*", 71 | "*://www.google.cv/search*", 72 | "*://www.google.com.cy/search*", 73 | "*://www.google.cz/search*", 74 | "*://www.google.de/search*", 75 | "*://www.google.dj/search*", 76 | "*://www.google.dk/search*", 77 | "*://www.google.dm/search*", 78 | "*://www.google.com.do/search*", 79 | "*://www.google.dz/search*", 80 | "*://www.google.com.ec/search*", 81 | "*://www.google.ee/search*", 82 | "*://www.google.com.eg/search*", 83 | "*://www.google.es/search*", 84 | "*://www.google.com.et/search*", 85 | "*://www.google.fi/search*", 86 | "*://www.google.com.fj/search*", 87 | "*://www.google.fm/search*", 88 | "*://www.google.fr/search*", 89 | "*://www.google.ga/search*", 90 | "*://www.google.ge/search*", 91 | "*://www.google.gg/search*", 92 | "*://www.google.com.gh/search*", 93 | "*://www.google.com.gi/search*", 94 | "*://www.google.gl/search*", 95 | "*://www.google.gm/search*", 96 | "*://www.google.gr/search*", 97 | "*://www.google.com.gt/search*", 98 | "*://www.google.gy/search*", 99 | "*://www.google.com.hk/search*", 100 | "*://www.google.hn/search*", 101 | "*://www.google.hr/search*", 102 | "*://www.google.ht/search*", 103 | "*://www.google.hu/search*", 104 | "*://www.google.co.id/search*", 105 | "*://www.google.ie/search*", 106 | "*://www.google.co.il/search*", 107 | "*://www.google.im/search*", 108 | "*://www.google.co.in/search*", 109 | "*://www.google.iq/search*", 110 | "*://www.google.is/search*", 111 | "*://www.google.it/search*", 112 | "*://www.google.je/search*", 113 | "*://www.google.com.jm/search*", 114 | "*://www.google.jo/search*", 115 | "*://www.google.co.jp/search*", 116 | "*://www.google.co.ke/search*", 117 | "*://www.google.com.kh/search*", 118 | "*://www.google.ki/search*", 119 | "*://www.google.kg/search*", 120 | "*://www.google.co.kr/search*", 121 | "*://www.google.com.kw/search*", 122 | "*://www.google.kz/search*", 123 | "*://www.google.la/search*", 124 | "*://www.google.com.lb/search*", 125 | "*://www.google.li/search*", 126 | "*://www.google.lk/search*", 127 | "*://www.google.co.ls/search*", 128 | "*://www.google.lt/search*", 129 | "*://www.google.lu/search*", 130 | "*://www.google.lv/search*", 131 | "*://www.google.com.ly/search*", 132 | "*://www.google.co.ma/search*", 133 | "*://www.google.md/search*", 134 | "*://www.google.me/search*", 135 | "*://www.google.mg/search*", 136 | "*://www.google.mk/search*", 137 | "*://www.google.ml/search*", 138 | "*://www.google.com.mm/search*", 139 | "*://www.google.mn/search*", 140 | "*://www.google.ms/search*", 141 | "*://www.google.com.mt/search*", 142 | "*://www.google.mu/search*", 143 | "*://www.google.mv/search*", 144 | "*://www.google.mw/search*", 145 | "*://www.google.com.mx/search*", 146 | "*://www.google.com.my/search*", 147 | "*://www.google.co.mz/search*", 148 | "*://www.google.com.na/search*", 149 | "*://www.google.com.ng/search*", 150 | "*://www.google.com.ni/search*", 151 | "*://www.google.ne/search*", 152 | "*://www.google.nl/search*", 153 | "*://www.google.no/search*", 154 | "*://www.google.com.np/search*", 155 | "*://www.google.nr/search*", 156 | "*://www.google.nu/search*", 157 | "*://www.google.co.nz/search*", 158 | "*://www.google.com.om/search*", 159 | "*://www.google.com.pa/search*", 160 | "*://www.google.com.pe/search*", 161 | "*://www.google.com.pg/search*", 162 | "*://www.google.com.ph/search*", 163 | "*://www.google.com.pk/search*", 164 | "*://www.google.pl/search*", 165 | "*://www.google.pn/search*", 166 | "*://www.google.com.pr/search*", 167 | "*://www.google.ps/search*", 168 | "*://www.google.pt/search*", 169 | "*://www.google.com.py/search*", 170 | "*://www.google.com.qa/search*", 171 | "*://www.google.ro/search*", 172 | "*://www.google.ru/search*", 173 | "*://www.google.rw/search*", 174 | "*://www.google.com.sa/search*", 175 | "*://www.google.com.sb/search*", 176 | "*://www.google.sc/search*", 177 | "*://www.google.se/search*", 178 | "*://www.google.com.sg/search*", 179 | "*://www.google.sh/search*", 180 | "*://www.google.si/search*", 181 | "*://www.google.sk/search*", 182 | "*://www.google.com.sl/search*", 183 | "*://www.google.sn/search*", 184 | "*://www.google.so/search*", 185 | "*://www.google.sm/search*", 186 | "*://www.google.sr/search*", 187 | "*://www.google.st/search*", 188 | "*://www.google.com.sv/search*", 189 | "*://www.google.td/search*", 190 | "*://www.google.tg/search*", 191 | "*://www.google.co.th/search*", 192 | "*://www.google.com.tj/search*", 193 | "*://www.google.tl/search*", 194 | "*://www.google.tm/search*", 195 | "*://www.google.tn/search*", 196 | "*://www.google.to/search*", 197 | "*://www.google.com.tr/search*", 198 | "*://www.google.tt/search*", 199 | "*://www.google.com.tw/search*", 200 | "*://www.google.co.tz/search*", 201 | "*://www.google.com.ua/search*", 202 | "*://www.google.co.ug/search*", 203 | "*://www.google.co.uk/search*", 204 | "*://www.google.com.uy/search*", 205 | "*://www.google.co.uz/search*", 206 | "*://www.google.com.vc/search*", 207 | "*://www.google.co.ve/search*", 208 | "*://www.google.vg/search*", 209 | "*://www.google.co.vi/search*", 210 | "*://www.google.com.vn/search*", 211 | "*://www.google.vu/search*", 212 | "*://www.google.ws/search*", 213 | "*://www.google.rs/search*", 214 | "*://www.google.co.za/search*", 215 | "*://www.google.co.zm/search*", 216 | "*://www.google.co.zw/search*", 217 | "*://www.google.cat/search*", 218 | 219 | "*://www.bing.com/search*", 220 | 221 | "*://*.yahoo.com/search*", 222 | 223 | "*://www.ecosia.org/search*", 224 | 225 | "*://duckduckgo.com/bang.js", 226 | "*://duckduckgo.com/*", 227 | "*://lite.duckduckgo.com/lite*", 228 | "*://html.duckduckgo.com/html*", 229 | 230 | "*://search.brave.com/search*", 231 | 232 | "*://www.startpage.com/sp/search*", 233 | "*://eu.startpage.com/sp/search*", 234 | "*://us.startpage.com/sp/search*", 235 | 236 | "*://swisscows.com/*/web*", 237 | 238 | "*://paulgo.io/search*", 239 | "*://searx.hu/search*", 240 | "*://priv.au/search*", 241 | "*://searxng.site/search*", 242 | "*://search.rhscz.eu/search*", 243 | "*://search.bus-hit.me/search*", 244 | "*://s.mble.dk/search*", 245 | "*://search.indst.eu/search*", 246 | "*://search.demoniak.ch/search*", 247 | "*://searxng.ca/search*", 248 | "*://searx.be/search*", 249 | "*://search.inetol.net/search*", 250 | "*://search.disroot.org/search*", 251 | "*://search.privacyguides.net/search*", 252 | "*://searx.rhscz.eu/search*", 253 | "*://search.hbubli.cc/search*", 254 | "*://search.im-in.space/search*", 255 | "*://searx.catfluori.de/search*", 256 | "*://searxng.ch/search*", 257 | "*://searx.tuxcloud.net/search*", 258 | "*://opnxng.com/search*", 259 | "*://searx.ari.lt/search*", 260 | "*://search.sapti.me/search*", 261 | "*://searx.techsaviours.org/search*", 262 | "*://search.leptons.xyz/search*", 263 | "*://ooglester.com/search*", 264 | "*://searx.work/search*", 265 | "*://searxng.online/search*", 266 | "*://www.gruble.de/search*", 267 | "*://copp.gg/search*", 268 | "*://searx.daetalytica.io/search*", 269 | "*://search.citw.lgbt/search*", 270 | "*://search.rowie.at/search*", 271 | "*://searx.dresden.network/search*", 272 | "*://searx.foss.family/search*", 273 | "*://search.projectsegfau.lt/search*", 274 | "*://search.ononoki.org/search*", 275 | "*://baresearch.org/search*", 276 | "*://searx.tiekoetter.com/search*", 277 | "*://searx.fi/search*", 278 | "*://xo.wtf/search*", 279 | "*://etsi.me/search*", 280 | "*://darmarit.org/searx/search*", 281 | "*://search.smnz.de/search*", 282 | "*://searx.oakleycord.dev/search*", 283 | "*://search.mdosch.de/search*", 284 | "*://searx.si/search*", 285 | "*://coppedge.info/search*", 286 | "*://s.frlt.one/search*", 287 | "*://searx.namejeff.xyz/search*", 288 | "*://searx.baczek.me/search*", 289 | "*://searx.sev.monster/search*", 290 | "*://searx.mha.fi/search*", 291 | "*://search.us.projectsegfau.lt/search*", 292 | "*://search.gcomm.ch/search*", 293 | "*://s.trung.fun/search*", 294 | "*://www.jabber-germany.de/searx/search*", 295 | "*://searx.juancord.xyz/search*", 296 | "*://search.zzls.xyz/search*", 297 | "*://searx.rasp.fr/search*", 298 | "*://search.charleseroop.com/search*", 299 | "*://search.suenram.us/search*", 300 | "*://searx.netzspielplatz.de/search*", 301 | "*://searx.orion-hub.fr/search*", 302 | "*://searx.gnous.eu/search*", 303 | "*://searx.mastodontech.de/search*", 304 | "*://searx.ru/search*", 305 | "*://searx.gnu.style/search*", 306 | "*://searx.roflcopter.fr/search*", 307 | "*://sx.catgirl.cloud/search*", 308 | "*://suche.tromdienste.de/search*", 309 | "*://searx.divided-by-zero.eu/search*", 310 | "*://searx.nixnet.services/search*", 311 | "*://searx.fossencdi.org/search*", 312 | "*://searx.absturztau.be/search*", 313 | "*://nogoo.me/search*", 314 | 315 | "*://www.mojeek.com/search*", 316 | 317 | "*://www.qwant.com/", 318 | "*://api.qwant.com/*/search*", 319 | 320 | "*://you.com/search*", 321 | 322 | "*://kagi.com/search*", 323 | 324 | "*://search.naver.com/search.naver*", 325 | 326 | "*://yandex.com/search*", 327 | 328 | "*://search.aol.com/*/search*", 329 | "*://suche.aol.de/*/search*", 330 | 331 | "*://spot.ecloud.global/search*", 332 | "*://spot.murena.io/search*", 333 | 334 | "*://metager.de/meta/*", 335 | 336 | "*://www.dogpile.com/serp*", 337 | 338 | "*://www.ask.com/*", 339 | "*://www.askjeeves.com/*", 340 | 341 | "*://www.baidu.com/*", 342 | 343 | "*://search.seznam.cz/*", 344 | 345 | "*://www.perplexity.ai/*", 346 | 347 | "*://*.karmasearch.org/*", 348 | 349 | "*://leta.mullvad.net/*", 350 | 351 | "*://good-search.org/*" 352 | ], 353 | 354 | "background": { 355 | "scripts": ["background.js"], 356 | "service_worker": "background.js", 357 | "type": "module" 358 | }, 359 | 360 | "action": { 361 | "default_title": "Yang!" 362 | }, 363 | 364 | "options_ui": { 365 | "page": "options/options.html", 366 | "open_in_tab": true 367 | } 368 | } 369 | -------------------------------------------------------------------------------- /options/add_edit_bang.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: InterVariable; 3 | font-style: normal; 4 | font-weight: 100 900; 5 | font-display: swap; 6 | src: url("fonts/Inter-4.0/InterVariable.woff2") format("woff2"); 7 | } 8 | 9 | body { 10 | opacity: 0; /* Set to 1 when the contents are loaded. */ 11 | font-family: InterVariable, sans-serif; 12 | font-size: 1rem; 13 | margin: 0; 14 | padding: 0; 15 | background-color: #f5f5f5; 16 | } 17 | 18 | a { 19 | color: #0000ff; 20 | } 21 | 22 | h1 { 23 | color: #333; 24 | margin-top: 30px; 25 | margin-bottom: 40px; 26 | font-weight: normal; 27 | } 28 | 29 | label { 30 | display: block; 31 | margin-bottom: 10px; 32 | text-align: start; 33 | width: 30vw; 34 | } 35 | 36 | input { 37 | width: 30vw; 38 | min-width: 30vw; 39 | padding: 8px; 40 | box-sizing: border-box; 41 | border: none; 42 | border: solid 1.5px #aaa; 43 | border-radius: 6px; 44 | font-size: 0.95rem; 45 | } 46 | 47 | input:focus { 48 | outline: 1px solid #0000ff; 49 | } 50 | 51 | input::placeholder { 52 | opacity: 0.7; 53 | color: #5c5c5c; 54 | } 55 | 56 | code { 57 | font-family: monospace; 58 | background-color: #f4f4f4; 59 | padding: 0.2em; 60 | border: 1px solid #ccc; 61 | border-radius: 4px; 62 | color: #133eff; 63 | font-weight: bold; 64 | } 65 | 66 | .container { 67 | max-width: 40%; 68 | margin: 50px auto; 69 | text-align: center; 70 | background-color: #fff; 71 | box-shadow: 0 0 10px rgba(0 0 0 / 10%); 72 | border-radius: 8px; 73 | padding: 2em; 74 | } 75 | 76 | .button-container { 77 | display: flex; 78 | justify-content: center; 79 | margin: 15px 0 30px; 80 | } 81 | 82 | #add-url, 83 | #save { 84 | display: flex; 85 | align-items: center; 86 | justify-content: center; 87 | border-radius: 8px; 88 | cursor: pointer; 89 | transition: 90 | border-radius 0.5s ease, 91 | background 0.3s ease; 92 | } 93 | 94 | #add-url { 95 | padding: 5px 10px; 96 | margin-top: 10px; 97 | font-size: 0.9rem; 98 | background: none; 99 | border: 0.15rem solid #e15e49; 100 | color: #e15e49; 101 | white-space: nowrap; 102 | } 103 | 104 | #add-url:hover { 105 | background: #e15e49; 106 | color: white; 107 | border-radius: 12px; 108 | } 109 | 110 | #add-url.disabled-button { 111 | opacity: 0.6; 112 | cursor: default; 113 | } 114 | 115 | #add-url.disabled-button:hover { 116 | background: none; 117 | color: #e15e49; 118 | } 119 | 120 | #save { 121 | margin: 0 auto 15px; 122 | padding: 15px 25px; 123 | font-size: 1rem; 124 | border: none; 125 | background: #e15e49; 126 | color: #fff; 127 | } 128 | 129 | #save:hover { 130 | background: #a84636; 131 | border-radius: 12px; 132 | } 133 | 134 | #custom-bang-form { 135 | display: flex; 136 | flex-direction: column; 137 | align-items: center; 138 | } 139 | 140 | .back-container { 141 | font-size: 0.9rem; 142 | text-align: left; 143 | } 144 | 145 | .input-container { 146 | display: flex; 147 | flex-direction: column; 148 | align-items: center; 149 | margin-bottom: 40px; 150 | } 151 | 152 | .error-input-border { 153 | border: 1px solid #f00; 154 | } 155 | 156 | .checkbox-container { 157 | display: flex; 158 | width: 30vw; 159 | margin-bottom: 10px; 160 | } 161 | 162 | .base-url-wrapper { 163 | margin-bottom: 10px; 164 | } 165 | 166 | .base-url { 167 | display: none; 168 | width: 100%; 169 | min-width: 100%; 170 | } 171 | 172 | #urls-container, 173 | #draggable-container { 174 | width: 100%; 175 | } 176 | 177 | .bang-option-label { 178 | cursor: pointer; 179 | user-select: none; 180 | } 181 | 182 | .checkbox-container input { 183 | width: auto; 184 | min-width: auto; 185 | margin-right: 10px; 186 | } 187 | 188 | .checkbox-container label { 189 | margin: 0; 190 | } 191 | 192 | .error-message { 193 | display: block; 194 | margin-top: 4px; 195 | text-align: start; 196 | width: 30vw; 197 | color: red; 198 | font-size: 0.87rem; 199 | } 200 | 201 | .tooltip { 202 | position: relative; 203 | display: inline-block; 204 | text-align: center; 205 | margin-left: 0.5em; 206 | top: 1px; 207 | cursor: pointer; 208 | } 209 | 210 | .tooltip-label-wrapper { 211 | width: 100%; 212 | text-align: start; 213 | } 214 | 215 | .tooltip-label { 216 | max-width: fit-content; 217 | } 218 | 219 | .tooltip-text { 220 | visibility: hidden; 221 | position: absolute; 222 | z-index: 1; 223 | color: white; 224 | font-size: small; 225 | background-color: #525252; 226 | border-radius: 5px; 227 | padding: 10px 15px; 228 | margin: 25px 0 0; 229 | line-height: 2em; 230 | } 231 | 232 | .tooltip-text.show { 233 | visibility: visible; 234 | } 235 | 236 | .target-url-container { 237 | width: 100%; 238 | display: flex; 239 | flex-direction: column; 240 | align-items: center; 241 | margin-bottom: 5px; 242 | } 243 | 244 | .target-url-wrapper { 245 | margin-bottom: 10px; 246 | } 247 | 248 | .target-url { 249 | display: flex; 250 | align-items: center; 251 | justify-content: center; 252 | transition: transform 0.2s ease; 253 | } 254 | 255 | .target-url-container.dragging .url { 256 | opacity: 0.5; 257 | transform: scale(1.05); 258 | box-shadow: 0 4px 10px rgba(0 0 0 / 20%); 259 | } 260 | 261 | .url-options-container { 262 | display: none; 263 | padding-left: 1vw; 264 | width: 29vw; 265 | opacity: 0; 266 | } 267 | 268 | .url-options-container.expanded { 269 | display: block; 270 | margin-bottom: 15px; 271 | opacity: 1; 272 | animation: fade 0.2s; 273 | } 274 | 275 | @keyframes fade { 276 | 0% { 277 | opacity: 0; 278 | } 279 | 280 | 100% { 281 | opacity: 1; 282 | } 283 | } 284 | 285 | .action-container { 286 | display: none; 287 | width: 10vw; 288 | } 289 | 290 | .action-container.left { 291 | justify-content: end; 292 | margin-right: 8px; 293 | } 294 | 295 | .action-container.right { 296 | margin-left: 8px; 297 | } 298 | 299 | .action-container > button { 300 | padding: 0; 301 | } 302 | 303 | .target-url:hover > .action-container { 304 | display: flex; 305 | gap: 8px; 306 | } 307 | 308 | .target-url:hover ~ .error-message { 309 | margin-left: calc(10vw + 8px); 310 | } 311 | 312 | .move-up-button, 313 | .move-down-button { 314 | display: none; 315 | } 316 | 317 | .reorder-button, 318 | .move-up-button, 319 | .move-down-button, 320 | .expand-button, 321 | .delete-button { 322 | border: none; 323 | background: none; 324 | padding: 0 8px; 325 | margin: 2px; 326 | color: #494949; 327 | user-select: none; 328 | } 329 | 330 | .reorder-button { 331 | cursor: move; 332 | } 333 | 334 | .move-up-button > svg { 335 | transform: rotate(180deg); 336 | } 337 | 338 | .expand-button > svg { 339 | transform: rotate(90deg); 340 | transition: transform 0.2s ease; 341 | } 342 | 343 | .expand-button.expanded > svg { 344 | transform: rotate(0); 345 | } 346 | 347 | .move-up-button, 348 | .move-down-button, 349 | .expand-button, 350 | .delete-button { 351 | cursor: pointer; 352 | } 353 | 354 | #add-url svg { 355 | margin-left: -2px; 356 | margin-right: 4px; 357 | } 358 | 359 | #save svg { 360 | margin-right: 8px; 361 | } 362 | 363 | .reorder-button:hover { 364 | color: #7814ae; 365 | } 366 | 367 | .delete-button:hover { 368 | color: #c01010; 369 | } 370 | 371 | .label-wrapper { 372 | position: relative; 373 | display: flex; 374 | flex-direction: column; 375 | text-align: start; 376 | align-items: center; 377 | width: 30vw; 378 | } 379 | 380 | .label-wrapper label { 381 | display: inline-block; 382 | width: auto; 383 | } 384 | 385 | @media screen and (width < 1000px) { 386 | html { 387 | background-color: white; 388 | } 389 | 390 | input, 391 | label, 392 | .label-wrapper, 393 | .url-options-container, 394 | .checkbox-container, 395 | .error-message { 396 | width: 65vw; 397 | } 398 | 399 | input { 400 | min-width: 65vw; 401 | } 402 | 403 | .container { 404 | max-width: 100%; 405 | margin: 0; 406 | padding: 0 0 50px; 407 | box-shadow: none; 408 | } 409 | 410 | .form { 411 | width: 90%; 412 | } 413 | 414 | .back-container { 415 | padding: 20px; 416 | } 417 | 418 | .target-url ~ .error-message { 419 | margin-left: calc(10vw + 8px); 420 | } 421 | 422 | .tooltip-text { 423 | width: 110%; 424 | } 425 | } 426 | 427 | @media not (hover: none) { 428 | .label-wrapper:has(.tooltip:hover) .tooltip-text { 429 | visibility: visible; 430 | } 431 | } 432 | 433 | /* Touchscreen devices. */ 434 | @media (hover: none) { 435 | .action-container { 436 | display: flex; 437 | gap: 8px; 438 | } 439 | 440 | .move-up-button, 441 | .move-down-button { 442 | display: block; 443 | } 444 | 445 | .reorder-button { 446 | display: none; 447 | } 448 | 449 | #add-url { 450 | padding: 5px 10px; 451 | margin-top: 10px; 452 | font-size: 0.9rem; 453 | background: none; 454 | border: 0.15rem solid #e15e49; 455 | color: #e15e49; 456 | white-space: nowrap; 457 | } 458 | 459 | #add-url:hover { 460 | background: none; 461 | color: #e15e49; 462 | border-radius: 8px; 463 | } 464 | } 465 | -------------------------------------------------------------------------------- /options/add_edit_bang.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Yang! – Add Bang 9 | 10 | 11 | 12 |
13 | 16 |

Add Custom Bang

17 |
18 |
19 | 20 | 26 |
27 |
28 | 29 | 35 |
36 |
37 |
38 |
39 |
40 | 41 |
42 | 54 | 55 | 56 | 57 | 58 |
59 |
60 |
61 | The {{{s}}} in the URL will be replaced with your 63 | bang 65 |
66 |
67 |
68 |
69 |
70 |
71 | 87 | 103 | 145 |
146 | 152 |
153 | 170 | 189 |
190 |
191 |
192 |
193 |
194 | 199 |
200 |
201 |
202 | 205 |
206 | 218 | 219 | 220 | 221 | 222 |
223 |
224 |
225 | Open a specific URL when the bang is triggered without 227 | arguments 229 |
230 |
231 |
232 | 238 |
239 |
240 | 245 | 248 |
249 |
250 |
251 |
252 | 270 |
271 | 295 |
296 |
297 | 298 | 299 | -------------------------------------------------------------------------------- /options/add_edit_bang.js: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2023-2024 Diego Miguel Lozano 2 | * 3 | * This program is free software: you can redistribute it and//or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | * 16 | * For license information on the libraries used, see LICENSE. 17 | */ 18 | 19 | import { getBangKey, getBangName } from "../utils.js"; 20 | 21 | // Support for Chromium. 22 | if (typeof browser === "undefined") { 23 | globalThis.browser = chrome; 24 | } 25 | 26 | // Mapping from input to the class name of the input. 27 | const FORM_FIELDS = Object.freeze({ 28 | NAME: "name", 29 | BANG: "bang", 30 | URL: "url", 31 | BASE_URL: "base-url", 32 | URL_ENCODE_QUERY: "url-encode-query", 33 | }); 34 | 35 | const LIMITS = Object.freeze({ 36 | // Maximum length for the name of the bang. 37 | MAX_LENGTH_NAME: 100, 38 | // Maximum length for the the bang. 39 | MAX_LENGTH_BANG: 25, 40 | // Maximum length for the the URLs. 41 | MAX_LENGTH_URLS: 250, 42 | // Maximum number of target URLs users can input. 43 | MAX_NUMBER_URLS: 10, 44 | }); 45 | 46 | function validateEmptyOrTooLong(inputElement, containerElement, maxLength) { 47 | const textValue = inputElement.value.trim(); 48 | if (textValue == null || textValue === "") { 49 | showErrorMessage( 50 | inputElement, 51 | containerElement, 52 | "This field cannot be empty.", 53 | ); 54 | return null; 55 | } else if (maxLength !== undefined && textValue.length > maxLength) { 56 | showErrorMessage( 57 | inputElement, 58 | containerElement, 59 | `The input is too long (max. ${maxLength} characters allowed).`, 60 | ); 61 | return null; 62 | } 63 | // Valid. 64 | return textValue; 65 | } 66 | 67 | function validateUrl(inputElement, containerElement) { 68 | let url; 69 | const urlString = inputElement.value.trim(); 70 | try { 71 | url = decodeURIComponent(new URL(urlString)); 72 | } catch (_) { 73 | showErrorMessage( 74 | inputElement, 75 | containerElement, 76 | "Invalid URL (don't forget to include the scheme, e.g., 'https://').", 77 | ); 78 | return null; 79 | } 80 | // Valid. 81 | return url; 82 | } 83 | 84 | async function validateBangKey(oldBangKey, newBangKey) { 85 | if (!newBangKey) { 86 | return null; 87 | } 88 | const bangElement = document.querySelector(`.${FORM_FIELDS.BANG}`); 89 | if (newBangKey == null && oldBangKey === newBangKey) { 90 | return null; 91 | } else if (/\s/.test(newBangKey)) { 92 | showErrorMessage( 93 | bangElement, 94 | bangElement.parentNode, 95 | "The bang cannot contain whitespaces.", 96 | ); 97 | return null; 98 | } 99 | const valid_bang = await browser.storage.sync.get(newBangKey).then( 100 | function onGot(item) { 101 | if (Object.keys(item).length > 0) { 102 | showErrorMessage( 103 | bangElement, 104 | bangElement.parentNode, 105 | "This bang already exists.", 106 | ); 107 | return null; 108 | } else { 109 | // Valid. 110 | return getBangName(newBangKey); 111 | } 112 | }, 113 | function onError(error) { 114 | return null; 115 | }, 116 | ); 117 | return valid_bang; 118 | } 119 | 120 | function getInputtedBang() { 121 | const newBang = { 122 | name: null, 123 | bang: null, 124 | targets: [], 125 | }; 126 | newBang.name = document.querySelector(`.${FORM_FIELDS.NAME}`).value.trim(); 127 | newBang.bang = document.querySelector(`.${FORM_FIELDS.BANG}`).value.trim(); 128 | document.querySelectorAll(".target-url-container").forEach((container) => { 129 | const targetUrl = {}; 130 | const baseUrl = container.querySelector( 131 | `.${FORM_FIELDS.BASE_URL}-checkbox`, 132 | ).checked; 133 | [FORM_FIELDS.URL, FORM_FIELDS.BASE_URL].forEach((className, index) => { 134 | const targetField = className === FORM_FIELDS.URL ? "url" : "baseUrl"; 135 | // Nothing to validate. 136 | if (index === 1 && !baseUrl) { 137 | targetUrl[targetField] = null; 138 | } else { 139 | targetUrl[targetField] = container 140 | .querySelector(`.${className}`) 141 | .value.trim(); 142 | } 143 | }); 144 | targetUrl.urlEncodeQuery = container.querySelector( 145 | `.${FORM_FIELDS.URL_ENCODE_QUERY}`, 146 | ).checked; 147 | newBang.targets.push(targetUrl); 148 | }); 149 | return newBang; 150 | } 151 | 152 | async function getAndValidateInputtedBang(last, mode) { 153 | hideAllErrorMessages(); 154 | const newBang = { 155 | name: null, 156 | bang: null, 157 | targets: [], 158 | }; 159 | // Validate name. 160 | const nameInput = document.querySelector(`.${FORM_FIELDS.NAME}`); 161 | newBang.name = validateEmptyOrTooLong( 162 | nameInput, 163 | nameInput.parentNode, 164 | LIMITS.MAX_LENGTH_NAME, 165 | ); 166 | 167 | // Validate bang (Still left to check if the bang does not already exist. This 168 | // is done later.) 169 | const bangInput = document.querySelector(`.${FORM_FIELDS.BANG}`); 170 | let bang = validateEmptyOrTooLong( 171 | bangInput, 172 | bangInput.parentNode, 173 | LIMITS.MAX_LENGTH_NAME, 174 | )?.toLowerCase(); 175 | if (mode === "add" || saveButton.bangKey !== getBangKey(bang)) { 176 | bang = await validateBangKey(saveButton.bangKey, getBangKey(bang)); 177 | } 178 | newBang.bang = bang; 179 | 180 | // Validate target URLs. 181 | let allUrlsValid = true; 182 | document.querySelectorAll(".target-url-container").forEach((container) => { 183 | const targetUrl = {}; 184 | const baseUrl = container.querySelector( 185 | `.${FORM_FIELDS.BASE_URL}-checkbox`, 186 | ).checked; 187 | [FORM_FIELDS.URL, FORM_FIELDS.BASE_URL].forEach((className, index) => { 188 | const targetField = className === FORM_FIELDS.URL ? "url" : "baseUrl"; 189 | // Nothing to validate. 190 | if (index === 1 && !baseUrl) { 191 | targetUrl[targetField] = null; 192 | } else { 193 | const urlInput = container.querySelector(`.${className}`); 194 | const containerElement = 195 | index === 0 ? urlInput.parentNode.parentNode : urlInput.parentNode; 196 | let url = validateEmptyOrTooLong( 197 | urlInput, 198 | containerElement, 199 | LIMITS.MAX_LENGTH_URLS, 200 | ); 201 | if (url != null) { 202 | url = validateUrl(urlInput, containerElement); 203 | } 204 | if ((className === FORM_FIELDS.URL || baseUrl) && url == null) { 205 | allUrlsValid = false; 206 | } 207 | targetUrl[targetField] = url; 208 | } 209 | }); 210 | targetUrl.urlEncodeQuery = container.querySelector( 211 | `.${FORM_FIELDS.URL_ENCODE_QUERY}`, 212 | ).checked; 213 | newBang.targets.push(targetUrl); 214 | }); 215 | newBang.order = mode === "add" ? last + 1 : last; 216 | if (newBang.name != null && newBang.bang != null && allUrlsValid) { 217 | return newBang; 218 | } 219 | return null; 220 | } 221 | 222 | function displayErrorAlert(error) { 223 | const errorMsg = "Error saving bang."; 224 | console.error(errorMsg, error.message); 225 | if ( 226 | error.message.includes("QuotaExceededError") || 227 | error.message.includes("QUOTA_BYTES") 228 | ) { 229 | alert(`${errorMsg} The browser's storage limit has been reached.`); 230 | } else { 231 | alert(`${errorMsg} ${error.message}`); 232 | } 233 | } 234 | 235 | async function saveCustomBang() { 236 | const saveButton = document.getElementById("save"); 237 | const inputtedBang = await getAndValidateInputtedBang( 238 | saveButton.last, 239 | saveButton.mode, 240 | ); 241 | if (inputtedBang != null) { 242 | const inputtedBangKey = getBangKey(inputtedBang.bang); 243 | if (saveButton.mode === "edit") { 244 | // If the bang has changed and does not already exist -> 245 | // Delete the previous one first. 246 | await browser.storage.sync.remove(saveButton.bangKey); 247 | await browser.storage.session.remove(saveButton.bangKey); 248 | } 249 | await browser.storage.sync.set({ [inputtedBangKey]: inputtedBang }).then( 250 | function onSet() { 251 | browser.storage.session 252 | .set({ 253 | [inputtedBangKey]: inputtedBang.targets, 254 | }) 255 | .then( 256 | () => { 257 | window.location.assign("options.html"); 258 | }, 259 | function onError(error) { 260 | displayErrorAlert(error); 261 | }, 262 | ); 263 | }, 264 | function onError(error) { 265 | displayErrorAlert(error); 266 | }, 267 | ); 268 | } 269 | return inputtedBang; 270 | } 271 | 272 | function attachEventListeners() { 273 | const urlContainers = document.querySelectorAll(".target-url-container"); 274 | const urlOptionsContainers = document.querySelectorAll( 275 | ".url-options-container", 276 | ); 277 | const expandButtons = document.querySelectorAll(".expand-button"); 278 | expandButtons.forEach((button, index) => { 279 | if (button.getAttribute("listener") !== "true") { 280 | button.addEventListener("click", () => { 281 | button.classList.toggle("expanded"); 282 | urlOptionsContainers[index].classList.toggle("expanded"); 283 | }); 284 | button.setAttribute("listener", "true"); 285 | } 286 | }); 287 | const deleteButtons = document.querySelectorAll(".delete-button"); 288 | deleteButtons.forEach((button, index) => { 289 | if (button.getAttribute("listener") !== "true") { 290 | button.addEventListener("click", () => { 291 | urlContainers[index].remove(); 292 | // Hide buttons if there is only one target URL. 293 | if (urlContainers.length <= LIMITS.MAX_NUMBER_URLS) { 294 | addUrlButton.disabled = false; 295 | addUrlButton.title = ""; 296 | addUrlButton.classList.remove("disabled-button"); 297 | } 298 | hideActionButtons(urlContainers); 299 | }); 300 | button.setAttribute("listener", "true"); 301 | } 302 | }); 303 | 304 | const urls = document.querySelectorAll(".url"); 305 | const baseUrls = document.querySelectorAll(".base-url"); 306 | const baseUrlCheckboxes = document.querySelectorAll(".base-url-checkbox"); 307 | baseUrlCheckboxes.forEach((checkbox, index) => { 308 | if (checkbox.getAttribute("listener") !== "true") { 309 | checkbox.addEventListener("change", (event) => { 310 | if (event.currentTarget.checked) { 311 | baseUrls[index].value = 312 | urls[index].value.length > 0 313 | ? new URL(urls[index].value).origin 314 | : ""; 315 | baseUrls[index].style.display = "block"; 316 | } else { 317 | baseUrls[index].style.display = "none"; 318 | } 319 | }); 320 | checkbox.setAttribute("listener", "true"); 321 | } 322 | }); 323 | 324 | // Allow to click on labels to toggle checkmarks. 325 | document.querySelectorAll(".bang-option-label").forEach((label) => { 326 | if (label.getAttribute("listener") !== "true") { 327 | label.addEventListener("click", () => { 328 | let parent = label.parentElement; 329 | if (parent.classList.contains("tooltip-label")) { 330 | parent = parent.parentElement.parentElement.parentElement; 331 | } 332 | const checkmark = parent.children[0]; 333 | checkmark.checked = !checkmark.checked; 334 | checkmark.dispatchEvent(new Event("change")); 335 | }); 336 | label.setAttribute("listener", "true"); 337 | } 338 | }); 339 | 340 | const container = document.getElementById("draggable-container"); 341 | const moveUpButtons = document.querySelectorAll(".move-up-button"); 342 | const moveDownButtons = document.querySelectorAll(".move-down-button"); 343 | const reorderButtons = document.querySelectorAll(".reorder-button"); 344 | urlContainers.forEach((urlContainer, index) => { 345 | if (moveUpButtons[index].getAttribute("listener") !== "true") { 346 | moveUpButtons[index].addEventListener("click", () => { 347 | const previousUrl = urlContainer.previousElementSibling; 348 | if (previousUrl) { 349 | urlContainer.parentNode.insertBefore(urlContainer, previousUrl); 350 | } 351 | }); 352 | moveUpButtons[index].setAttribute("listener", "true"); 353 | } 354 | if (moveDownButtons[index].getAttribute("listener") !== "true") { 355 | moveDownButtons[index].addEventListener("click", () => { 356 | const nextUrl = urlContainer.nextElementSibling; 357 | if (nextUrl) { 358 | urlContainer.parentNode.insertBefore(nextUrl, urlContainer); 359 | } 360 | }); 361 | moveDownButtons[index].setAttribute("listener", "true"); 362 | } 363 | if (reorderButtons[index].getAttribute("dragStartListener") !== "true") { 364 | reorderButtons[index].addEventListener("dragstart", (e) => { 365 | e.stopPropagation(); 366 | urlContainer.classList.add("dragging"); 367 | urlOptionsContainers.forEach((urlContainer) => { 368 | urlContainer.classList.remove("expanded"); 369 | }); 370 | expandButtons.forEach((expandButton) => { 371 | expandButton.classList.remove("expanded"); 372 | }); 373 | reorderButtons.forEach((reorderButton) => { 374 | reorderButton.style.opacity = 0.000001; 375 | }); 376 | }); 377 | reorderButtons[index].setAttribute("dragStarListener", "true"); 378 | } 379 | if (reorderButtons[index].getAttribute("dragEndListener") !== "true") { 380 | reorderButtons[index].addEventListener("dragend", () => { 381 | urlContainer.classList.remove("dragging"); 382 | reorderButtons.forEach((reorderButton) => { 383 | reorderButton.style.opacity = 1; 384 | }); 385 | }); 386 | reorderButtons[index].setAttribute("dragEndListener", "true"); 387 | } 388 | hideActionButtons(urlContainers); 389 | }); 390 | 391 | if (container.getAttribute("listener") !== "true") { 392 | container.addEventListener("dragover", (e) => { 393 | e.preventDefault(); 394 | const afterElement = getDragAfterElement(container, e.clientY); 395 | const dragging = document.querySelector(".dragging"); 396 | if (afterElement == null) { 397 | container.appendChild(dragging); 398 | } else { 399 | container.insertBefore(dragging, afterElement); 400 | } 401 | }); 402 | container.setAttribute("listener", "true"); 403 | } 404 | 405 | function getDragAfterElement(container, y) { 406 | const draggableElements = [ 407 | ...container.querySelectorAll(".target-url-container:not(.dragging)"), 408 | ]; 409 | 410 | return draggableElements.reduce( 411 | (closest, child) => { 412 | const box = child.getBoundingClientRect(); 413 | const offset = y - box.top - box.height / 2; 414 | if (offset < 0 && offset > closest.offset) { 415 | return { offset: offset, element: child }; 416 | } else { 417 | return closest; 418 | } 419 | }, 420 | { offset: Number.NEGATIVE_INFINITY }, 421 | ).element; 422 | } 423 | } 424 | 425 | function showErrorMessage(inputElement, containerElement, message) { 426 | const errorMessage = document.createElement("span"); 427 | 428 | errorMessage.className = "error-message"; 429 | errorMessage.textContent = message; 430 | 431 | inputElement.classList.add("error-input-border"); 432 | containerElement.appendChild(errorMessage); 433 | } 434 | 435 | function hideAllErrorMessages() { 436 | document.querySelectorAll(".error-input-border").forEach((input) => { 437 | input.classList.remove("error-input-border"); 438 | }); 439 | document.querySelectorAll(".error-message").forEach((errorMessage) => { 440 | errorMessage.parentNode.removeChild(errorMessage); 441 | }); 442 | } 443 | 444 | // Hide buttons if there is only one target URL. 445 | function hideActionButtons(urlContainers) { 446 | urlContainers = document.querySelectorAll(".target-url-container"); 447 | const deleteButtons = document.querySelectorAll(".delete-button"); 448 | // Used in desktop. 449 | const reorderButtons = document.querySelectorAll(".reorder-button"); 450 | // Used in mobile. 451 | const moveUpButtons = document.querySelectorAll(".move-up-button"); 452 | const moveDownButtons = document.querySelectorAll(".move-down-button"); 453 | 454 | if (urlContainers.length === 1) { 455 | moveUpButtons[0].style.display = "none"; 456 | moveDownButtons[0].style.display = "none"; 457 | reorderButtons[0].style.display = "none"; 458 | deleteButtons[0].style.display = "none"; 459 | } else { 460 | urlContainers.forEach((_, index) => { 461 | // Mobile? 462 | if (window.matchMedia("(hover: none)").matches) { 463 | moveUpButtons[index].style.display = "block"; 464 | moveDownButtons[index].style.display = "block"; 465 | reorderButtons[index].style.display = "none"; 466 | } else { 467 | moveUpButtons[index].style.display = "none"; 468 | moveDownButtons[index].style.display = "none"; 469 | reorderButtons[index].style.display = "block"; 470 | } 471 | }); 472 | deleteButtons[0].style.display = "block"; 473 | } 474 | } 475 | 476 | const addUrlButton = document.getElementById("add-url"); 477 | addUrlButton.addEventListener("click", () => { 478 | const urlContainers = document.getElementsByClassName("target-url-container"); 479 | const lastUrlContainer = urlContainers[urlContainers.length - 1]; 480 | // Clone and empty fields. 481 | const newUrlContainer = lastUrlContainer.cloneNode(true); 482 | newUrlContainer.querySelector(".url").value = ""; 483 | newUrlContainer 484 | .querySelector(".url-options-container") 485 | .classList.remove("expanded"); 486 | const baseUrlCheckbox = newUrlContainer.querySelector(".base-url-checkbox"); 487 | baseUrlCheckbox.checked = false; 488 | baseUrlCheckbox.removeAttribute("listener"); 489 | newUrlContainer.querySelectorAll(".bang-option-label").forEach((label) => { 490 | label.removeAttribute("listener"); 491 | }); 492 | newUrlContainer.querySelector(".base-url").style.display = "none"; 493 | newUrlContainer.querySelector(".base-url").value = ""; 494 | newUrlContainer.querySelector(".url-encode-query").checked = false; 495 | const reorderButton = newUrlContainer.querySelector(".reorder-button"); 496 | reorderButton.removeAttribute("dragStarListener"); 497 | reorderButton.removeAttribute("dragEndListener"); 498 | reorderButton.style.display = "block"; 499 | const moveUpButton = newUrlContainer.querySelector(".move-up-button"); 500 | moveUpButton.removeAttribute("listener"); 501 | const moveDownButton = newUrlContainer.querySelector(".move-down-button"); 502 | moveDownButton.removeAttribute("listener"); 503 | const expandButton = newUrlContainer.querySelector(".expand-button"); 504 | expandButton.removeAttribute("listener"); 505 | expandButton.classList.remove("expanded"); 506 | const deleteButton = newUrlContainer.querySelector(".delete-button"); 507 | deleteButton.removeAttribute("listener"); 508 | deleteButton.style.display = "block"; 509 | const errorMessages = newUrlContainer.querySelectorAll(".error-message"); 510 | errorMessages.forEach((error) => { 511 | error.parentNode.removeChild(error); 512 | newUrlContainer 513 | .querySelector(".error-input-border") 514 | .classList.remove("error-input-border"); 515 | }); 516 | lastUrlContainer.after(newUrlContainer); 517 | if (urlContainers.length >= LIMITS.MAX_NUMBER_URLS) { 518 | addUrlButton.disabled = true; 519 | addUrlButton.title = "Maximum number of URLs reached"; 520 | addUrlButton.classList.add("disabled-button"); 521 | } 522 | attachEventListeners(); 523 | }); 524 | 525 | window.addEventListener("resize", () => { 526 | const urlContainers = document.querySelectorAll(".target-url-container"); 527 | urlContainers.forEach((_, index) => { 528 | hideActionButtons(urlContainers); 529 | }); 530 | }); 531 | 532 | // If on mobile, the tooltips are opened when clicking on them, instead of 533 | // hovering. 534 | if (window.matchMedia("(hover: none)").matches) { 535 | const tooltips = document.querySelectorAll(".tooltip-text"); 536 | window.addEventListener("click", (e) => { 537 | const tooltip = 538 | e.target.closest(".tooltip")?.parentNode?.parentNode?.nextElementSibling; 539 | tooltips.forEach((t) => { 540 | if (t !== tooltip) { 541 | t.classList.remove("show"); 542 | } 543 | }); 544 | if (tooltip != null && tooltip.classList.contains("tooltip-text")) { 545 | tooltip.classList.toggle("show"); 546 | } 547 | }); 548 | } 549 | 550 | const saveButton = document.getElementById("save"); 551 | const urlParams = new URLSearchParams(window.location.search); 552 | const mode = urlParams.get("mode"); 553 | const last = Number(urlParams.get("last")); 554 | 555 | document.body.addEventListener("pageloaded", () => { 556 | const initialBang = getInputtedBang(); 557 | // Ask for confirmation upon unsaved changes. 558 | const beforeUnloadHandler = (e) => { 559 | if (JSON.stringify(getInputtedBang()) !== JSON.stringify(initialBang)) { 560 | e.preventDefault(); 561 | // Included for legacy support, e.g. Chrome/Edge < 119. 562 | e.returnValue = true; 563 | } 564 | }; 565 | window.addEventListener("beforeunload", beforeUnloadHandler); 566 | saveButton.addEventListener("click", () => { 567 | window.removeEventListener("beforeunload", beforeUnloadHandler); 568 | }); 569 | document.getElementById("cancel").addEventListener("click", () => { 570 | window.removeEventListener("beforeunload", beforeUnloadHandler); 571 | }); 572 | const keyHandler = async (e) => { 573 | // Save on Ctrl/Cmd + Enter. 574 | if ((e.ctrlKey || e.metaKey) && (e.keyCode === 13 || e.keyCode === 10)) { 575 | window.removeEventListener("beforeunload", beforeUnloadHandler); 576 | e.preventDefault(); 577 | const bang = await saveCustomBang(); 578 | if (bang == null) { 579 | // Add back the listener if the bang is not valid. 580 | window.addEventListener("beforeunload", beforeUnloadHandler); 581 | } 582 | } 583 | // Exit on Escape. 584 | else if (e.key === "Escape") { 585 | e.preventDefault(); 586 | window.location.assign("options.html"); 587 | } 588 | }; 589 | document.body.addEventListener("keydown", keyHandler); 590 | saveButton.addEventListener("click", async () => { 591 | const bang = await saveCustomBang(); 592 | if (bang == null) { 593 | // Add back the listener if the bang is not valid. 594 | window.addEventListener("beforeunload", beforeUnloadHandler); 595 | } 596 | }); 597 | }); 598 | 599 | let bangKey; 600 | if (mode === "edit") { 601 | const title = document.getElementById("title"); 602 | title.innerHTML = "Edit Custom Bang"; 603 | document.title = "Yang! – Edit Bang"; 604 | bangKey = getBangKey(urlParams.get("bang")); 605 | browser.storage.sync.get(bangKey).then( 606 | function onGot(item) { 607 | const bangInfo = item[bangKey]; 608 | const name = document.querySelector(`.${FORM_FIELDS.NAME}`); 609 | name.value = bangInfo.name; 610 | const bang = document.querySelector(`.${FORM_FIELDS.BANG}`); 611 | bang.value = bangInfo.bang; 612 | const firstTargetUrlContainer = document.getElementsByClassName( 613 | "target-url-container", 614 | )[0]; 615 | for (let i = 0; i < bangInfo.targets.length - 1; i++) { 616 | // Create as many URL containers as we need. 617 | firstTargetUrlContainer.after(firstTargetUrlContainer.cloneNode(true)); 618 | } 619 | const targetUrls = document.querySelectorAll(`.${FORM_FIELDS.URL}`); 620 | const targetBaseUrlCheckboxes = document.querySelectorAll( 621 | `.${FORM_FIELDS.BASE_URL}-checkbox`, 622 | ); 623 | const targetBaseUrls = document.querySelectorAll( 624 | `.${FORM_FIELDS.BASE_URL}`, 625 | ); 626 | const urlEncodeQueryCheckboxes = document.querySelectorAll( 627 | `.${FORM_FIELDS.URL_ENCODE_QUERY}`, 628 | ); 629 | bangInfo.targets.forEach((target, index) => { 630 | targetUrls[index].value = target.url; 631 | targetBaseUrlCheckboxes[index].checked = target.baseUrl != null; 632 | targetBaseUrls[index].style.display = 633 | target.baseUrl != null ? "block" : "none"; 634 | targetBaseUrls[index].value = 635 | target.baseUrl != null ? target.baseUrl : ""; 636 | urlEncodeQueryCheckboxes[index].checked = target.urlEncodeQuery; 637 | }); 638 | attachEventListeners(); 639 | saveButton.last = bangInfo.order; 640 | // Display page once everything is loaded. 641 | document.body.style.opacity = "1"; 642 | document.body.dispatchEvent(new Event("pageloaded")); 643 | }, 644 | function onError(error) { 645 | // TODO: Handle error. 646 | }, 647 | ); 648 | } else { 649 | attachEventListeners(); 650 | saveButton.last = last; 651 | document.querySelector(`.${FORM_FIELDS.NAME}`).focus(); // focus first field; 652 | // Display page once everything is loaded. 653 | document.body.style.opacity = "1"; 654 | document.body.dispatchEvent(new Event("pageloaded")); 655 | } 656 | 657 | saveButton.mode = mode; 658 | saveButton.bangKey = bangKey; 659 | -------------------------------------------------------------------------------- /options/export_import.js: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2023-2024 Diego Miguel Lozano 2 | * 3 | * This program is free software: you can redistribute it and//or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | * 16 | * For license information on the libraries used, see LICENSE. 17 | */ 18 | 19 | export { BACKUP_VERSION, BackupFields, exportSettings, importSettings }; 20 | import { PreferencePrefix, fetchSettings, getBangKey } from "../utils.js"; 21 | 22 | // Support for Chromium. 23 | if (typeof browser === "undefined") { 24 | globalThis.browser = chrome; 25 | } 26 | 27 | const BACKUP_VERSION = "1.2"; 28 | 29 | const BackupFields = Object.freeze({ 30 | BACKUP_VERSION: "backupVersion", 31 | BANGS: "bangs", 32 | SETTINGS: "settings", 33 | BANG_SYMBOL: "bangSymbol", 34 | SEARCH_ENGINES: "searchEngines", 35 | }); 36 | 37 | function exportSettings(settings) { 38 | const jsonString = JSON.stringify(settings, null, 2); 39 | const timestamp = new Date().toISOString().replace(/[-T:.Z]/g, ""); 40 | const filename = `yang-backup_${timestamp}.json`; 41 | 42 | const blob = new Blob([jsonString], { type: "application/json" }); 43 | const url = URL.createObjectURL(blob); 44 | 45 | const a = document.createElement("a"); 46 | a.href = url; 47 | a.download = filename; 48 | document.body.appendChild(a); 49 | a.click(); 50 | document.body.removeChild(a); 51 | 52 | URL.revokeObjectURL(url); 53 | } 54 | 55 | async function importSettings(file) { 56 | const errorMsg = "Error importing settings."; 57 | // Read existent bang symbol (if any). 58 | let bangSymbol = await browser.storage.sync 59 | .get(PreferencePrefix.BANG_SYMBOL) 60 | .then( 61 | function onGot(item) { 62 | return item[PreferencePrefix.BANG_SYMBOL]; 63 | }, 64 | function onError(error) { 65 | return "!"; // default 66 | }, 67 | ); 68 | const reader = new FileReader(); 69 | reader.onload = async (event) => { 70 | const preferences = new Map(); 71 | try { 72 | const readBackup = JSON.parse(event.target.result); 73 | let readBangs = {}; 74 | const backupKeys = Object.keys(readBackup); 75 | // Backup version < 1.0. 76 | let backupVersion = 1.0; 77 | if (!backupKeys.includes(BackupFields.BACKUP_VERSION)) { 78 | readBangs = readBackup; 79 | } else { 80 | readBangs = readBackup[BackupFields.BANGS]; 81 | backupVersion = parseFloat(readBackup[BackupFields.BACKUP_VERSION]); 82 | } 83 | // Backup version >= 1.1. 84 | if (backupKeys.includes(BackupFields.SETTINGS)) { 85 | bangSymbol = 86 | readBackup[BackupFields.SETTINGS][BackupFields.BANG_SYMBOL]; 87 | } 88 | let order = 0; 89 | const neededFields = 90 | backupVersion >= 1.2 91 | ? ["name", "bang", "targets"] 92 | : ["name", "url", "bang", "urlEncodeQuery"]; 93 | for (const [bangName, bangInfo] of Object.entries(readBangs)) { 94 | if (!neededFields.every((key) => Object.keys(bangInfo).includes(key))) { 95 | throw new SyntaxError("Malformed backup file."); 96 | } 97 | bangInfo.bang = bangInfo.bang.toLowerCase(); 98 | bangInfo.order = order; 99 | if (backupVersion < 1.2) { 100 | bangInfo.targets = [ 101 | { 102 | url: bangInfo.url, 103 | baseUrl: 104 | Object.hasOwn("openBaseUrl") && bangInfo.openBaseUrl 105 | ? new URL(bangInfo.url).origin 106 | : null, 107 | urlEncodeQuery: bangInfo.urlEncodeQuery, 108 | }, 109 | ]; 110 | delete bangInfo.url; 111 | delete bangInfo.openBaseUrl; 112 | delete bangInfo.urlEncodeQuery; 113 | } 114 | let key; 115 | // Backup version >= 1.0. 116 | if (bangName.startsWith(PreferencePrefix.BANG)) { 117 | key = bangInfo.bang; 118 | } else { 119 | key = getBangKey(bangInfo.bang); 120 | } 121 | preferences.set(key, bangInfo); 122 | order++; 123 | } 124 | preferences.set(PreferencePrefix.BANG_SYMBOL, bangSymbol); 125 | browser.storage.sync.set(Object.fromEntries(preferences)).then( 126 | async function onSet() { 127 | await fetchSettings(true); 128 | alert("Settings imported successfully!"); 129 | window.location.assign("options.html"); 130 | }, 131 | function onError(error) { 132 | console.error(errorMsg, error.message); 133 | if ( 134 | error.message.includes("QuotaExceededError") || 135 | error.message.includes("QUOTA_BYTES") 136 | ) { 137 | alert( 138 | `${errorMsg} The backup file is too big and exceeds the ` + 139 | "browser's storage limits. Please, make it smaller and try again.", 140 | ); 141 | } else { 142 | alert(`${errorMsg} ${error.message}`); 143 | } 144 | }, 145 | ); 146 | } catch (error) { 147 | console.error(errorMsg, error); 148 | alert(`${errorMsg} Please, make sure the file is a valid Yang backup.`); 149 | } 150 | }; 151 | reader.readAsText(file); 152 | } 153 | -------------------------------------------------------------------------------- /options/fonts/Inter-4.0/InterVariable.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/options/fonts/Inter-4.0/InterVariable.woff2 -------------------------------------------------------------------------------- /options/fonts/Inter-4.0/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | This license is copied below, and is also available with a FAQ at: 5 | http://scripts.sil.org/OFL 6 | 7 | ----------------------------------------------------------- 8 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 9 | ----------------------------------------------------------- 10 | 11 | PREAMBLE 12 | The goals of the Open Font License (OFL) are to stimulate worldwide 13 | development of collaborative font projects, to support the font creation 14 | efforts of academic and linguistic communities, and to provide a free and 15 | open framework in which fonts may be shared and improved in partnership 16 | with others. 17 | 18 | The OFL allows the licensed fonts to be used, studied, modified and 19 | redistributed freely as long as they are not sold by themselves. The 20 | fonts, including any derivative works, can be bundled, embedded, 21 | redistributed and/or sold with any software provided that any reserved 22 | names are not used by derivative works. The fonts and derivatives, 23 | however, cannot be released under any other type of license. The 24 | requirement for fonts to remain under this license does not apply 25 | to any document created using the fonts or their derivatives. 26 | 27 | DEFINITIONS 28 | "Font Software" refers to the set of files released by the Copyright 29 | Holder(s) under this license and clearly marked as such. This may 30 | include source files, build scripts and documentation. 31 | 32 | "Reserved Font Name" refers to any names specified as such after the 33 | copyright statement(s). 34 | 35 | "Original Version" refers to the collection of Font Software components as 36 | distributed by the Copyright Holder(s). 37 | 38 | "Modified Version" refers to any derivative made by adding to, deleting, 39 | or substituting -- in part or in whole -- any of the components of the 40 | Original Version, by changing formats or by porting the Font Software to a 41 | new environment. 42 | 43 | "Author" refers to any designer, engineer, programmer, technical 44 | writer or other person who contributed to the Font Software. 45 | 46 | PERMISSION AND CONDITIONS 47 | Permission is hereby granted, free of charge, to any person obtaining 48 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 49 | redistribute, and sell modified and unmodified copies of the Font 50 | Software, subject to the following conditions: 51 | 52 | 1) Neither the Font Software nor any of its individual components, 53 | in Original or Modified Versions, may be sold by itself. 54 | 55 | 2) Original or Modified Versions of the Font Software may be bundled, 56 | redistributed and/or sold with any software, provided that each copy 57 | contains the above copyright notice and this license. These can be 58 | included either as stand-alone text files, human-readable headers or 59 | in the appropriate machine-readable metadata fields within text or 60 | binary files as long as those fields can be easily viewed by the user. 61 | 62 | 3) No Modified Version of the Font Software may use the Reserved Font 63 | Name(s) unless explicit written permission is granted by the corresponding 64 | Copyright Holder. This restriction only applies to the primary font name as 65 | presented to the users. 66 | 67 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 68 | Software shall not be used to promote, endorse or advertise any 69 | Modified Version, except to acknowledge the contribution(s) of the 70 | Copyright Holder(s) and the Author(s) or with their explicit written 71 | permission. 72 | 73 | 5) The Font Software, modified or unmodified, in part or in whole, 74 | must be distributed entirely under this license, and must not be 75 | distributed under any other license. The requirement for fonts to 76 | remain under this license does not apply to any document created 77 | using the Font Software. 78 | 79 | TERMINATION 80 | This license becomes null and void if any of the above conditions are 81 | not met. 82 | 83 | DISCLAIMER 84 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 85 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 86 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 87 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 88 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 89 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 90 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 91 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 92 | OTHER DEALINGS IN THE FONT SOFTWARE. 93 | -------------------------------------------------------------------------------- /options/options.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: InterVariable; 3 | font-style: normal; 4 | font-weight: 100 900; 5 | font-display: swap; 6 | src: url("fonts/Inter-4.0/InterVariable.woff2") format("woff2"); 7 | } 8 | 9 | body { 10 | opacity: 0; /* Set to 1 when the contents are loaded. */ 11 | font-family: InterVariable, sans-serif; 12 | font-size: 1.1rem; 13 | margin: 0; 14 | padding: 0; 15 | background-color: #f5f5f5; 16 | } 17 | 18 | .container { 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: space-between; 23 | max-width: 60%; 24 | min-height: 80vh; 25 | margin: 50px auto; 26 | text-align: center; 27 | background-color: #fff; 28 | box-shadow: 0 0 10px #ebebeb; 29 | border-radius: 8px; 30 | padding: 2rem; 31 | overflow-x: hidden; 32 | } 33 | 34 | a { 35 | color: #0000ff; 36 | } 37 | 38 | h1 { 39 | color: #333; 40 | margin-top: 5px; 41 | margin-bottom: 40px; 42 | font-weight: normal; 43 | } 44 | 45 | .button-container { 46 | display: flex; 47 | justify-content: space-between; 48 | align-items: center; 49 | margin: 10px 0; 50 | } 51 | 52 | .button-container a { 53 | text-decoration: none; 54 | } 55 | 56 | .button-container button { 57 | display: flex; 58 | align-items: center; 59 | font-size: medium; 60 | } 61 | 62 | .button-container button svg { 63 | margin-right: 5px; 64 | } 65 | 66 | #add-bang { 67 | background: #e15e49; 68 | color: #fff; 69 | padding: 15px 20px; 70 | border: none; 71 | border-radius: 8px; 72 | cursor: pointer; 73 | transition: 74 | border-radius 0.5s ease, 75 | background 0.3s ease; 76 | } 77 | 78 | #add-bang:hover { 79 | background: #a84636; 80 | border-radius: 12px; 81 | } 82 | 83 | #settings { 84 | color: #454545; 85 | fill: #454545; 86 | border: none; 87 | background: none; 88 | } 89 | 90 | #settings:hover { 91 | color: #2a2a2a; 92 | fill: #2a2a2a; 93 | text-decoration: underline; 94 | cursor: pointer; 95 | } 96 | 97 | #yang-logo { 98 | width: 15%; 99 | margin-top: 20px; 100 | } 101 | 102 | .table-container { 103 | margin: 25px auto; 104 | min-width: 50%; 105 | width: 80%; 106 | } 107 | 108 | #bangs-table { 109 | width: 100%; 110 | table-layout: fixed; 111 | border-collapse: collapse; 112 | border-radius: 8px 8px 0 0; 113 | font-size: 0.95rem; 114 | font-family: sans-serif; 115 | text-align: left; 116 | box-shadow: 0 0 20px #ebebeb; 117 | overflow: hidden; 118 | } 119 | 120 | #bangs-table thead tr { 121 | background: linear-gradient(to right, #7814ae, #d53); 122 | color: #fff; 123 | } 124 | 125 | #bangs-table th, 126 | #bangs-table td { 127 | padding: 12px 15px; 128 | white-space: nowrap; 129 | } 130 | 131 | #bangs-table th:first-child, 132 | #bangs-table td:first-child { 133 | width: 25vw; 134 | overflow: hidden; 135 | text-overflow: ellipsis; 136 | } 137 | 138 | #bangs-table th:last-child, 139 | #bangs-table td:last-child { 140 | text-align: end; 141 | padding-right: 10px; 142 | padding-left: 0; 143 | overflow: visible; 144 | } 145 | 146 | #bangs-table tbody tr { 147 | border-bottom: 1px solid #ddd; 148 | } 149 | 150 | #bangs-table tbody tr:nth-of-type(even) { 151 | background-color: #f3f3f3; 152 | } 153 | 154 | #bangs-table tbody tr:last-of-type { 155 | border-bottom: 2px solid #d53; 156 | } 157 | 158 | #bangs-table tbody tr:hover { 159 | color: #361149; 160 | background-color: #f5f0f8; 161 | } 162 | 163 | #bangs-table .edit-button, 164 | #bangs-table .delete-button { 165 | border: none; 166 | background: none; 167 | padding: 0 8px; 168 | margin: 2px; 169 | cursor: pointer; 170 | color: #494949; 171 | } 172 | 173 | #bangs-table .edit-button:hover { 174 | color: #7814ae; 175 | } 176 | 177 | #bangs-table .delete-button:hover { 178 | color: #c01010; 179 | } 180 | 181 | .bang { 182 | overflow: hidden; 183 | text-overflow: ellipsis; 184 | max-width: 80%; 185 | font-family: monospace; 186 | font-size: 0.75rem; 187 | font-weight: bold; 188 | color: #7914ad; 189 | background-color: #f4f4f4; 190 | padding: 0.2rem; 191 | border: 1px solid #ccc; 192 | border-radius: 4px; 193 | } 194 | 195 | #bangs-table td .bang { 196 | display: inline-block; 197 | cursor: pointer; 198 | } 199 | 200 | #no-bangs { 201 | color: #585858; 202 | font-size: 0.95rem; 203 | margin: 15px 0; 204 | } 205 | 206 | .footer { 207 | display: flex; 208 | width: 100%; 209 | margin-top: 20px; 210 | justify-content: space-between; 211 | font-size: 0.85rem; 212 | } 213 | 214 | #version { 215 | font-size: 0.8rem; 216 | } 217 | 218 | #version a:link, 219 | #version a:visited { 220 | color: #4e4e4e; 221 | } 222 | 223 | .toast-container { 224 | position: fixed; 225 | width: 50%; 226 | bottom: 20px; 227 | left: 50%; 228 | transform: translateX(-50%); 229 | background-color: #1a1a1a; 230 | font-size: 0.95rem; 231 | color: #fff; 232 | padding: 15px; 233 | border-radius: 5px; 234 | display: flex; 235 | justify-content: space-between; 236 | align-items: center; 237 | } 238 | 239 | .toast-container button { 240 | background-color: transparent; 241 | color: yellow; 242 | border: none; 243 | text-decoration: underline; 244 | font-size: 1rem; 245 | cursor: pointer; 246 | } 247 | 248 | @media screen and (width < 1000px) { 249 | h1 { 250 | margin-bottom: 35px; 251 | } 252 | 253 | .container { 254 | max-width: 100%; 255 | height: 100dvh; 256 | display: flex; 257 | flex-direction: column; 258 | margin: 0; 259 | padding: 0; 260 | } 261 | 262 | .footer { 263 | width: 95%; 264 | margin-bottom: 30px; 265 | } 266 | 267 | .toast-container { 268 | width: 90%; 269 | } 270 | 271 | #yang-logo { 272 | width: 25%; 273 | margin-top: 30px; 274 | } 275 | 276 | .table-container { 277 | margin: 10px auto; 278 | width: 95%; 279 | } 280 | 281 | .button-container { 282 | justify-content: space-between; 283 | margin-bottom: 20px; 284 | } 285 | 286 | #bangs-table th:first-child, 287 | #bangs-table td:first-child { 288 | width: 50vw; 289 | } 290 | 291 | #bangs-table th:nth-child(2), 292 | #bangs-table td:nth-child(2) { 293 | padding-right: 0; 294 | padding-left: 0; 295 | } 296 | 297 | #bangs-table th:last-child, 298 | #bangs-table td:last-child { 299 | padding-right: 0; 300 | padding-left: 0; 301 | float: right; 302 | } 303 | } 304 | -------------------------------------------------------------------------------- /options/options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Yang! – Custom Bangs 9 | 10 | 11 | 12 |
13 |
14 | 15 |

Custom Bangs

16 |
17 |
18 | 19 | 39 | 40 | 58 |
59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
NameBang
69 |
Click on + Add Bang to get started.
70 |
71 |
72 | 83 |
84 | 85 | 86 | -------------------------------------------------------------------------------- /options/options.js: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2023-2024 Diego Miguel Lozano 2 | * 3 | * This program is free software: you can redistribute it and//or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | * 16 | * For license information on the libraries used, see LICENSE. 17 | */ 18 | 19 | import { PreferencePrefix, fetchSettings, getBangKey } from "../utils.js"; 20 | 21 | // Support for Chromium. 22 | if (typeof browser === "undefined") { 23 | globalThis.browser = chrome; 24 | } 25 | 26 | function onGot(allBangs) { 27 | // Get only the bang values, sorted by order. 28 | const sortedBangs = Object.entries(allBangs) 29 | .filter((entry) => entry[0].startsWith(PreferencePrefix.BANG)) 30 | .sort((a, b) => a[1].order - b[1].order) 31 | .map((entry) => entry[0]); 32 | if (sortedBangs.length > 0) { 33 | document.getElementById("no-bangs").style.display = "none"; 34 | for (const b of sortedBangs) { 35 | const tableBody = document.querySelector("#bangs-table tbody"); 36 | const row = tableBody.insertRow(); 37 | const nameCell = row.insertCell(0); 38 | const bangCell = row.insertCell(1); 39 | const actionsCell = row.insertCell(2); 40 | 41 | const name = document.createTextNode(allBangs[b].name); 42 | nameCell.appendChild(name); 43 | 44 | const bang = document.createElement("code"); 45 | bang.classList.add("bang"); 46 | bang.textContent = allBangs[b].bang; 47 | bang.addEventListener("click", () => copyBang(bang)); 48 | bangCell.appendChild(bang); 49 | 50 | const editButton = document.createElement("button"); 51 | editButton.className = "edit-button"; 52 | editButton.title = "Edit"; 53 | editButton.innerHTML = ` 54 | 55 | 56 | `; 57 | editButton.addEventListener("click", editBang, false); 58 | 59 | const deleteButton = document.createElement("button"); 60 | deleteButton.className = "delete-button"; 61 | deleteButton.title = "Delete"; 62 | deleteButton.innerHTML = ` 63 | 64 | 65 | `; 66 | deleteButton.addEventListener("click", deleteBang, false); 67 | 68 | actionsCell.appendChild(editButton); 69 | actionsCell.appendChild(deleteButton); 70 | } 71 | const last = allBangs[sortedBangs.at(-1)].order; // order of the most recent bang 72 | const addBangButton = document.getElementById("add-bang"); 73 | addBangButton.last = last; 74 | } 75 | } 76 | 77 | // TODO: Handle errors. 78 | function onError(error) { 79 | console.error(`Error: ${error}`); 80 | } 81 | 82 | function addBang(e) { 83 | const last = e.currentTarget.last == null ? -1 : e.currentTarget.last; 84 | window.location.assign(`add_edit_bang.html?mode=add&last=${last}`); 85 | } 86 | 87 | function editBang(e) { 88 | const row = e.currentTarget.parentNode.parentNode; 89 | const bang = row.cells[1].textContent; 90 | const addBangButton = document.getElementById("add-bang"); 91 | window.location.assign( 92 | `add_edit_bang.html?mode=edit&bang=${bang}&last=${addBangButton.last}`, 93 | ); 94 | } 95 | 96 | function deleteBang(e) { 97 | const row = e.currentTarget.parentNode.parentNode; 98 | const bangKey = getBangKey(row.cells[1].textContent); 99 | // Retrieve bang to be able to undo deletion. 100 | browser.storage.sync.get(bangKey).then( 101 | function onGot(item) { 102 | if (Object.hasOwn(item, bangKey)) { 103 | const bang = item[bangKey]; 104 | browser.storage.sync.remove(bangKey).then( 105 | function onRemoved() { 106 | browser.storage.session.remove(bangKey).then( 107 | async function onRemoved() { 108 | const rowIndex = row.rowIndex; 109 | row.remove(); 110 | // Remove sets rowIndex to -1 so we restore it. 111 | row.index = rowIndex; 112 | const table = document.getElementById("bangs-table"); 113 | if (table.rows.length === 1) { 114 | // Empty table. 115 | document 116 | .getElementById("no-bangs") 117 | .style.removeProperty("display"); 118 | } 119 | const toastMessage = document.createElement("div"); 120 | toastMessage.appendChild( 121 | document.createTextNode("Bang\xA0\xA0"), 122 | ); 123 | const bangName = document.createElement("code"); 124 | bangName.classList.add("bang"); 125 | bangName.textContent = bang.bang; 126 | toastMessage.appendChild(bangName); 127 | toastMessage.appendChild( 128 | document.createTextNode("\xA0\xA0deleted."), 129 | ); 130 | displayToast(bangKey, toastMessage, "Undo", undoDeletion, [ 131 | row, 132 | bang, 133 | ]); 134 | await fetchSettings(true); 135 | }, 136 | function onError() { 137 | // TODO: Handle errors. 138 | }, 139 | ); 140 | }, 141 | function onError() { 142 | // TODO: Handle errors. 143 | }, 144 | ); 145 | } 146 | }, 147 | function onError(error) { 148 | // TODO: Handle error. 149 | }, 150 | ); 151 | } 152 | 153 | function undoDeletion([row, bang, timeoutId]) { 154 | const bangKey = getBangKey(bang.bang); 155 | browser.storage.sync.set({ [bangKey]: bang }).then( 156 | function onSet() { 157 | browser.storage.session 158 | .set({ 159 | [bangKey]: bang.targets, 160 | }) 161 | .then( 162 | function onSet() { 163 | const table = document.getElementById("bangs-table"); 164 | if (table.rows.length === 1) { 165 | document.getElementById("no-bangs").style.display = "none"; 166 | } 167 | const tableBody = table.getElementsByTagName("tbody")[0]; 168 | tableBody.insertBefore(row, tableBody.childNodes[row.index - 1]); 169 | hideToast(); 170 | clearTimeout(timeoutId); 171 | }, 172 | function onError() {}, 173 | ); 174 | }, 175 | function onError(error) {}, 176 | ); 177 | } 178 | 179 | function displayToast( 180 | toastId, 181 | messageElement, 182 | actionText = null, 183 | actionCallback = null, 184 | argsCallback = null, 185 | hideAfter = 5000, 186 | ) { 187 | hideToast(); 188 | toastId = `toast-${toastId}`; 189 | const toastContainer = document.createElement("div"); 190 | toastContainer.id = toastId; 191 | toastContainer.classList.add("toast-container"); 192 | messageElement.classList.add("toast-message"); 193 | toastContainer.appendChild(messageElement); 194 | // Remove toast after a delay. 195 | const timeoutId = setTimeout(() => hideToast(toastId), hideAfter); 196 | if (actionText != null && actionCallback != null && argsCallback != null) { 197 | const buttonId = `undo-button-${toastId}`; 198 | const undoButton = document.createElement("button"); 199 | undoButton.id = buttonId; 200 | undoButton.textContent = actionText; 201 | undoButton.addEventListener("click", () => 202 | actionCallback([...argsCallback, timeoutId]), 203 | ); 204 | toastContainer.appendChild(undoButton); 205 | } 206 | document.body.appendChild(toastContainer); 207 | } 208 | 209 | function hideToast(toastId) { 210 | // If not toast id is passed, we hide all toasts. 211 | const toasts = 212 | toastId == null 213 | ? document.querySelectorAll('[id^="toast-"]') 214 | : [document.getElementById(toastId)]; 215 | for (const toast of toasts) { 216 | if (toast != null) { 217 | toast.remove(); 218 | } 219 | } 220 | } 221 | 222 | function copyBang(element) { 223 | const bang = element.innerText; 224 | const toastMessage = document.createElement("div"); 225 | toastMessage.appendChild( 226 | document.createTextNode("Bang copied to clipboard."), 227 | ); 228 | // Use the Clipboard API to copy the text. 229 | navigator.clipboard 230 | .writeText(bang) 231 | .then(displayToast(`copy-${bang}`, toastMessage, null, null, null, 2000)) 232 | .catch(function (err) { 233 | console.error("Could not copy text: ", err); 234 | }); 235 | } 236 | 237 | (async () => { 238 | await browser.storage.sync.get().then(onGot, onError); 239 | document.body.style.opacity = "1"; 240 | })(); 241 | 242 | const addBangButton = document.getElementById("add-bang"); 243 | addBangButton.addEventListener("click", addBang, false); 244 | -------------------------------------------------------------------------------- /options/settings.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: InterVariable; 3 | font-style: normal; 4 | font-weight: 100 900; 5 | font-display: swap; 6 | src: url("fonts/Inter-4.0/InterVariable.woff2") format("woff2"); 7 | } 8 | 9 | body { 10 | opacity: 0; /* Set to 1 when the contents are loaded. */ 11 | font-family: InterVariable, sans-serif; 12 | font-size: 1rem; 13 | margin: 0; 14 | padding: 0; 15 | background-color: #f5f5f5; 16 | } 17 | 18 | .container { 19 | max-width: 40%; 20 | margin: 50px auto; 21 | text-align: center; 22 | background-color: #fff; 23 | box-shadow: 0 0 10px rgba(0 0 0 0.1); 24 | border-radius: 8px; 25 | padding: 2rem; 26 | } 27 | 28 | a { 29 | color: #0000ff; 30 | } 31 | 32 | h1 { 33 | color: #333; 34 | margin-top: 30px; 35 | margin-bottom: 40px; 36 | font-weight: normal; 37 | } 38 | 39 | h2 { 40 | color: #e15e49; 41 | font-weight: normal; 42 | font-size: 1.5rem; 43 | text-align: start; 44 | } 45 | 46 | label { 47 | margin-bottom: 5px; 48 | text-align: start; 49 | width: 100%; 50 | font-size: 1rem; 51 | } 52 | 53 | input { 54 | width: 15%; 55 | padding: 8px; 56 | box-sizing: border-box; 57 | text-align: center; 58 | border: none; 59 | border: solid 1.5px #aaa; 60 | border-radius: 6px; 61 | } 62 | 63 | input:focus { 64 | outline: 1px solid #0000ff; 65 | } 66 | 67 | input::placeholder { 68 | opacity: 0.7; 69 | color: #5c5c5c; 70 | } 71 | 72 | .setting-group:nth-child(n + 2) { 73 | margin-top: 50px; 74 | } 75 | 76 | .button-container { 77 | display: flex; 78 | justify-content: center; 79 | margin-top: 55px; 80 | } 81 | 82 | button { 83 | display: flex; 84 | align-items: center; 85 | justify-content: center; 86 | background: #e15e49; 87 | color: #fff; 88 | padding: 15px 25px; 89 | border: none; 90 | border-radius: 8px; 91 | cursor: pointer; 92 | font-size: 1rem; 93 | transition: 94 | border-radius 0.5s ease, 95 | background 0.3s ease; 96 | } 97 | 98 | button:hover { 99 | background: #a84636; 100 | border-radius: 12px; 101 | } 102 | 103 | button svg { 104 | margin-right: 8px; 105 | } 106 | 107 | #save { 108 | margin: 55px auto 15px; 109 | } 110 | 111 | .setting-button { 112 | padding: 5px 10px; 113 | margin-left: 15px; 114 | font-size: 0.9rem; 115 | background: none; 116 | border: solid 2px #e15e49; 117 | color: #e15e49; 118 | white-space: nowrap; 119 | } 120 | 121 | .setting-button svg { 122 | width: 1.1rem; 123 | } 124 | 125 | .setting-button:hover { 126 | background: #e15e49; 127 | color: white; 128 | border-radius: 8px; 129 | } 130 | 131 | .form { 132 | width: 75%; 133 | margin: 0 auto; 134 | box-sizing: border-box; 135 | } 136 | 137 | .back-container { 138 | font-size: 0.9rem; 139 | text-align: left; 140 | } 141 | 142 | .setting-container { 143 | display: flex; 144 | justify-content: space-between; 145 | align-items: center; 146 | margin-bottom: 20px; 147 | } 148 | 149 | .setting-label { 150 | display: flex; 151 | flex-direction: column; 152 | text-align: start; 153 | } 154 | 155 | .setting-label p { 156 | margin: 7px 0 0; 157 | color: #454545; 158 | } 159 | 160 | .setting-detail, 161 | .storage-label { 162 | font-size: 0.82rem; 163 | } 164 | 165 | .storage-container { 166 | display: flex; 167 | flex-direction: column; 168 | width: 100%; 169 | text-align: end; 170 | margin-bottom: 20px; 171 | } 172 | 173 | .storage-label { 174 | margin-bottom: 5px; 175 | } 176 | 177 | .storage-bar { 178 | width: 100%; 179 | height: 0.5rem; 180 | border-radius: 5px; 181 | background: #e3e3e3; 182 | } 183 | 184 | .storage-bar > div { 185 | width: 5%; 186 | height: 0.5rem; 187 | border-radius: 5px; 188 | background: #e15e49; 189 | } 190 | 191 | @media screen and (width < 1000px) { 192 | html { 193 | background-color: white; 194 | } 195 | 196 | .container { 197 | max-width: 100%; 198 | margin: 0; 199 | padding: 0 0 50px; 200 | box-shadow: none; 201 | } 202 | 203 | .form { 204 | width: 90%; 205 | } 206 | 207 | .back-container { 208 | padding: 20px; 209 | } 210 | 211 | .button-label { 212 | display: none; 213 | } 214 | 215 | .setting-button svg { 216 | margin-right: 0; 217 | width: 1.1rem; 218 | } 219 | } 220 | 221 | /* No storage quota on mobile. */ 222 | @media (hover: none) { 223 | #storage, 224 | .storage-container { 225 | display: none; 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /options/settings.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Yang! – Settings 9 | 10 | 11 | 12 |
13 | 16 |

Settings

17 |
18 |
19 |

Bangs

20 |
21 |
22 | 23 |
24 | 32 |
33 |

Backups

34 |
35 |
36 | 37 |
38 | 57 |
58 |
59 |
60 | 61 | 62 | Existent bangs and settings will be updated 63 | 64 |
65 | 83 |
84 | 90 |

Storage

91 |
92 | 93 |
94 |
95 |
96 |
97 |
98 | 99 |
100 |
101 |
102 |
103 | 127 |
128 |
129 |
130 | 131 | 132 | -------------------------------------------------------------------------------- /options/settings.js: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2023-2024 Diego Miguel Lozano 2 | * 3 | * This program is free software: you can redistribute it and//or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | * 16 | * For license information on the libraries used, see LICENSE. 17 | */ 18 | 19 | import { PreferencePrefix } from "../utils.js"; 20 | import { 21 | BACKUP_VERSION, 22 | BackupFields, 23 | exportSettings, 24 | importSettings, 25 | } from "./export_import.js"; 26 | 27 | const LIMITS = Object.freeze({ 28 | // Maximum total amount (in bytes) of data that can be stored in sync storage. 29 | // Firefox: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync#storage_quotas_for_sync_data 30 | // Chrome: https://developer.chrome.com/docs/extensions/reference/api/storage#property-sync-sync-QUOTA_BYTES 31 | SYNC_MAX_QUOTA_BYTES: 102400, 32 | // Maximum number of items that can be stored in sync storage. 33 | // Firefox: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync#storage_quotas_for_sync_data 34 | // Chrome: https://developer.chrome.com/docs/extensions/reference/api/storage#property-sync-sync-MAX_ITEMS 35 | SYNC_MAX_ITEMS: 512, 36 | }); 37 | 38 | // Support for Chromium. 39 | if (typeof browser === "undefined") { 40 | globalThis.browser = chrome; 41 | } 42 | 43 | let storedSettings = new Map(); 44 | storedSettings.set(PreferencePrefix.BANG_SYMBOL, { 45 | element: document.getElementById("bang-symbol"), 46 | default: "!", 47 | }); 48 | 49 | function success() { 50 | window.location.assign("options.html"); 51 | } 52 | 53 | function saveSettings() { 54 | const settings = {}; 55 | for (const [settingName, settingValue] of storedSettings) { 56 | settings[settingName] = settingValue.element.value || settingValue.default; 57 | } 58 | browser.storage.sync.set(settings).then( 59 | function onSet() { 60 | browser.storage.session.set(settings).then(success, onError); 61 | }, 62 | function onError(error) {}, 63 | ); 64 | } 65 | 66 | function onError(error) {} 67 | 68 | browser.storage.sync.get(Array.from(storedSettings.keys())).then( 69 | function onGot(items) { 70 | for (const [settingName, settingValue] of storedSettings) { 71 | if (Object.hasOwn(items, settingName) && items[settingName] != null) { 72 | settingValue.element.setAttribute("value", items[settingName]); 73 | } else { 74 | settingValue.element.setAttribute("value", settingValue.default); 75 | } 76 | } 77 | }, 78 | function onError(error) { 79 | // TODO: Handle error. 80 | }, 81 | ); 82 | // Storage quotas only on Desktop, since on Mobile they don't work reliably. 83 | if (!window.matchMedia("(hover: none)").matches) { 84 | (async () => { 85 | const bytesInUse = await browser.storage.sync.getBytesInUse(); 86 | const storagePercentage = (bytesInUse / LIMITS.SYNC_MAX_QUOTA_BYTES) * 100; 87 | const storagePercentageLabel = 88 | storagePercentage > 0 && storagePercentage < 1 89 | ? "< 1" 90 | : Math.round(storagePercentage); 91 | document.getElementById("storage-quota-usage").textContent = 92 | `${(bytesInUse / 1000).toFixed(2)} KB of ` + 93 | `${(LIMITS.SYNC_MAX_QUOTA_BYTES / 1000).toFixed(2)} KB used ` + 94 | `(${storagePercentageLabel}%)`; 95 | document.getElementById("storage-quota-bar").style.width = 96 | `${storagePercentage}%`; 97 | browser.storage.sync.get().then( 98 | function onGot(storedData) { 99 | const bangCount = Object.keys(storedData).filter((k) => { 100 | return k.startsWith(PreferencePrefix.BANG); 101 | }).length; 102 | const otherSettingsCount = Object.keys(storedData).length - bangCount; 103 | const totalBangsLimit = LIMITS.SYNC_MAX_ITEMS - otherSettingsCount; 104 | const bangPercentage = (bangCount / totalBangsLimit) * 100; 105 | const bangPercentageLabel = 106 | bangPercentage !== 0 && bangPercentage < 1 107 | ? "< 1" 108 | : Math.round(bangPercentage); 109 | document.getElementById("storage-item-usage").textContent = 110 | `${bangCount} bangs of ${totalBangsLimit} bangs used ` + 111 | `(${bangPercentageLabel}%)`; 112 | document.getElementById("storage-item-bar").style.width = 113 | `${bangPercentage}%`; 114 | }, 115 | function onError() { 116 | // TODO: Handle errors. 117 | }, 118 | ); 119 | })(); 120 | } 121 | document.body.style.opacity = "1"; 122 | const saveButton = document.getElementById("save"); 123 | saveButton.addEventListener("click", saveSettings, false); 124 | 125 | const keyHandler = (e) => { 126 | // Save on Ctrl/Cmd + Enter. 127 | if ((e.ctrlKey || e.metaKey) && (e.keyCode === 13 || e.keyCode === 10)) { 128 | saveSettings(); 129 | } else if (e.keyCode === 13 || e.keyCode === 10) { 130 | e.preventDefault(); 131 | } 132 | // Exit on Escape. 133 | else if (e.key === "Escape") { 134 | e.preventDefault(); 135 | window.location.assign("options.html"); 136 | } 137 | }; 138 | document.body.addEventListener("keydown", keyHandler); 139 | 140 | const exportButton = document.getElementById("export-button"); 141 | exportButton.addEventListener("click", async () => { 142 | const settings = await browser.storage.sync.get().then( 143 | function onGot(storedData) { 144 | const loadedSettings = {}; 145 | loadedSettings[BackupFields.BACKUP_VERSION] = BACKUP_VERSION; 146 | loadedSettings[BackupFields.SETTINGS] = {}; 147 | loadedSettings[BackupFields.SETTINGS][BackupFields.BANG_SYMBOL] = 148 | storedData[PreferencePrefix.BANG_SYMBOL] || "!"; 149 | loadedSettings[BackupFields.SETTINGS][BackupFields.SEARCH_ENGINES] = {}; 150 | const sortedBangs = Object.entries(storedData) 151 | .filter((entry) => entry[0].startsWith(PreferencePrefix.BANG)) 152 | .sort((a, b) => a[1].order - b[1].order) 153 | .map((entry) => { 154 | delete entry[1].order; 155 | return entry[1]; 156 | }); 157 | loadedSettings[BackupFields.BANGS] = sortedBangs; 158 | return loadedSettings; 159 | }, 160 | function onError(error) { 161 | // TODO: Handle errors. 162 | }, 163 | ); 164 | exportSettings(settings); 165 | }); 166 | 167 | const importButton = document.getElementById("import-button"); 168 | const fileInput = document.getElementById("fileInput"); 169 | importButton.addEventListener("click", () => { 170 | fileInput.click(); 171 | }); 172 | fileInput.addEventListener("change", (event) => { 173 | const file = event.target.files[0]; 174 | if (file) { 175 | importSettings(file); 176 | } 177 | }); 178 | -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2023-2024 Diego Miguel Lozano 2 | * 3 | * This program is free software: you can redistribute it and//or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | * 16 | * For license information on the libraries used, see LICENSE. 17 | */ 18 | 19 | export { PreferencePrefix, Defaults, fetchSettings, getBangKey, getBangName }; 20 | 21 | // Prefixes added to the storage keys to differentiate between different types 22 | // of settings. 23 | const PreferencePrefix = Object.freeze({ 24 | BANG: "#bang#", 25 | BANG_SYMBOL: "#symbol#", 26 | SEARCH_ENGINE: "#engine#", 27 | }); 28 | 29 | const Defaults = Object.freeze({ 30 | BANG_SYMBOL: "!", 31 | }); 32 | 33 | async function fetchSettings(update = false) { 34 | if (!update) { 35 | // Check if any settings are loaded. We look for, e.g., the bang symbol key. 36 | // If no settings are loaded, we fetch them and retry. A more elegant 37 | // solution would be `StorageArea.getBytesInUse()`, but it's not supported 38 | // for `storage.session`. 39 | const updated = await browser.storage.session 40 | .get(PreferencePrefix.BANG_SYMBOL) 41 | .then( 42 | function onGot(item) { 43 | // Any matches? 44 | return Object.hasOwn(item, PreferencePrefix.BANG_SYMBOL); 45 | }, 46 | function onError(error) { 47 | // TODO: Handle error. 48 | }, 49 | ); 50 | if (updated) { 51 | return null; 52 | } 53 | } 54 | const settings = {}; 55 | let defaultBangs = []; 56 | const bangApis = [ 57 | "https://raw.githubusercontent.com/kagisearch/bangs/main/data/bangs.json", 58 | "https://duckduckgo.com/bang.js", 59 | ]; 60 | for (const api of bangApis) { 61 | try { 62 | const res = await fetch(new Request(api)); 63 | defaultBangs = await res.json(); 64 | break; 65 | } catch (error) { 66 | // retry 67 | } 68 | } 69 | for (const bang of defaultBangs) { 70 | // Kagi does not specify the origin for its own bangs, so we add it. 71 | if (bang.d === "kagi.com" && bang.u.startsWith("/")) { 72 | bang.u = `https://kagi.com${bang.u}`; 73 | } 74 | const bangTargets = [ 75 | { 76 | url: bang.u, 77 | baseUrl: 78 | Object.hasOwn(bang, "fmt") && !bang.fmt.includes("open_base_path") 79 | ? null 80 | : new URL(bang.u).origin, 81 | urlEncodeQuery: Object.hasOwn(bang, "fmt") 82 | ? bang.fmt.includes("url_encode_placeholder") 83 | : true, 84 | }, 85 | ]; 86 | settings[getBangKey(bang.t)] = bangTargets; 87 | } 88 | // Exceptions for DDG (unfortunately, default bangs do not expose this info). 89 | settings[getBangKey("wayback")][0].urlEncodeQuery = false; 90 | settings[getBangKey("waybackmachine")][0].urlEncodeQuery = false; 91 | // Fetch custom bangs. 92 | await browser.storage.sync.get().then( 93 | function onGot(storedSettings) { 94 | for (const [key, item] of Object.entries(storedSettings)) { 95 | // In the session storage, for the bangs we only need the targets. 96 | settings[key] = key.startsWith(PreferencePrefix.BANG) 97 | ? item.targets 98 | : item; 99 | } 100 | if ( 101 | !Object.hasOwn(settings, PreferencePrefix.BANG_SYMBOL) || 102 | !settings[PreferencePrefix.BANG_SYMBOL] 103 | ) { 104 | settings[PreferencePrefix.BANG_SYMBOL] = Defaults.BANG_SYMBOL; 105 | } 106 | browser.storage.session.clear().then( 107 | function onCleared() { 108 | browser.storage.session.set(settings); 109 | }, 110 | function onError(error) {}, 111 | ); 112 | }, 113 | function onError(error) { 114 | // TODO: Handle error. 115 | }, 116 | ); 117 | return null; 118 | } 119 | 120 | function getBangKey(bang) { 121 | if (bang == null) { 122 | return null; 123 | } 124 | return `${PreferencePrefix.BANG}${bang.toLowerCase()}`; 125 | } 126 | 127 | function getBangName(bangKey) { 128 | if (bangKey == null) { 129 | return null; 130 | } 131 | return bangKey.slice(PreferencePrefix.BANG.length); 132 | } 133 | -------------------------------------------------------------------------------- /web-ext-config.mjs: -------------------------------------------------------------------------------- 1 | export default { 2 | ignoreFiles: [ 3 | "img/", 4 | "changelog/", 5 | "node_modules/", 6 | "package.json", 7 | "package-lock.json", 8 | "web-ext-config.mjs", 9 | "README.md", 10 | "CONTRIBUTING.md", 11 | ], 12 | }; 13 | -------------------------------------------------------------------------------- /yang.xpi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlls/yang/b387af39f85e1073b94ec1f86a98a76727d9042e/yang.xpi --------------------------------------------------------------------------------