├── .browserslistrc ├── .editorconfig ├── .gitignore ├── .stylelintrc ├── DEVELOP.md ├── LICENSE ├── PRIVACY.md ├── README.md ├── angular.json ├── package-lock.json ├── package.json ├── screenshots ├── pinboard-pin-dark.png ├── pinboard-pin-light.png └── pinboard-pin-settings.png ├── src ├── app │ ├── app.component.ts │ ├── app.module.ts │ ├── background │ │ └── background.component.ts │ ├── guard.ts │ ├── icon.service.ts │ ├── index.ts │ ├── interval.pipe.ts │ ├── login │ │ ├── login.component.html │ │ ├── login.component.scss │ │ └── login.component.ts │ ├── options │ │ ├── options.component.html │ │ ├── options.component.scss │ │ └── options.component.ts │ ├── pinboard.service.ts │ ├── pinpage │ │ ├── pinpage.component.html │ │ ├── pinpage.component.scss │ │ └── pinpage.component.ts │ └── storage.service.ts ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── img │ ├── pinboard_128.png │ ├── pinboard_16.png │ ├── pinboard_24.png │ ├── pinboard_256.png │ ├── pinboard_32.png │ ├── pinboard_48.png │ ├── pinboard_64.png │ ├── pinboard_96.png │ ├── pinboard_idle_128.png │ ├── pinboard_idle_16.png │ ├── pinboard_idle_24.png │ ├── pinboard_idle_256.png │ ├── pinboard_idle_32.png │ ├── pinboard_idle_48.png │ ├── pinboard_idle_64.png │ └── pinboard_idle_96.png ├── index.html ├── js │ └── content.js ├── main.ts ├── manifest.json ├── polyfills.ts └── styles.scss ├── tsconfig.app.json ├── tsconfig.json └── tslint.json /.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Firefox version 12 | Firefox ESR 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # cache 4 | .angular/cache 5 | .nx/cache 6 | 7 | # compiled output 8 | /dist 9 | /tmp 10 | /out-tsc 11 | 12 | # dependencies 13 | /node_modules 14 | 15 | # built extensions 16 | *.xpi 17 | *.zip 18 | 19 | # IDEs and editors 20 | .idea/ 21 | .project/ 22 | .classpath 23 | .c9/ 24 | *.launch 25 | .settings/ 26 | *.sublime-workspace 27 | .vscode/ 28 | 29 | # misc 30 | /.sass-cache 31 | /connect.lock 32 | /coverage 33 | /libpeerconnection.log 34 | npm-debug.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | -------------------------------------------------------------------------------- /.stylelintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "stylelint-config-standard" 3 | } 4 | -------------------------------------------------------------------------------- /DEVELOP.md: -------------------------------------------------------------------------------- 1 | Development Notes for Pinboard Pin 2 | ================================== 3 | 4 | This is an add-on for pinning pages on [Pinboard](https://pinboard.in) in the web browser, based on the [WebExtensions](https://developer.mozilla.org/de/Add-ons/WebExtensions) system. This web extension has been developed for and tested with Firefox 80 for Windows and Linux. Since WebExtensions was created as a cross-browser standard, it should be portable to other platforms and web browsers like Chrome, Opera or Edge with only few adaptations. 5 | 6 | The web extension has been created using [Angular](https://angular.io/) and the [Angular CLI](https://github.com/angular/angular-cli). 7 | 8 | Installation 9 | ------------ 10 | 11 | Install the application for development: 12 | 13 | npm install 14 | 15 | Building and testing 16 | -------------------- 17 | 18 | Build extension for development: 19 | 20 | npm run build 21 | 22 | Test extension with Firefox: 23 | 24 | npm run test 25 | 26 | Build unsigned extension for production: 27 | 28 | npm run build:prod 29 | 30 | Package unsigned extension as zip file: 31 | 32 | npm run build:zip 33 | 34 | Known issues 35 | ------------ 36 | 37 | * Due to limitations in the Web-Ext API, the keyboard shortcut (Alt+P) cannot be changed or deactivated (at least I don't see a simple way how to do this - let me know if I'm overlooking something). 38 | 39 | * Unfortunately, storing tabsets is not supported by the Pinboard API. Therefore you need to be logged in to Pinboard in order use this feature. This works the same as in the official add-on. 40 | 41 | * If you get errors when requesting data from the Pinboard API via https, these could be caused by the Privacy Badger extension. Make sure that the domain pinboard.in is fully enabled in Privacy Badger or whitelist it. 42 | 43 | Future development 44 | ------------------ 45 | 46 | * Use v2 of the Pinboard API when this is available with all the necessary functionality. 47 | 48 | * Require only those permissions that are needed for the selected options (issue #8). 49 | 50 | * The Pinboard API seems to have the "popular" and "recommended" categories interchanged in the "suggest" method for tags. "Popular" are actually those taken from our own tags, contrary to what the Pinboard API docs say. This has already been reported to the Pinboard support. If they will changed this behavior, we need to adapt our code that currently swaps these categories. 51 | 52 | * Ask Pinboard author to provide a method for storing tabsets and support it in the add-on. 53 | 54 | * The PinPageComponent is much too big, and should be refactored to use child components, and objects instead of individual properties for the form fields, similar to the OptionsComponent. 55 | 56 | * Make this extension also work with Chrome (use the `chrome.*` API instead of the `browser.*` API provided by Firefox). 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /PRIVACY.md: -------------------------------------------------------------------------------- 1 | Privacy Policy for the Pinboard-Pin Add-On 2 | ========================================== 3 | 4 | This add-on communicates with the [Pinboard](https://pinboard.in/) service using the [Pinboard API](https://pinboard.in/api) for the purpose of storing and updating bookmarks in your personal Pinboard account. 5 | 6 | In order to access your personal Pinboard account, your personal Pinboard API token is requested by the add-on and cached locally until you log out using the add-on. Your Pinboard password is not requested, accessed or stored by the add-on. 7 | 8 | In order to provide suggestions for tagging bookmarks, the add-on retrieves your tags stored in your personal Pinboard account using the Pinboard API and caches these tags locally. 9 | 10 | The data sent to the Pinboard service are the URL of the bookmarked link, its title, description, tags, and privacy and read status on Pinboard. 11 | 12 | If you activate the option "always check and show whether pages have been bookmarked" (which is deactivated by default), then the add-on checks for every tab whether it has been already bookmarked. For this purpose, it sends the URL of the tab to the Pinboard service using the Pinboard API. 13 | 14 | Please also read the [Pinboard privacy policy](https://pinboard.in/privacy/) for information on the privacy police of the Pinboard service itself. 15 | 16 | The author of this add-on is not affiliated with the Pinboard service in any way and does not take any responsibility for how the service handles your bookmarks. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Pinboard Pin Web Extension for Firefox 2 | -------------------------------------- 3 | 4 | Pinboard Pin is a modern web extension for pinning pages on [Pinboard](https://pinboard.in) with Firefox. 5 | 6 | Pinboard is a fast, no-nonsense bookmarking site for people who value privacy and speed. Note that while the Pinboard Pin extension is provided by its author as free and open source software, Pinboard is a separate, paid service and you need to sign up for an account in order to use it. The author of Pinboard Pin is not affiliated with the provider of the Pinboard service. For any questions regarding the Pinboard service itself, please contact the Pinboard support. 7 | 8 | This extension pretty much replicates the functionality of the [Pinboard Plus](https://github.com/clvrobj/Pinboard-Plus) extension that has been created for the Chrome browser, but it has been rewritten from scratch to support Firefox using the modern [Angular](https://angular.io/) framework instead of a mix of the older [AngularJS](https://angularjs.org/), [jQuery](https://jquery.com/) and [Underscore](http://underscorejs.org/) libraries used by Pinboard Plus. This rewrite was also intended as a proof-of-concept that modern Angular is a viable platform for building web extensions. 9 | 10 | The current version has been tested with Firefox 80 for Windows and Linux. 11 | 12 | Features 13 | -------- 14 | 15 | * Icon that changes its color to show whether the current page has been bookmarked in Pinboard. 16 | * Save a new bookmark for the current page in Pinboard, adding description and tags in a popup dialog. 17 | * Update and delete the bookmark for the current page in Pinboard from the popup. 18 | * Automatic creation of a description from a selected text on the page or using an existing meta tag on the page. 19 | * Enter or update tags using automatic suggestions in the popup dialog. 20 | * Use a keyboard shortcut (Alt + P) to open the popup dialog. 21 | * Use the context menu to open the popup dialog for the current page or to quickly save any link on the page. 22 | * Configurable dark mode for the popup dialog. 23 | 24 | Installation 25 | ------------ 26 | 27 | You can install the extension using the [Mozilla Add-ons](https://addons.mozilla.org/de/firefox/addon/pinboard-pin/) page. 28 | 29 | Notes 30 | ----- 31 | 32 | Note that you must explicitly enable the option for displaying whether the page has already been saved on Pinboard, because this will send the URL of the page to the Pinboard server for every page. Therefore this feature is also automatically disabled in "incognito mode". 33 | 34 | Also note that if you are using the Privacy Badger extension and Pinboard Pin shows an error when accessing Pinboard, make sure that the domain pinboard.in is not blocked in the filter settings of Privacy Badger, or simply put in on the whitelist of Privacy Badger. 35 | 36 | Development 37 | ----------- 38 | 39 | * Follow the instructions outlined in [DEVELOP.md](https://github.com/cito/Pinboard-Pin/blob/master/DEVELOP.md) if you want to build this extension on your own or run it in development mode. 40 | * Read my blog post [Web Extensions made with Angular](https://cito.github.io/blog/web-ext-with-angular/) to learn more about how and why this extension has been created. 41 | * Contact the author, open GitHub issues or send in pull requests to contribute. 42 | 43 | Author 44 | ------ 45 | 46 | * [Christoph Zwerschke](https://github.com/cito) 47 | 48 | Some Screenshots 49 | ---------------- 50 | 51 | Saving a page with Pinboard Pin: 52 | 53 | ![Saving a page - light mode](screenshots/pinboard-pin-light.png?raw=true) 54 | 55 | Changing the Pinboard Pin settings: 56 | 57 | ![Settings - light mode](screenshots/pinboard-pin-settings.png?raw=true) 58 | 59 | Pinboard Pin also supports dark mode: 60 | 61 | ![Saving a page - dark mode](screenshots/pinboard-pin-dark.png?raw=true) 62 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "pinboard-pin": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | }, 12 | "@schematics/angular:application": { 13 | "strict": true 14 | } 15 | }, 16 | "root": "", 17 | "sourceRoot": "src", 18 | "prefix": "app", 19 | "architect": { 20 | "build": { 21 | "builder": "@angular-devkit/build-angular:browser", 22 | "options": { 23 | "outputPath": "dist", 24 | "index": "src/index.html", 25 | "main": "src/main.ts", 26 | "polyfills": "src/polyfills.ts", 27 | "tsConfig": "tsconfig.app.json", 28 | "inlineStyleLanguage": "scss", 29 | "assets": [ 30 | "src/img", 31 | "src/js", 32 | "src/manifest.json" 33 | ], 34 | "styles": [ 35 | "src/styles.scss" 36 | ], 37 | "scripts": [], 38 | "vendorChunk": true, 39 | "extractLicenses": false, 40 | "buildOptimizer": false, 41 | "sourceMap": true, 42 | "optimization": false, 43 | "namedChunks": true 44 | }, 45 | "configurations": { 46 | "production": { 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "500kb", 51 | "maximumError": "1mb" 52 | }, 53 | { 54 | "type": "anyComponentStyle", 55 | "maximumWarning": "2kb", 56 | "maximumError": "4kb" 57 | } 58 | ], 59 | "optimization": { 60 | "scripts": true, 61 | "styles": { 62 | "minify": true, 63 | "inlineCritical": false 64 | }, 65 | "fonts": true 66 | }, 67 | "outputHashing": "all", 68 | "sourceMap": false, 69 | "namedChunks": false, 70 | "extractLicenses": true, 71 | "vendorChunk": false, 72 | "buildOptimizer": true, 73 | "fileReplacements": [ 74 | { 75 | "replace": "src/environments/environment.ts", 76 | "with": "src/environments/environment.prod.ts" 77 | } 78 | ] 79 | } 80 | } 81 | }, 82 | "serve": { 83 | "builder": "@angular-devkit/build-angular:dev-server", 84 | "options": { 85 | "buildTarget": "pinboard-pin:build" 86 | }, 87 | "configurations": { 88 | "production": { 89 | "buildTarget": "pinboard-pin:build:production" 90 | } 91 | } 92 | }, 93 | "extract-i18n": { 94 | "builder": "@angular-devkit/build-angular:extract-i18n", 95 | "options": { 96 | "buildTarget": "pinboard-pin:build" 97 | } 98 | }, 99 | "lint": { 100 | "builder": "@angular-devkit/build-angular:tslint", 101 | "options": { 102 | "tsConfig": [ 103 | "tsconfig.app.json" 104 | ], 105 | "exclude": [] 106 | } 107 | } 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pinboard-pin", 3 | "version": "0.4.3", 4 | "license": "MIT", 5 | "scripts": { 6 | "build": "ng build", 7 | "build:prod": "ng build --configuration production --source-map=false --output-hashing=none", 8 | "build:ext": "web-ext build --source-dir=dist --artifacts-dir=.", 9 | "build:zip": "npm run build:prod && npm run build:ext", 10 | "lint": "tslint \"src/**/*.ts\"", 11 | "test": "web-ext run --source-dir=dist --firefox=\"C:/Program Files/Mozilla Firefox/firefox.exe\"", 12 | "test:dev": "web-ext run --source-dir=dist --firefox=\"C:/Program Files/Firefox Developer Edition/firefox.exe\"", 13 | "test:nightly": "web-ext run --source-dir=dist --firefox=\"C:/Program Files/Nightly/firefox.exe\"" 14 | }, 15 | "private": true, 16 | "dependencies": { 17 | "@angular/common": "^17.3.5", 18 | "@angular/compiler": "^17.3.5", 19 | "@angular/core": "^17.3.5", 20 | "@angular/forms": "^17.3.5", 21 | "@angular/platform-browser": "^17.3.5", 22 | "@angular/platform-browser-dynamic": "^17.3.5", 23 | "@angular/router": "^17.3.5", 24 | "rxjs": "^7.8.1", 25 | "tslib": "^2.6.2", 26 | "zone.js": "~0.14.4" 27 | }, 28 | "devDependencies": { 29 | "@angular-devkit/build-angular": "^17.3.5", 30 | "@angular/cli": "^17.3.5", 31 | "@angular/compiler-cli": "^17.3.5", 32 | "@angular/language-service": "^17.3.5", 33 | "@angular-eslint/builder": "^17.3.0", 34 | "@angular-eslint/eslint-plugin": "^17.3.0", 35 | "@angular-eslint/eslint-plugin-template": "^17.3.0", 36 | "@angular-eslint/schematics": "^17.3.0", 37 | "@angular-eslint/template-parser": "^17.3.0", 38 | "@types/node": "^20.12.7", 39 | "@typescript-eslint/eslint-plugin": "^7.7.0", 40 | "@typescript-eslint/parser": "^7.7.0", 41 | "@types/firefox-webext-browser": "^120.0.3", 42 | "eslint": "^8.57.0", 43 | "typescript": "^5.4.5", 44 | "web-ext": "^7.11.0" 45 | } 46 | } -------------------------------------------------------------------------------- /screenshots/pinboard-pin-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/screenshots/pinboard-pin-dark.png -------------------------------------------------------------------------------- /screenshots/pinboard-pin-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/screenshots/pinboard-pin-light.png -------------------------------------------------------------------------------- /screenshots/pinboard-pin-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/screenshots/pinboard-pin-settings.png -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | 4 | // Root component of the application 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | template: '' 9 | }) 10 | export class AppComponent { } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpClientModule } from '@angular/common/http'; 5 | import { Routes, RouterModule } from '@angular/router'; 6 | 7 | import { AppComponent } from './app.component'; 8 | import { LoginComponent } from './login/login.component'; 9 | import { PinPageComponent } from './pinpage/pinpage.component'; 10 | import { OptionsComponent } from './options/options.component'; 11 | import { BackgroundComponent } from './background/background.component'; 12 | 13 | import { guard } from './guard'; 14 | import { PinboardService } from './pinboard.service'; 15 | import { StorageService } from './storage.service'; 16 | import { IconService } from './icon.service'; 17 | 18 | import { AgoPipe } from './interval.pipe'; 19 | 20 | 21 | const appRoutes: Routes = [ 22 | { path: 'login', component: LoginComponent }, 23 | { path: 'options', component: OptionsComponent }, 24 | { path: 'background', component: BackgroundComponent }, 25 | { path: '**', component: PinPageComponent, canActivate: [guard] } 26 | ]; 27 | 28 | 29 | @NgModule({ 30 | declarations: [ 31 | AppComponent, 32 | PinPageComponent, 33 | OptionsComponent, 34 | LoginComponent, 35 | AgoPipe, 36 | BackgroundComponent 37 | ], 38 | imports: [ 39 | BrowserModule, 40 | FormsModule, 41 | HttpClientModule, 42 | RouterModule.forRoot(appRoutes) 43 | ], 44 | providers: [PinboardService, StorageService, IconService], 45 | bootstrap: [AppComponent] 46 | }) 47 | export class AppModule { } 48 | -------------------------------------------------------------------------------- /src/app/background/background.component.ts: -------------------------------------------------------------------------------- 1 | // this component pings the saved state of pages in the background 2 | 3 | import { Component, OnInit, OnDestroy } from '@angular/core'; 4 | import { StorageService } from '../storage.service'; 5 | import { PinboardService } from '../pinboard.service'; 6 | import { Post } from '../pinpage/pinpage.component'; 7 | import { IconService } from '../icon.service'; 8 | import { Options } from '../storage.service'; 9 | 10 | // Background page used for checking whether pages are saved in Pinboard 11 | 12 | @Component({ 13 | selector: 'app-background', 14 | template: '

Background page for Pinboard

' 15 | }) 16 | export class BackgroundComponent implements OnInit, OnDestroy { 17 | 18 | private readonly updatedListener: 19 | (tabId: number, changeInfo: any, tab: browser.tabs.Tab) => void; 20 | private readonly messageListener: 21 | (message: any) => void; 22 | private readonly menuListener: 23 | (info: browser.menus.OnClickData, tab: browser.tabs.Tab) => void; 24 | 25 | constructor( 26 | private storage: StorageService, 27 | private pinboard: PinboardService, 28 | private icon: IconService) { 29 | this.updatedListener = this.onUpdated.bind(this); 30 | this.messageListener = this.onMessage.bind(this); 31 | this.menuListener = this.onMenuClicked.bind(this); 32 | } 33 | 34 | private ping = false; 35 | private menu = false; 36 | private toread = false; 37 | private unshared = false; 38 | 39 | ngOnInit() { 40 | this.storage.getOptions().subscribe(options => { 41 | this.setOnMessageListener(true); 42 | this.onMessage({ options }); 43 | }); 44 | } 45 | 46 | ngOnDestroy() { 47 | this.setOnUpdateListener(false); 48 | this.setOnMessageListener(false); 49 | this.setOnMenuClickedListener(false); 50 | } 51 | 52 | // set the listener for internal messages 53 | setOnMessageListener(on: boolean) { 54 | const event = browser.runtime.onMessage; 55 | const listener = this.messageListener; 56 | if (event.hasListener(listener)) { 57 | if (!on) { 58 | event.removeListener(listener); 59 | } 60 | } else { 61 | if (on) { 62 | event.addListener(listener); 63 | } 64 | } 65 | } 66 | 67 | // fires when another process connects 68 | onMessage(message: any): void { 69 | const options: Options = message.options; 70 | if (options) { 71 | if (options.ping !== this.ping) { 72 | this.setOnUpdateListener(options.ping); 73 | } 74 | if (options.menu !== this.menu) { 75 | this.setOnMenuClickedListener(options.menu); 76 | } 77 | this.toread = options.toread; 78 | this.unshared = options.unshared; 79 | } 80 | } 81 | 82 | // set the listener for url update in browser tabs 83 | setOnUpdateListener(on: boolean) { 84 | const event = browser.tabs.onUpdated; 85 | const listener = this.updatedListener; 86 | if (event.hasListener(listener)) { 87 | if (!on) { 88 | event.removeListener(listener); 89 | } 90 | } else { 91 | if (on) { 92 | event.addListener(listener); 93 | } 94 | } 95 | this.ping = on; 96 | } 97 | 98 | // fires when the active tab in a window changes 99 | onUpdated(tabId: number, changeInfo: any, tab: browser.tabs.Tab): void { 100 | // do not ping Pinboard in incognito mode 101 | if (tab.incognito) { 102 | return; 103 | } 104 | const url = changeInfo.url; 105 | if (url) { 106 | if (/^https?:\/\//.test(url)) { 107 | this.pinboard.get(url).subscribe( 108 | data => this.icon.setIcon( 109 | tabId, !!(data && data.posts && data.posts.length)), 110 | error => this.icon.setIcon(tabId, false)); 111 | } else { 112 | this.icon.setIcon(tabId, false); 113 | } 114 | } 115 | } 116 | 117 | // set the listener for context menu clicks 118 | setOnMenuClickedListener(on: boolean) { 119 | const menus = browser.contextMenus; 120 | const event = menus.onClicked; 121 | const listener = this.menuListener; 122 | if (event.hasListener(listener)) { 123 | if (!on) { 124 | event.removeListener(listener); 125 | menus.remove('save-link-to-pinboard'); 126 | menus.remove('save-page-to-pinboard'); 127 | } 128 | } else { 129 | if (on) { 130 | browser.contextMenus.create({ 131 | id: 'save-page-to-pinboard', 132 | title: 'Save page to Pinboard', 133 | contexts: ['page'], 134 | documentUrlPatterns: ['http://*/*', 'https://*/*'], 135 | command: '_execute_browser_action' 136 | }); 137 | browser.contextMenus.create({ 138 | id: 'save-link-to-pinboard', 139 | title: 'Save link to Pinboard', 140 | contexts: ['link'], 141 | targetUrlPatterns: ['http://*/*', 'https://*/*'] 142 | }); 143 | event.addListener(listener); 144 | } 145 | } 146 | this.menu = on; 147 | } 148 | 149 | // handle menu clicks for saving links in the background 150 | onMenuClicked(info: browser.menus.OnClickData, tab: browser.tabs.Tab): void { 151 | if (info.menuItemId === 'save-link-to-pinboard' && info.linkUrl) { 152 | const url = info.linkUrl; 153 | // since we cannot get the actual title, we use the link text instead 154 | const title = info.linkText || 'Link saved with Pinboard Pin'; 155 | const post: Post = { 156 | url, title, description: '', tags: '', 157 | unshared: this.unshared, toread: this.toread, 158 | // links will be only added, 159 | // we do not want to overwrite existing titles and descriptions 160 | noreplace: true 161 | }; 162 | this.pinboard.save(post).subscribe( 163 | error => { 164 | if (error && !/already exists/.test(error)) { 165 | this.saveLinkError(error); 166 | } 167 | }, 168 | error => { 169 | this.saveLinkError(error.toString()); 170 | }); 171 | } 172 | } 173 | 174 | saveLinkError(error: string): void { 175 | console.error(error); 176 | // we cannot display an alert directly, so we use a workaround 177 | const showAlert = 'alert("Could not save the link to Pinboard.")'; 178 | browser.tabs.executeScript(null, { code: showAlert }); 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/app/guard.ts: -------------------------------------------------------------------------------- 1 | import { inject } from '@angular/core'; 2 | import { Router, ActivatedRouteSnapshot } from '@angular/router'; 3 | 4 | import { map } from 'rxjs/operators'; 5 | 6 | import { PinboardService } from './pinboard.service'; 7 | 8 | 9 | // Guard for the index route of this extension 10 | 11 | 12 | export const guard = (route: ActivatedRouteSnapshot) => { 13 | const pinboard = inject(PinboardService); 14 | const router = inject(Router); 15 | 16 | const page = route.queryParams['page']; 17 | 18 | if (!page || page === 'popup') { 19 | return pinboard.needToken.pipe(map(needed => { 20 | if (!needed) { 21 | return true; 22 | } 23 | router.navigate(['/login']); 24 | return false; 25 | })); 26 | } 27 | 28 | router.navigate(['/' + page]); 29 | return false; 30 | }; 31 | -------------------------------------------------------------------------------- /src/app/icon.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | const defaultIcon = { 4 | '16': '/img/pinboard_idle_16.png', 5 | '24': '/img/pinboard_idle_24.png', 6 | '32': '/img/pinboard_idle_32.png', 7 | '48': '/img/pinboard_idle_48.png', 8 | '64': '/img/pinboard_idle_64.png', 9 | '96': '/img/pinboard_idle_96.png', 10 | '128': '/img/pinboard_idle_128.png', 11 | '256': '/img/pinboard_idle_256.png' 12 | }; 13 | 14 | const savedIcon = { 15 | '16': '/img/pinboard_16.png', 16 | '24': '/img/pinboard_24.png', 17 | '32': '/img/pinboard_32.png', 18 | '48': '/img/pinboard_48.png', 19 | '64': '/img/pinboard_64.png', 20 | '96': '/img/pinboard_96.png', 21 | '128': '/img/pinboard_128.png', 22 | '256': '/img/pinboard_256.png' 23 | }; 24 | 25 | 26 | // Service for setting the browser action icon 27 | 28 | @Injectable() 29 | export class IconService { 30 | 31 | constructor() { } 32 | 33 | // set the icon for saved or unsaved for the given tab 34 | setIcon(tabId: number, saved: boolean) { 35 | browser.browserAction.setIcon({ 36 | tabId: tabId, path: saved ? savedIcon : defaultIcon 37 | }); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/app/index.ts: -------------------------------------------------------------------------------- 1 | export * from './app.component'; 2 | export * from './app.module'; 3 | -------------------------------------------------------------------------------- /src/app/interval.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | 3 | const msPerSecond = 1000; 4 | const msPerMinute = msPerSecond * 60; 5 | const msPerHour = msPerMinute * 60; 6 | const msPerDay = msPerHour * 24; 7 | const msPerMonth = msPerDay * 30; 8 | const msPerYear = msPerDay * 365; 9 | 10 | const intervalUnits = [ 11 | 'second', 'minute', 'hour', 'day', 'month', 'year']; 12 | const intervalParts = [ 13 | msPerSecond, msPerMinute, msPerHour, msPerDay, msPerMonth, msPerYear]; 14 | 15 | 16 | // Pipe for showing time intervals 17 | 18 | @Pipe({ 19 | name: 'ago' 20 | }) 21 | export class AgoPipe implements PipeTransform { 22 | 23 | // show date as passed time in simple human readable form 24 | transform(value: Date | string): string { 25 | if (!value) { 26 | return 'some time ago'; 27 | } 28 | 29 | const time: number = typeof value === 'string' ? 30 | Date.parse(value as string) : (value as Date).getTime(); 31 | const elapsed = Date.now() - time; 32 | 33 | if (elapsed < 0) { 34 | return 'some time ago'; 35 | } 36 | if (elapsed < msPerSecond) { 37 | return 'just now'; 38 | } 39 | 40 | for (let i = 0; i < 6; ++i) { 41 | if (i > 4 || elapsed < intervalParts[i + 1]) { 42 | const n = Math.round(elapsed / intervalParts[i]); 43 | let unit = intervalUnits[i]; 44 | if (n !== 1) { 45 | unit += 's'; 46 | } 47 | return n + ' ' + unit + ' ago'; 48 | } 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/app/login/login.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Log in to Pinboard

4 | 5 |

You must log in to Pinboard first using the API token 6 | that you can find on your 7 | Pinboard password page.

8 | 9 |
10 |
11 | 15 | 17 |
18 |
19 | 21 | 24 |
25 |
26 | 27 |
-------------------------------------------------------------------------------- /src/app/login/login.component.scss: -------------------------------------------------------------------------------- 1 | .popup { 2 | width: 400px; 3 | } 4 | 5 | div label { 6 | line-height: 175%; 7 | } 8 | 9 | form div { 10 | display: flex; 11 | flex-direction: row; 12 | align-items: stretch; 13 | input[type="text"] { 14 | flex: 1 0 70px; 15 | margin-right: 8px; 16 | } 17 | 18 | button { 19 | flex: 0 0 80px; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app/login/login.component.ts: -------------------------------------------------------------------------------- 1 | // this component is the login dialog displayed in the popup 2 | 3 | import { Component, OnInit } from '@angular/core'; 4 | import { NgForm } from '@angular/forms'; 5 | import { Router } from '@angular/router'; 6 | 7 | import { passwordPage, PinboardService } from '../pinboard.service'; 8 | import { Options, StorageService } from '../storage.service'; 9 | 10 | export interface Login { 11 | token: string; 12 | } 13 | 14 | 15 | // Log in form 16 | 17 | @Component({ 18 | selector: 'app-login', 19 | templateUrl: './login.component.html', 20 | styleUrls: ['./login.component.scss'] 21 | }) 22 | export class LoginComponent implements OnInit { 23 | 24 | checking = false; 25 | error = false; 26 | 27 | theme = 'light'; // color scheme of the page 28 | 29 | constructor( 30 | private pinboard: PinboardService, 31 | private storage: StorageService, 32 | private router: Router) { } 33 | 34 | ngOnInit() { 35 | this.storage.getOptions().subscribe(options => 36 | this.setTheme(options)); 37 | } 38 | 39 | setTheme(options: Options) { 40 | this.theme = ( 41 | options.dark === true || 42 | options.dark !== false && 43 | window.matchMedia('(prefers-color-scheme: dark)').matches) ? 44 | 'dark' : 'light'; 45 | } 46 | 47 | openPasswordPage() { 48 | browser.windows.create({ url: passwordPage }); 49 | return false; 50 | } 51 | 52 | // submit form (store token) 53 | submit(form: NgForm) { 54 | if (!form.valid) { 55 | return false; 56 | } 57 | let token = form.value.token; 58 | if (!token) { 59 | return false; 60 | } 61 | token = token.trim(); 62 | if (!token) { 63 | return false; 64 | } 65 | this.checking = true; 66 | this.pinboard.setToken(token).subscribe( 67 | ok => { 68 | this.error = !ok; 69 | if (ok) { 70 | this.continue(); 71 | } else { 72 | this.checking = false; 73 | } 74 | }, 75 | error => { 76 | this.error = true; 77 | console.error(error.toString()); 78 | this.checking = false; 79 | }); 80 | return false; 81 | } 82 | 83 | continue() { 84 | this.router.navigate(['/popup']); 85 | } 86 | 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/app/options/options.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 |
6 | 7 |

{{ page == 'popup'? 'Pinboard Pin Options' : 'Options' }}

8 | 9 |
10 |
11 | 13 | 14 |
15 |
16 | 18 | 19 |
20 |
21 | 23 | 24 |
25 |
26 | 28 | 29 |
30 |
31 | 33 | 34 |
35 |
36 | 38 | 39 |
40 |
41 | 43 | 44 |
45 |
46 | 48 | 49 |
50 |
51 | 53 | 54 |
55 |
56 | 57 | 59 | 60 | 62 | 63 | 65 | 66 |
67 |
68 | Keyboard shortcut for saving pages to Pinboard Pin: 69 | {{shortcut}} 70 |
71 |
72 | 73 |
-------------------------------------------------------------------------------- /src/app/options/options.component.scss: -------------------------------------------------------------------------------- 1 | .options { 2 | padding: 8px; 3 | 4 | h1 { 5 | font-size: 24px; 6 | font-weight: normal; 7 | margin: 18px 0 12px; 8 | padding: 0; 9 | } 10 | } 11 | 12 | .popup { 13 | width: 500px; 14 | } 15 | 16 | input[type="checkbox"] { 17 | margin-right: 8px; 18 | } 19 | 20 | input[type="radio"] { 21 | margin-left: 16px; 22 | } 23 | 24 | .popup div button { 25 | float: right; 26 | } 27 | 28 | form div { 29 | display: flex; 30 | align-items: center; 31 | } 32 | -------------------------------------------------------------------------------- /src/app/options/options.component.ts: -------------------------------------------------------------------------------- 1 | // this component is the user setting dialog displayed under options 2 | 3 | import { Component, OnInit, OnDestroy, ApplicationRef } from '@angular/core'; 4 | import { NgForm } from '@angular/forms'; 5 | import { Options, StorageService } from '../storage.service'; 6 | 7 | 8 | // Options form 9 | 10 | @Component({ 11 | selector: 'app-options', 12 | templateUrl: './options.component.html', 13 | styleUrls: ['./options.component.scss'] 14 | }) 15 | export class OptionsComponent implements OnInit, OnDestroy { 16 | 17 | options: Options; 18 | 19 | shortcut: string; // default keyboard shortcut 20 | 21 | page: string; // type of page (popup or options) 22 | 23 | theme = 'light'; // color scheme of the page 24 | 25 | private readonly messageListener: (message: any) => void; 26 | 27 | constructor( 28 | private storage: StorageService, 29 | private appRef: ApplicationRef) { 30 | this.messageListener = this.onMessage.bind(this); 31 | } 32 | 33 | ngOnInit() { 34 | this.page = this.storage.getInfo('options.page') || 'options'; 35 | this.storage.getOptions().subscribe(options => { 36 | this.options = options; 37 | this.setTheme(); 38 | this.setOnMessageListener(true); 39 | }); 40 | browser.commands.getAll().then(commands => { 41 | for (const command of commands) { 42 | if (command.name === '_execute_browser_action') { 43 | this.shortcut = command.shortcut; 44 | } 45 | } 46 | }); 47 | } 48 | 49 | ngOnDestroy() { 50 | this.setOnMessageListener(false); 51 | } 52 | 53 | setTheme() { 54 | this.theme = ( 55 | this.options.dark === true || 56 | this.options.dark !== false && 57 | window.matchMedia('(prefers-color-scheme: dark)').matches) ? 58 | 'dark' : 'light'; 59 | } 60 | 61 | // check whether given options are the same 62 | sameOptions(options: Options): boolean { 63 | for (const key in this.options) { 64 | if (typeof this.options[key] === 'boolean' 65 | && key !== 'dark') { 66 | options[key] = !!options[key]; 67 | } 68 | } 69 | for (const key in options) { 70 | if (options[key] !== this.options[key]) { 71 | return false; 72 | } 73 | } 74 | return true; 75 | } 76 | 77 | // set the listener for internal messages 78 | setOnMessageListener(on: boolean) { 79 | const event = browser.runtime.onMessage; 80 | const listener = this.messageListener; 81 | if (event.hasListener(listener)) { 82 | if (!on) { 83 | event.removeListener(listener); 84 | } 85 | } else { 86 | if (on) { 87 | event.addListener(listener); 88 | } 89 | } 90 | } 91 | 92 | // fires when another process connects 93 | // this synchronizes the settings if options popup and options page 94 | // are open at the same time 95 | onMessage(message: any): void { 96 | const options = message.options; 97 | if (options && !this.sameOptions(options)) { 98 | this.options = options; 99 | this.setTheme(); 100 | this.appRef.tick(); // run change detection 101 | } 102 | } 103 | 104 | // submit form (store options in local storage) 105 | submit(form: NgForm) { 106 | if (!form.valid) { 107 | return false; 108 | } 109 | const value: Options = form.value; 110 | if (!value || this.sameOptions(value)) { 111 | return false; 112 | } 113 | this.options = value; 114 | this.setTheme(); 115 | this.storage.setOptions(value).subscribe(); 116 | browser.runtime.sendMessage({ 'options': value }); 117 | return false; 118 | } 119 | 120 | // close the options popup 121 | close() { 122 | if (this.page === 'popup') { 123 | window.close(); 124 | } 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/app/pinboard.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | import { 4 | throwError as observableThrow, Observable, 5 | of as ObservableOf, forkJoin, from as ObservableFrom 6 | } from 'rxjs'; 7 | import { filter, map, mergeMap, switchMap, tap } from 'rxjs/operators'; 8 | 9 | import { StorageService } from './storage.service'; 10 | import { Post } from './pinpage/pinpage.component'; 11 | import { HttpClient, HttpParameterCodec, HttpParams } from '@angular/common/http'; 12 | 13 | export const pinboardPage = 'https://pinboard.in/'; 14 | 15 | export const passwordPage = pinboardPage + 'settings/password'; 16 | const tabsPage = pinboardPage + 'tabs/'; 17 | 18 | const apiUrl = 'https://api.pinboard.in/v1/'; 19 | 20 | const cacheTimeout = 1000 * 60 * 60; // one hour cache time 21 | 22 | // Create a custom encoder for query parameters that can be used 23 | // as a workaround for https://github.com/angular/angular/issues/18261 24 | // in order to fix https://github.com/Cito/Pinboard-Pin/issues/17 25 | 26 | class ParamsEncoder implements HttpParameterCodec { 27 | encodeKey(key: string): string { 28 | return encodeURIComponent(key); 29 | } 30 | 31 | encodeValue(value: string): string { 32 | return encodeURIComponent(value); 33 | } 34 | 35 | decodeKey(key: string): string { 36 | return decodeURIComponent(key); 37 | } 38 | 39 | decodeValue(value: string): string { 40 | return decodeURIComponent(value); 41 | } 42 | } 43 | 44 | const paramsEncoder = new ParamsEncoder(); 45 | 46 | 47 | // Service for dealing with the Pinboard API 48 | 49 | @Injectable() 50 | export class PinboardService { 51 | 52 | constructor(private http: HttpClient, private storage: StorageService) { } 53 | 54 | // get an object via the Pinboard API 55 | httpGet(method: string, params?: any): Observable { 56 | params = params || {}; 57 | if (!params.auth_token) { 58 | return this.storage.get('token').pipe(switchMap(token => { 59 | if (!token) { 60 | observableThrow(new Error('No API token!')); 61 | } 62 | params.auth_token = token; 63 | return this.httpGet(method, params); 64 | })); 65 | } 66 | params.format = 'json'; 67 | const httpParams = Object.entries(params).reduce( 68 | (params: HttpParams, [key, value]: [string, string]) => 69 | params.set(key, value), new HttpParams({ encoder: paramsEncoder })); 70 | return this.http.get( 71 | apiUrl + method, { params: httpParams }); 72 | } 73 | 74 | // check the given API token and memorize it if valid 75 | setToken(value: string): Observable { 76 | const values = value.split(':', 2); 77 | if (values.length !== 2) { 78 | return ObservableOf(false); 79 | } 80 | return this.httpGet( 81 | 'user/api_token', { auth_token: value }).pipe( 82 | map(data => data.result === values[1]), 83 | switchMap(ok => ok ? 84 | this.storage.set({ token: value }).pipe(map(() => true)) : 85 | ObservableOf(false))); 86 | } 87 | 88 | // check whether we still need an API token 89 | get needToken(): Observable { 90 | return this.storage.get('token').pipe(map(res => !res)); 91 | } 92 | 93 | // extract user name from API token 94 | get userName(): Observable { 95 | return this.storage.get('token').pipe( 96 | map(res => res && res.split(':', 1)[0]), filter(res => res)); 97 | } 98 | 99 | // forget the API token 100 | forgetToken(): Observable { 101 | // also clear the tags cache when leaving 102 | return this.storage.remove(['token', 'tags']); 103 | } 104 | 105 | // get bookmark with the given url 106 | get(url: string): Observable { 107 | return this.httpGet('posts/get', { url: url, meta: 'no' }); 108 | } 109 | 110 | // add or replace bookmark with given attributes 111 | save(post: Post): 112 | Observable { 113 | const params: any = { url: post.url, description: post.title, dt: new Date().toISOString() }; 114 | if (post.description) { 115 | params.extended = post.description; 116 | } 117 | if (post.tags) { 118 | params.tags = post.tags; 119 | } 120 | params.replace = post.noreplace ? 'no' : 'yes'; 121 | params.shared = post.unshared ? 'no' : 'yes'; 122 | params.toread = post.toread ? 'yes' : 'no'; 123 | return this.httpGet('posts/add', params).pipe( 124 | map(res => res.result_code === 'done' ? null : res.result_code)); 125 | } 126 | 127 | // delete bookmark with the given url 128 | delete(url: string): Observable { 129 | return this.httpGet('posts/delete', { url: url }); 130 | } 131 | 132 | // get suggested tags for the given url 133 | suggest(url: string): Observable { 134 | return this.httpGet( 135 | 'posts/suggest', { url: url }).pipe(map(data => { 136 | const tags = { popular: [], recommended: [] }; 137 | for (const d of data) { 138 | if (d.popular) { 139 | tags.popular.push(...d.popular); 140 | } 141 | if (d.recommended) { 142 | tags.recommended.push(...d.recommended); 143 | } 144 | } 145 | return tags; 146 | })); 147 | } 148 | 149 | // get post for the given url together with the suggested tags 150 | getAndSuggest(url: string): Observable { 151 | return forkJoin([this.get(url), this.suggest(url)]).pipe(map( 152 | data => Object.assign(data[0], data[1]))); 153 | } 154 | 155 | // get the list of all used tags (with numeric tag counters) 156 | tags(): Observable<{ [tag: string]: number }> { 157 | return this.httpGet('tags/get').pipe(map(tags => { 158 | for (const tag in tags) { 159 | if (tags.hasOwnProperty(tag)) { 160 | tags[tag] = +tags[tag]; 161 | } 162 | } 163 | return tags; 164 | })); 165 | } 166 | 167 | // get a cached list of all used tags 168 | cachedTags(): Observable<{ [tag: string]: number }> { 169 | return this.storage.get('tags').pipe(switchMap(tags => { 170 | const date = Date.now(); 171 | if (!tags || !tags.tags || !tags.date || 172 | tags.tags instanceof Array) { // old version used arrays 173 | // no tags cached, retrieve tags first from Pinboard 174 | return this.tags().pipe(tap(tags => 175 | this.storage.set({ tags: { tags: tags, date: date } }).subscribe())); 176 | } 177 | // replace outdated tags in the background 178 | if (tags.date > date || date - tags.date > cacheTimeout) { 179 | this.tags().subscribe(tags => 180 | this.storage.set({ tags: { tags: tags, date: date } }).subscribe()); 181 | } 182 | // but still return the cached tags for faster access 183 | return ObservableOf(tags.tags); 184 | })); 185 | } 186 | 187 | // update the cached object with all used tags and their frequency 188 | updateTagCache(addTags: string[], savedTags: string[]): Observable { 189 | return this.storage.get('tags').pipe(mergeMap(cache => { 190 | let tags: { [tag: string]: number }, date: number; 191 | if (cache && cache.tags && cache.date) { 192 | tags = cache.tags; 193 | date = cache.date; 194 | } else { 195 | tags = {}; 196 | date = Date.now(); 197 | } 198 | for (const tag of savedTags) { 199 | if (!addTags.includes[tag]) { 200 | if (tags.hasOwnProperty(tag)) { 201 | if (--tags[tag] <= 0) { 202 | delete tags[tag]; 203 | } 204 | } 205 | } 206 | } 207 | for (const tag of addTags) { 208 | if (!savedTags.includes[tag]) { 209 | if (tags.hasOwnProperty(tag)) { 210 | ++tags[tag]; 211 | } else { 212 | tags[tag] = 1; 213 | } 214 | } 215 | } 216 | return this.storage.set({ tags: { tags: tags, date: date } }); 217 | })); 218 | } 219 | 220 | // save the current tabs as tabset using the web form 221 | // (this operation is not provided by the Pinboard API) 222 | saveTabs(data: any): Observable { 223 | const params = new FormData(); 224 | params.append('data', JSON.stringify(data)); 225 | const post = this.http.post(tabsPage + 'save/', params); 226 | const show = ObservableFrom(browser.tabs.create( 227 | { url: tabsPage + 'show/' })); 228 | return post.pipe(switchMap(() => show)); 229 | } 230 | 231 | // check if the given URL is valid (can be saved in Pinboard) 232 | isValidUrl(url: string): boolean { 233 | return url && /:\/\//.test(url); 234 | } 235 | 236 | } 237 | -------------------------------------------------------------------------------- /src/app/pinpage/pinpage.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Loading page from Pinboard...

4 |

Save page to Pinboard

5 |

Update page in Pinboard

6 | 7 |
8 | 11 | 14 | 17 | 20 | 23 | 26 | 29 | 32 | 35 | 38 | 41 |
42 | 43 |
44 |
45 | 46 | 47 | This page has already been added as a bookmark to Pinboard. 48 | 49 | This page has already been added as a bookmark to Pinboard {{date | ago}}. 50 | 51 | This page has not yet been added as a bookmark to Pinboard. 52 | 53 |
54 |
55 | 56 | 57 |
58 |
59 | 60 | 62 |
63 |
64 | 65 | 68 |
69 |
70 |
    71 |
  • {{tag}}
  • 73 |
74 |
75 |
76 | 77 | 80 |
81 |
82 | 83 | 84 | {{tag}} 85 | Add all 86 | 87 |
88 |
89 | 90 | 91 | {{tag}} 92 | Add all 93 | 94 |
95 |
96 | 97 | 98 | {{tag}} 99 | Add all 100 | 101 |
102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 | 111 | 114 |
115 |
116 | 117 |

{{error}}

118 | 119 |
120 |
121 | 122 | 123 | 124 |
125 |
126 | 127 |
-------------------------------------------------------------------------------- /src/app/pinpage/pinpage.component.scss: -------------------------------------------------------------------------------- 1 | .popup { 2 | width: 720px; 3 | } 4 | 5 | .error { 6 | color: var(--color-error); 7 | text-align: center; 8 | font-weight: bold; 9 | } 10 | 11 | div.buttons { 12 | display: flex; 13 | justify-content: space-between; 14 | margin-top: 8px; 15 | margin-bottom: 16px; 16 | 17 | button { 18 | font-size: 11px; 19 | max-width: 70px; 20 | } 21 | } 22 | 23 | form { 24 | div { 25 | display: flex; 26 | align-items: baseline; 27 | margin-top: 8px; 28 | 29 | label { 30 | flex: 0 0 100px; 31 | margin-right: 8px; 32 | text-align: right; 33 | font-weight: bold; 34 | } 35 | 36 | input[type="text"], 37 | input[type="url"], 38 | textarea { 39 | flex: 1 0 70px; 40 | } 41 | } 42 | 43 | div.info { 44 | margin-bottom: 8px; 45 | } 46 | 47 | div.submit { 48 | margin-top: 16px; 49 | display: flex; 50 | align-items: center; 51 | 52 | label { 53 | text-align: left; 54 | width: auto; 55 | 56 | + button { 57 | margin-left: auto; 58 | } 59 | } 60 | 61 | button { 62 | margin-left: 8px; 63 | width: 120px; 64 | font-size: 14px; 65 | padding: 8px; 66 | align-self: stretch; 67 | } 68 | } 69 | 70 | div.completions { 71 | display: block; 72 | position: relative; 73 | margin: 0; 74 | padding: 0; 75 | height: 0; 76 | } 77 | } 78 | 79 | span.suggested { 80 | display: flex; 81 | align-items: baseline; 82 | flex-wrap: wrap; 83 | a { 84 | color: hsl(var(--hue), 40%, 33%); 85 | margin-right: 8px; 86 | text-decoration: none; 87 | 88 | &.added { 89 | color: hsl(var(--hue), 5%, 60%); 90 | } 91 | 92 | &:last-child { 93 | font-weight: bold; 94 | } 95 | 96 | &:nth-last-child(2) { 97 | margin-right: 12px; 98 | } 99 | } 100 | } 101 | 102 | input[type="checkbox"] { 103 | flex: 0 0 30px; 104 | width: 30px; 105 | height: 30px; 106 | margin-right: 12px; 107 | margin-bottom: 4px; 108 | 109 | &::before { 110 | font-size: 28px; 111 | margin-left: 3px; 112 | } 113 | } 114 | 115 | .completions { 116 | ul { 117 | position: absolute; 118 | list-style-type: none; 119 | bottom: -2px; 120 | left: 110px; 121 | width: 300px; 122 | max-height: 250px; 123 | overflow-y: scroll; 124 | margin: 0; 125 | padding: 0; 126 | background-color: var(--color-bg-input); 127 | border: 1px solid hsl(var(--hue-2), 15%, 67%); 128 | box-shadow: 4px 4px 10px hsl(var(--hue), 15%, 67%); 129 | color: hsl(var(--hue), 40%, 33%); 130 | z-index: 9; 131 | } 132 | 133 | li { 134 | padding: 4px; 135 | } 136 | 137 | li.selected { 138 | background-color: hsl(var(--hue), 33%, 40%); 139 | color: var(--color-bg-input); 140 | } 141 | } 142 | 143 | main.dark { 144 | span.suggested { 145 | a { 146 | color: hsl(var(--hue), 60%, 67%); 147 | 148 | &.added { 149 | color: hsl(var(--hue), 5%, 40%); 150 | } 151 | } 152 | } 153 | 154 | .completions { 155 | ul { 156 | border: 1px solid hsl(var(--hue-2), 15%, 25%); 157 | box-shadow: 4px 4px 10px hsl(var(--hue), 15%, 3%); 158 | color: hsl(var(--hue), 33%, 86%); 159 | } 160 | 161 | li.selected { 162 | background-color: hsl(var(--hue), 40%, 80%); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/app/pinpage/pinpage.component.ts: -------------------------------------------------------------------------------- 1 | // this component is the save bookmark dialog displayed in the popup 2 | 3 | import { Component, ElementRef, OnInit, OnDestroy } from '@angular/core'; 4 | import { NgForm } from '@angular/forms'; 5 | import { Router } from '@angular/router'; 6 | 7 | import { Subscription, Subject, timer } from 'rxjs'; 8 | import { debounceTime, distinctUntilChanged, finalize } from 'rxjs/operators'; 9 | 10 | import { IconService } from '../icon.service'; 11 | import { PinboardService, pinboardPage } from '../pinboard.service'; 12 | import { Options, StorageService } from '../storage.service'; 13 | 14 | const debounceDueTime = 250; // timeout in ms for reacting to changes 15 | const maxCompletions = 9; // maximum number of suggested completions 16 | 17 | export interface Post { 18 | url: string; 19 | title: string; 20 | description: string; 21 | tags: string; 22 | unshared: boolean; 23 | toread: boolean; 24 | noreplace: boolean; 25 | } 26 | 27 | interface Content { 28 | url: string; 29 | title: string; 30 | description: string; 31 | keywords: string[]; 32 | } 33 | 34 | interface RawContent { 35 | url: string; 36 | title: string; 37 | selection: string; 38 | description: string; 39 | keywords: string; 40 | } 41 | 42 | 43 | // Pin page form 44 | // TODO: This class is too big, should be refactored. 45 | // At least the tag handling should go into sub component(s). 46 | 47 | @Component({ 48 | selector: 'app-popup', 49 | templateUrl: './pinpage.component.html', 50 | styleUrls: ['./pinpage.component.scss'] 51 | }) 52 | export class PinPageComponent implements OnInit, OnDestroy { 53 | 54 | url: string; 55 | title: string; 56 | description: string; // description 57 | tags: string; // current tags 58 | savedTags: string; // tags already saved for this URL 59 | allTags: { [tag: string]: number }; // all of our tags with frequency 60 | suggested: string[]; // recommended tags from our own 61 | popular: string[]; // other popular tags 62 | keywords: string[]; // keywords taken from the page 63 | completions: string[]; // tag completions 64 | tagsFocus: boolean; // whether the tags field has focus 65 | tagSelected: number; // index of the selected tag 66 | unshared: boolean; 67 | toread: boolean; 68 | ready: boolean; 69 | update: boolean; 70 | date: string; 71 | error: boolean; 72 | retry: boolean; 73 | options: Options; 74 | 75 | theme = 'light'; // color scheme of the page 76 | 77 | private tagsSubject = new Subject(); 78 | private tagsSubscription: Subscription; 79 | 80 | constructor( 81 | private pinboard: PinboardService, 82 | private storage: StorageService, 83 | private icon: IconService, 84 | private router: Router, 85 | private eref: ElementRef) { } 86 | 87 | ngOnInit() { 88 | this.ready = this.update = this.error = this.retry = false; 89 | this.storage.getOptions().subscribe(options => { 90 | this.options = options; 91 | this.setTheme(); 92 | const getContent = options.meta || options.selection ? 93 | browser.tabs.executeScript(null, { file: '/js/content.js' } 94 | ).then((content: Array) => 95 | this.processContent(content[0])).catch(() => 96 | this.getContent()) : this.getContent(); 97 | getContent.then( 98 | content => this.setContent(content), 99 | error => this.logError( 100 | 'Can only pin normal web pages.', error.toString())); 101 | }); 102 | this.tagsFocus = false; 103 | this.tagsSubscription = this.tagsSubject.pipe( 104 | debounceTime(debounceDueTime), distinctUntilChanged() 105 | ).subscribe(value => this.tagsChanged(value)); 106 | } 107 | 108 | ngOnDestroy() { 109 | this.tagsSubscription.unsubscribe(); 110 | } 111 | 112 | setTheme() { 113 | this.theme = ( 114 | this.options.dark === true || 115 | this.options.dark !== false && 116 | window.matchMedia('(prefers-color-scheme: dark)').matches) ? 117 | 'dark' : 'light'; 118 | } 119 | 120 | // process the data gathered by the content script 121 | processContent(content: RawContent): Content { 122 | let { url, title } = content; 123 | url = url || null; 124 | title = title ? (title.length > 255 ? // trim title 125 | title.slice(0, 254) + '\u2026' : title) : null; 126 | const options = this.options; 127 | let description = options.selection ? content.selection : null; 128 | if (!description && options.meta) { 129 | description = content.description; 130 | } 131 | description = description ? (description.length > 3200 ? 132 | // trim description (actual max. size seems to be 3798 chars) 133 | description.slice(0, 3199) + '\u2026' : description) : null; 134 | let keywords: string[] = []; 135 | if (options.meta && content.keywords) { 136 | for (let word of content.keywords.split(',')) { 137 | word = word.replace(/\s+/, '').slice( 138 | 0, 255).toLowerCase(); 139 | if (word && !keywords.includes(word)) { 140 | keywords.push(word); 141 | if (keywords.length >= 100) { 142 | break; 143 | } 144 | } 145 | } 146 | } 147 | keywords = keywords.length ? keywords.slice(0, 6400) : null; 148 | return { url, title, description, keywords }; 149 | } 150 | 151 | // get url and title of content (used if content script cannot run) 152 | getContent(): Promise { 153 | return browser.tabs.query( 154 | { active: true, currentWindow: true }).then( 155 | tabs => tabs[0]).then(tab => ({ 156 | url: tab.url, title: tab.title, 157 | description: null, keywords: null 158 | })); 159 | } 160 | 161 | // store info on current content in the form inputs 162 | setContent(content: Content): void { 163 | if (content && content.url && this.pinboard.isValidUrl(content.url)) { 164 | this.url = content.url; 165 | this.title = content.title; 166 | this.description = content.description; 167 | if (this.description && this.options.blockquote) { 168 | this.description = '
' + 169 | this.description.slice(0, 3200 - 25) + '
'; 170 | } 171 | this.keywords = content.keywords; 172 | this.tags = null; 173 | this.unshared = this.options.unshared; 174 | this.toread = this.options.toread; 175 | this.retry = true; 176 | this.suggested = this.popular = null; 177 | // query both page data and suggested tags 178 | this.pinboard.getAndSuggest(this.url).subscribe( 179 | data => this.setData(data), 180 | error => this.logError( 181 | 'Cannot check this page on Pinboard.', error.toString())); 182 | } else { 183 | this.logError('Can only pin normal web pages.', 184 | 'Cannot get the URL of the page'); 185 | } 186 | } 187 | 188 | // receive page data and suggested tags from parallel queries 189 | setData(data: any): void { 190 | if (data.posts && data.posts.length) { 191 | this.date = data?.date; 192 | const post = data.posts[0]; 193 | this.url = post.href; 194 | this.title = post.description; 195 | this.description = post.extended; 196 | this.tags = post.tags; 197 | this.unshared = post.shared !== 'yes'; 198 | this.toread = post.toread === 'yes'; 199 | this.update = true; 200 | // set browser icon to saved state 201 | browser.tabs.query({ url: this.url }).then(tabs => { 202 | for (const tab of tabs) { 203 | this.icon.setIcon(tab.id, true); 204 | } 205 | }, 206 | error => console.error(error.toString())); 207 | } 208 | // Note: "popular" and "recommended" are interchanged in Pinboard 209 | if (data.popular) { 210 | this.suggested = data.popular; 211 | } 212 | if (this.options.popular && data.recommended) { 213 | this.popular = data.recommended; 214 | } 215 | this.pinboard.cachedTags().subscribe(tags => { 216 | this.allTags = tags; 217 | if (this.tags) { 218 | this.tags.trim(); 219 | this.savedTags = this.tags; 220 | this.tags += ' '; 221 | } else { 222 | this.savedTags = null; 223 | } 224 | this.completions = null; 225 | this.setReady(); 226 | }); 227 | } 228 | 229 | // set form as ready for input 230 | setReady(): void { 231 | this.ready = true; 232 | // wait until inputs have been enabled, then focus 233 | timer(0).subscribe(() => { 234 | const focus = this.url ? (this.title ? ( 235 | this.tags && !this.description ? 236 | 'description' : 'tags') : 'title') : 'url'; 237 | this.eref.nativeElement.querySelector('#' + focus).focus(); 238 | }); 239 | } 240 | 241 | // check whether the given tags have already been added 242 | hasTags(tags: string | string[]): boolean { 243 | if (!this.tags) { 244 | return false; 245 | } 246 | if (!Array.isArray(tags)) { 247 | tags = [tags as string]; 248 | } 249 | const allTags = this.tags.split(' ').filter(tag => !!tag); 250 | return (tags as string[]).every(tag => allTags.includes(tag)); 251 | } 252 | 253 | // add the given tags if they have not already been added, otherwise remove 254 | addTags(tags: string | string[]): void { 255 | if (!Array.isArray(tags)) { 256 | tags = [tags as string]; 257 | } 258 | let allTags = (this.tags || '').split(' ').filter(tag => !!tag); 259 | const newTags = (tags as string[]).filter(tag => !allTags.includes(tag)); 260 | if (newTags.length) { // some tags are new 261 | allTags.push(...newTags); // add these tags 262 | } else { // all tags have already been added, remove these tags again 263 | allTags = allTags.filter(tag => !(tags as string[]).includes(tag)); 264 | } 265 | this.tags = allTags.join(' '); 266 | } 267 | 268 | // this method is called when keys have been pressed down in the tabs field 269 | tagsKeyDown(event: any): boolean { 270 | if (!this.ready || !this.tagsFocus || !this.completions) { 271 | return true; 272 | } 273 | // Firefox reacts to some of our control keys as well, so to prevent this 274 | // from happening, we have to listen here before the key has been pressed 275 | let control = true; 276 | switch (event.code) { 277 | case 'Home': 278 | this.tagSelected = 0; 279 | break; 280 | case 'End': 281 | this.tagSelected = this.completions.length - 1; 282 | break; 283 | case 'ArrowDown': 284 | if (this.tagSelected < this.completions.length - 1) { 285 | ++this.tagSelected; 286 | } 287 | break; 288 | case 'ArrowUp': 289 | if (this.tagSelected > 0) { 290 | --this.tagSelected; 291 | } 292 | break; 293 | case 'Enter': 294 | case 'Tab': 295 | case 'ArrowRight': 296 | const tag = this.completions[this.tagSelected]; 297 | let value = event.target.value; 298 | const words = value.split(' '); 299 | if (words.length) { 300 | words.pop(); 301 | } 302 | if (!words.includes(tag)) { 303 | words.push(tag); 304 | value = words.join(' ') + ' '; 305 | this.tagsChanged(value); 306 | this.tags = value; 307 | } 308 | break; 309 | default: 310 | control = false; 311 | } 312 | return !control; 313 | } 314 | 315 | // this method is called when keys have been released in the tabs field 316 | tagsKeyUp(event: any): boolean { 317 | // the field value is changed after the key has been pressed, 318 | // so this is the right moment for checking for value changes 319 | if (this.ready && this.tagsFocus) { 320 | this.tagsSubject.next(event.target.value); 321 | } 322 | return true; 323 | } 324 | 325 | // this method is called with debounce when tags have changed 326 | // it must then determine the list of tag completions 327 | tagsChanged(tags: string): void { 328 | const words = tags.replace(',', ' ').split(' '); 329 | let word = words.length ? words.pop() : null; 330 | const allTags = this.allTags; 331 | const matches: [string, number][] = []; 332 | const alpha = this.options.alpha; 333 | if (word) { 334 | word = word.toLowerCase(); 335 | for (const tag in allTags) { 336 | if (allTags.hasOwnProperty(tag)) { 337 | if (tag.toLowerCase().startsWith(word) && !words.includes(tag)) { 338 | matches.push([tag, alpha ? 0 : allTags[tag]]); 339 | } 340 | } 341 | } 342 | } 343 | // sort matching tags by decreasing frequency 344 | matches.sort((a: [string, number], b: [string, number]) => 345 | b[1] - a[1] || a[0].localeCompare(b[0])); 346 | matches.splice(maxCompletions); 347 | const completions: string[] = matches.map(a => a[0]).reverse(); 348 | if (completions.length) { 349 | const oldCompletions = this.completions; 350 | if (!oldCompletions || completions.length !== oldCompletions.length || 351 | completions.some((tag, i) => 352 | completions[i] !== oldCompletions[i])) { 353 | this.completions = completions; 354 | this.tagSelected = completions.length - 1; 355 | } 356 | } else { 357 | this.completions = null; 358 | } 359 | } 360 | 361 | // this method is called when a tag completion was clicked 362 | selectCompletion(tag: string): boolean { 363 | let value = this.tags || ''; 364 | const words = value.split(' '); 365 | if (words.length) { 366 | words.pop(); 367 | } 368 | if (!words.includes(tag)) { 369 | words.push(tag); 370 | value = words.join(' ') + ' '; 371 | this.tagsChanged(value); 372 | this.tags = value; 373 | } 374 | return false; 375 | } 376 | 377 | // delete the current bookmark 378 | remove(): boolean { 379 | if (this.ready && this.update && this.url) { 380 | this.pinboard.delete(this.url).subscribe( 381 | () => { 382 | // update the tags in the cache 383 | const savedTags = this.savedTags ? this.savedTags.split(' ') : []; 384 | this.pinboard.updateTagCache([], savedTags).pipe(finalize( 385 | // set the browser icon to unsaved state 386 | () => browser.tabs.query({ url: this.url }).then(tabs => { 387 | for (const tab of tabs) { 388 | this.icon.setIcon(tab.id, false); 389 | } 390 | this.cancel(); 391 | }, error => { 392 | console.error(error.toString()); 393 | this.cancel(); 394 | }))).subscribe(); 395 | }, 396 | error => { 397 | this.logError('Sorry, could not remove this page from Pinboard', 398 | error.toString()); 399 | }); 400 | } 401 | return false; 402 | } 403 | 404 | // reset error message 405 | reset(): boolean { 406 | this.error = null; 407 | return false; 408 | } 409 | 410 | // submit form 411 | submit(form: NgForm): boolean { 412 | if (form.valid) { 413 | this.save(form.value); 414 | } 415 | return false; 416 | } 417 | 418 | // save page to Pinboard 419 | save(value: Post): void { 420 | value.url = (value.url || '').trim(); 421 | value.title = (value.title || '').trim(); 422 | if (!value.url || !value.title) { 423 | return; 424 | } 425 | value.description = (value.description || '').trim() || null; 426 | // clean up tags, maximum of 100 tags with 255 chars each 427 | const tags = value.tags ? value.tags.split(' ').filter( 428 | tag => !!tag).slice(0, 100).map(tag => tag.slice(0, 255)) : []; 429 | value.tags = tags.join(' '); 430 | const savedTags = this.savedTags ? this.savedTags.split(' ') : []; 431 | this.pinboard.save(value).subscribe( 432 | error => { 433 | if (error) { 434 | this.logError('Sorry, could not save this page to Pinboard', 435 | error); 436 | } else { 437 | // update the tags in the cache 438 | this.pinboard.updateTagCache(tags, savedTags).pipe(finalize( 439 | // set the browser icon to saved state 440 | () => browser.tabs.query({ url: this.url }).then(tabs => { 441 | for (const tab of tabs) { 442 | this.icon.setIcon(tab.id, true); 443 | } 444 | this.cancel(); 445 | }, error => { 446 | console.error(error.toString()); 447 | this.cancel(); 448 | }))).subscribe(); 449 | } 450 | }, 451 | error => { 452 | this.logError('Sorry, could not save this page to Pinboard', 453 | error.toString()); 454 | }); 455 | } 456 | 457 | // save current tabs as tab set to Pinboard 458 | saveTabs(): void { 459 | browser.tabs.query({ windowType: 'normal', url: '*://*/*' }).then( 460 | tabs => { 461 | const wTabs = {}; 462 | for (const tab of tabs) { 463 | const wId = tab.windowId; 464 | if (!wTabs[wId]) { 465 | wTabs[wId] = {}; 466 | } 467 | wTabs[wId][tab.index] = { title: tab.title, url: tab.url }; 468 | } 469 | const windows = Object.keys(wTabs).map( 470 | wId => Object.keys(wTabs[wId]).map( 471 | index => wTabs[wId][index])); 472 | if (windows.length) { 473 | const data = { 474 | browser: 'ffox', windows: windows, 475 | }; 476 | this.pinboard.saveTabs(data).subscribe(() => { 477 | this.cancel(); 478 | }, error => { 479 | this.logError( 480 | 'Sorry, could not save this tab set to Pinboard.', 481 | error.toString()); 482 | }); 483 | } 484 | }); 485 | } 486 | 487 | // navigate to options 488 | settings(): void { 489 | // store a note that we are showing on a popup page 490 | this.storage.setInfo('options.page', 'popup'); 491 | this.router.navigate(['/options']); 492 | } 493 | 494 | // log out from Pinboard 495 | logOut(): void { 496 | this.pinboard.forgetToken().subscribe( 497 | () => this.router.navigate(['/login'])); 498 | } 499 | 500 | // show error message and log it on the console 501 | logError(errmsg, logmsg): void { 502 | if (errmsg) { 503 | console.error(logmsg || errmsg); 504 | } 505 | this.error = errmsg; 506 | } 507 | 508 | pinboardLink(page): boolean { 509 | if (page && page.indexOf('~') >= 0) { 510 | this.pinboard.userName.subscribe( 511 | name => this.pinboardLink(page.replace('~', 'u:' + name))); 512 | } else { 513 | let url = pinboardPage; 514 | if (page) { 515 | url += page; 516 | } 517 | browser.tabs.create({ url: url }); 518 | this.cancel(); 519 | } 520 | return false; 521 | } 522 | 523 | // close the whole popup 524 | cancel(): void { 525 | window.close(); 526 | } 527 | 528 | } 529 | -------------------------------------------------------------------------------- /src/app/storage.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | import { Observable, from as ObservableFrom } from 'rxjs'; 4 | import { map } from 'rxjs/operators'; 5 | 6 | export interface Options { 7 | ping: boolean; // check whether pages are bookmarked 8 | unshared: boolean; // add as private by default 9 | toread: boolean; // add as to read by default 10 | meta: boolean; // parse meta elements 11 | selection: boolean; // use selected text 12 | blockquote: boolean; // wrap as block quote 13 | alpha: boolean; // sort alphabetically 14 | popular: boolean; // show popular tags 15 | menu: boolean; // add entry to context menu 16 | dark: boolean; // use dark mode 17 | } 18 | 19 | const defaultOptions: Options = { 20 | ping: false, 21 | unshared: false, 22 | toread: false, 23 | meta: true, 24 | selection: true, 25 | blockquote: false, 26 | alpha: false, 27 | popular: true, 28 | menu: false, 29 | dark: null, 30 | }; 31 | 32 | 33 | // Wrapper around the browser local storage for the web extension, 34 | // using Observables instead of Promises for flexibility and consistency. 35 | 36 | @Injectable() 37 | export class StorageService { 38 | 39 | private storage = browser.storage.local; // needs "storage" permission 40 | 41 | private readonly info: Object; 42 | 43 | constructor() { 44 | this.info = {}; // for various info shared via this service 45 | } 46 | 47 | // get keys from local storage as an Observable 48 | // when only one key is requested, only its value is returned 49 | get(keys: string | string[] | null): Observable { 50 | return ObservableFrom(this.storage.get(keys)).pipe( 51 | map(res => typeof keys === 'string' ? res[keys] : res)); 52 | } 53 | 54 | // set keys in local storage as an Observable 55 | set(keys: any): Observable { 56 | return ObservableFrom(this.storage.set(keys)); 57 | } 58 | 59 | // remove keys in local storage as an Observable 60 | remove(keys: string | string[]): Observable { 61 | return ObservableFrom(this.storage.remove(keys)); 62 | } 63 | 64 | // retrieve options from local storage 65 | getOptions(): Observable { 66 | return this.get('options').pipe( 67 | map(options => { 68 | const opts = {}; 69 | Object.keys(defaultOptions).forEach( 70 | key => { 71 | const val = options ? options[key] : undefined; 72 | opts[key] = val === undefined ? defaultOptions[key] : val; 73 | }); 74 | return opts as Options; 75 | })); 76 | } 77 | 78 | // store options in local storage 79 | setOptions(options: Options): Observable { 80 | return this.set({ options: options }); 81 | } 82 | 83 | // set a volatile info for users of this service 84 | setInfo(name: string, value: any): void { 85 | this.info[name] = value; 86 | } 87 | 88 | // get a volatile info that was previously set 89 | getInfo(name: string): any { 90 | return this.info[name]; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /src/img/pinboard_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_128.png -------------------------------------------------------------------------------- /src/img/pinboard_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_16.png -------------------------------------------------------------------------------- /src/img/pinboard_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_24.png -------------------------------------------------------------------------------- /src/img/pinboard_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_256.png -------------------------------------------------------------------------------- /src/img/pinboard_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_32.png -------------------------------------------------------------------------------- /src/img/pinboard_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_48.png -------------------------------------------------------------------------------- /src/img/pinboard_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_64.png -------------------------------------------------------------------------------- /src/img/pinboard_96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_96.png -------------------------------------------------------------------------------- /src/img/pinboard_idle_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_idle_128.png -------------------------------------------------------------------------------- /src/img/pinboard_idle_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_idle_16.png -------------------------------------------------------------------------------- /src/img/pinboard_idle_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_idle_24.png -------------------------------------------------------------------------------- /src/img/pinboard_idle_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_idle_256.png -------------------------------------------------------------------------------- /src/img/pinboard_idle_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_idle_32.png -------------------------------------------------------------------------------- /src/img/pinboard_idle_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_idle_48.png -------------------------------------------------------------------------------- /src/img/pinboard_idle_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_idle_64.png -------------------------------------------------------------------------------- /src/img/pinboard_idle_96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cito/Pinboard-Pin/13efee4147e3983e53c9b6dca641a2550bc54892/src/img/pinboard_idle_96.png -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PinboardPin 6 | 7 | 8 | 9 | 10 | Loading... 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/js/content.js: -------------------------------------------------------------------------------- 1 | (function getContent() { 2 | const url = document.location.href; 3 | if (!url || !/^https?:\/\//.test(url)) return null; 4 | let title = document.querySelector('title'); 5 | if (title) title = title.innerText.trim(); 6 | const selection = window.getSelection().toString().trim(); 7 | let meta = document.querySelector('meta[name="description"]'); 8 | const description = meta && (meta.getAttribute('content') || '').trim(); 9 | meta = document.querySelector('meta[name="keywords"]'); 10 | const keywords = meta && (meta.getAttribute('content') || '').trim(); 11 | return {url, title, selection, description, keywords}; 12 | })(); 13 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(error => console.error(error)); 13 | -------------------------------------------------------------------------------- /src/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 2, 3 | 4 | "name": "Pinboard Pin", 5 | "version": "0.4.3", 6 | "description": "A modern web extension for pinning pages on Pinboard (pinboard.in) with Firefox.", 7 | "homepage_url": "https://github.com/Cito/Pinboard-Pin", 8 | 9 | "options_ui": { 10 | "page": "/index.html?page=options" 11 | }, 12 | 13 | "icons": { 14 | "16": "/img/pinboard_16.png", 15 | "24": "/img/pinboard_24.png", 16 | "32": "/img/pinboard_32.png", 17 | "48": "/img/pinboard_48.png", 18 | "64": "/img/pinboard_64.png", 19 | "96": "/img/pinboard_96.png", 20 | "128": "/img/pinboard_128.png", 21 | "256": "/img/pinboard_256.png" 22 | }, 23 | 24 | "background": { 25 | "page": "/index.html?page=background" 26 | }, 27 | 28 | "browser_action": { 29 | "default_title": "Pinboard Pin", 30 | "default_icon": { 31 | "16": "/img/pinboard_idle_16.png", 32 | "24": "/img/pinboard_idle_24.png", 33 | "32": "/img/pinboard_idle_32.png", 34 | "48": "/img/pinboard_idle_48.png", 35 | "64": "/img/pinboard_idle_64.png", 36 | "96": "/img/pinboard_idle_96.png", 37 | "128": "/img/pinboard_idle_128.png", 38 | "256": "/img/pinboard_idle_256.png" 39 | }, 40 | "default_popup": "/index.html" 41 | }, 42 | 43 | "commands": { 44 | "_execute_browser_action": { 45 | "suggested_key": { 46 | "default": "Alt+P" 47 | }, 48 | "description": "Save page to Pinboard" 49 | } 50 | }, 51 | 52 | "permissions": ["storage", "tabs", "contextMenus", "*://*/*"] 53 | } 54 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | // This file includes polyfills needed by Angular and is loaded before 2 | // the app. You can add your own extra polyfills to this file. 3 | 4 | // Zone JS is required by Angular itself. 5 | import 'zone.js'; 6 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | body { 4 | font-family: sans-serif; 5 | font-size: 14px; 6 | padding: 0; 7 | margin: 0; 8 | } 9 | 10 | main { 11 | --hue: 220; 12 | --hue-2: 100; 13 | --color-lines: hsl(var(--hue-2), 33%, 40%); 14 | --color-focus: hsl(var(--hue-2), 40%, 67%); 15 | --color-bg: hsl(var(--hue), 5%, 95%); 16 | --color-fg: hsl(var(--hue), 5%, 5%); 17 | --color-bg-input: hsl(var(--hue), 10%, 90%); 18 | --color-fg-input: hsl(var(--hue), 10%, 10%); 19 | --color-error: hsl(0, 67%, 50%); 20 | --color-info: hsl(120, 33%, 37%); 21 | --color-note: hsl(240, 10%, 33%); 22 | 23 | color: var(--color-fg); 24 | background-color: var(--color-bg); 25 | } 26 | 27 | .popup { 28 | padding: 8px; 29 | } 30 | 31 | .popup h1 { 32 | font-size: 24px; 33 | line-height: 36px; 34 | background: url("/img/pinboard_32.png") no-repeat; 35 | padding: 2px 48px; 36 | margin: 0 0 4px; 37 | border-bottom: 1px solid var(--color-lines); 38 | } 39 | 40 | input[type="text"], 41 | input[type="url"], 42 | textarea { 43 | font-family: sans-serif; 44 | font-size: 14px; 45 | padding: 8px; 46 | border-radius: 4px; 47 | border: 1px solid var(--color-lines); 48 | background-color: var(--color-bg-input); 49 | color: var(--color-fg-input); 50 | width: 42em; 51 | } 52 | 53 | button { 54 | border: none; 55 | border-bottom: 2px solid hsl(var(--hue), 20%, 15%); 56 | border-radius: 4px; 57 | background: linear-gradient(to bottom, hsl(var(--hue), 40%, 33%) 0%, hsl(var(--hue), 30%, 25%) 100%); 58 | color: hsl(var(--hue), 25%, 95%); 59 | padding: 6px; 60 | font-weight: 600; 61 | font-size: 12px; 62 | box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.1); 63 | } 64 | 65 | button:hover { 66 | --hue: var(--hue-2); 67 | } 68 | 69 | button[type="submit"] { 70 | border-width: 2px; 71 | } 72 | 73 | button:disabled, 74 | button:disabled:hover { 75 | opacity: 0.4; 76 | } 77 | 78 | input[type="checkbox"], 79 | input[type="radio"] { 80 | -moz-appearance: none; 81 | border-radius: 4px; 82 | border: 1px solid var(--color-lines); 83 | background-color: var(--color-bg-input); 84 | width: 16px; 85 | height: 16px; 86 | 87 | &::before { 88 | content: "\2713"; 89 | text-align: center; 90 | color: var(--color-bg-input); 91 | font-size: 14px; 92 | line-height: 1; 93 | float: left; 94 | margin-left: 1.5px; 95 | } 96 | 97 | &:checked { 98 | background-color: hsl(var(--hue), 40%, 33%); 99 | } 100 | } 101 | 102 | input[type="radio"] { 103 | border-radius: 8px; 104 | 105 | &::before { 106 | content: "\2b24"; 107 | font-size: 12px; 108 | } 109 | } 110 | 111 | input[type="text"], 112 | input[type="url"], 113 | input[type="checkbox"], 114 | input[type="radio"], 115 | textarea, 116 | button { 117 | &:focus { 118 | outline: solid 2px var(--color-focus); 119 | -moz-outline-radius: 6px; 120 | } 121 | } 122 | 123 | input[type="radio"]:focus { 124 | -moz-outline-radius: 9px; 125 | } 126 | 127 | span.error { 128 | color: var(--color-error); 129 | } 130 | 131 | span.info { 132 | color: var(--color-info); 133 | } 134 | 135 | span.note { 136 | color: var(--color-note); 137 | } 138 | 139 | main.dark { 140 | --color-bg: hsl(var(--hue), 25%, 7%); 141 | --color-fg: hsl(var(--hue), 12%, 93%); 142 | --color-bg-input: hsl(var(--hue), 25%, 15%); 143 | --color-fg-input: hsl(var(--hue), 12%, 85%); 144 | --color-focus: hsl(var(--hue-2), 40%, 50%); 145 | --color-error: hsl(0, 75%, 57%); 146 | --color-info: hsl(120, 67%, 40%); 147 | --color-note: hsl(240, 10%, 60%); 148 | 149 | input[type="checkbox"], 150 | input[type="radio"] { 151 | &:checked { 152 | background-color: hsl(var(--hue), 50%, 85%); 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "files": [ 4 | "src/main.ts", 5 | "src/polyfills.ts" 6 | ], 7 | "include": [ 8 | "src/typings.d.ts" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "experimentalDecorators": true, 9 | "typeRoots": [ 10 | "node_modules/@types", 11 | "node_modules/web-ext-types" 12 | ], 13 | "target": "ES2022", 14 | "module": "es2020", 15 | "lib": [ 16 | "es2020", 17 | "dom" 18 | ], 19 | "useDefineForClassFields": false 20 | }, 21 | "angularCompilerOptions": { 22 | "preserveWhitespaces": false, 23 | "strictInjectionParameters": true, 24 | "strictInputAccessModifiers": true, 25 | "strictTemplates": true 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-shadowed-variable": false, 69 | "no-string-literal": false, 70 | "no-string-throw": true, 71 | "no-switch-case-fall-through": true, 72 | "no-trailing-whitespace": true, 73 | "no-unnecessary-initializer": true, 74 | "no-unused-expression": true, 75 | "no-var-keyword": true, 76 | "object-literal-sort-keys": false, 77 | "one-line": [ 78 | true, 79 | "check-open-brace", 80 | "check-catch", 81 | "check-else", 82 | "check-whitespace" 83 | ], 84 | "prefer-const": true, 85 | "quotemark": [ 86 | true, 87 | "single" 88 | ], 89 | "radix": true, 90 | "semicolon": [ 91 | true, 92 | "always" 93 | ], 94 | "triple-equals": [ 95 | true, 96 | "allow-null-check" 97 | ], 98 | "typedef-whitespace": [ 99 | true, 100 | { 101 | "call-signature": "nospace", 102 | "index-signature": "nospace", 103 | "parameter": "nospace", 104 | "property-declaration": "nospace", 105 | "variable-declaration": "nospace" 106 | } 107 | ], 108 | "unified-signatures": true, 109 | "variable-name": false, 110 | "whitespace": [ 111 | true, 112 | "check-branch", 113 | "check-decl", 114 | "check-operator", 115 | "check-separator", 116 | "check-type" 117 | ], 118 | "directive-selector": [ 119 | true, 120 | "attribute", 121 | "app", 122 | "camelCase" 123 | ], 124 | "component-selector": [ 125 | true, 126 | "element", 127 | "app", 128 | "kebab-case" 129 | ], 130 | "no-output-on-prefix": true, 131 | "use-input-property-decorator": true, 132 | "use-output-property-decorator": true, 133 | "use-host-property-decorator": true, 134 | "no-input-rename": true, 135 | "no-output-rename": true, 136 | "use-life-cycle-interface": true, 137 | "use-pipe-transform-interface": true, 138 | "component-class-suffix": true, 139 | "directive-class-suffix": true 140 | } 141 | } 142 | --------------------------------------------------------------------------------