Andreu | 2c6367c | 2019-09-17 23:46:36 +0200 | [diff] [blame^] | 1 | function getUrlParameter(name) { |
| 2 | name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); |
| 3 | var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); |
| 4 | var results = regex.exec(location.search); |
| 5 | return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); |
| 6 | }; |
| 7 | |
| 8 | function b64EncodeUnicode(str) { |
| 9 | // first we use encodeURIComponent to get percent-encoded UTF-8, |
| 10 | // then we convert the percent encodings into raw bytes which |
| 11 | // can be fed into btoa. |
| 12 | return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, |
| 13 | function toSolidBytes(match, p1) { |
| 14 | return String.fromCharCode('0x' + p1); |
| 15 | })); |
| 16 | } |
| 17 | |
| 18 | function b64DecodeUnicode(str) { |
| 19 | // Going backwards: from bytestream, to percent-encoding, to original string. |
| 20 | return decodeURIComponent(atob(str).split('').map(function(c) { |
| 21 | return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); |
| 22 | }).join('')); |
| 23 | } |