| 1 | /** |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License as published by |
| 4 | * the Free Software Foundation; either version 2 of the License, or |
| 5 | * (at your option) any later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License along |
| 13 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 15 | * http://www.gnu.org/copyleft/gpl.html |
| 16 | */ |
| 17 | |
| 18 | class CopyButton { |
| 19 | |
| 20 | static attach() { |
| 21 | // eslint-disable-next-line no-jquery/no-global-selector |
| 22 | $( '.mw-oathauth-recoverycodes-copy-button' ) |
| 23 | .addClass( 'clipboard-api-supported' ) |
| 24 | .on( 'click', ( e ) => { |
| 25 | e.preventDefault(); |
| 26 | // eslint-disable-next-line compat/compat |
| 27 | navigator.clipboard.writeText( mw.config.get( 'oathauth-recoverycodes' ) ).then( () => { |
| 28 | mw.notify( mw.msg( 'oathauth-recoverycodes-copy-success' ), { |
| 29 | type: 'success', |
| 30 | tag: 'recoverycodes' |
| 31 | } ); |
| 32 | } ); |
| 33 | } ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | if ( navigator.clipboard && navigator.clipboard.writeText ) { |
| 38 | // navigator.clipboard() is not supported in Safari 11.1, iOS Safari 11.3-11.4 |
| 39 | $( CopyButton.attach ); |
| 40 | } |