| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | (function() { |
| 2 | var Options; |
| 3 | |
| 4 | exports.Options = Options = (function() { |
| 5 | function Options() { |
| 6 | this.https = false; |
| 7 | this.host = null; |
| 8 | this.port = 35729; |
| 9 | this.snipver = null; |
| 10 | this.ext = null; |
| 11 | this.extver = null; |
| 12 | this.mindelay = 1000; |
| 13 | this.maxdelay = 60000; |
| 14 | this.handshake_timeout = 5000; |
| 15 | } |
| 16 | |
| 17 | Options.prototype.set = function(name, value) { |
| 18 | if (typeof value === 'undefined') { |
| 19 | return; |
| 20 | } |
| 21 | if (!isNaN(+value)) { |
| 22 | value = +value; |
| 23 | } |
| 24 | return this[name] = value; |
| 25 | }; |
| 26 | |
| 27 | return Options; |
| 28 | |
| 29 | })(); |
| 30 | |
| 31 | Options.extract = function(document) { |
| 32 | var element, i, j, keyAndValue, len, len1, m, mm, options, pair, ref, ref1, src; |
| 33 | ref = document.getElementsByTagName('script'); |
| 34 | for (i = 0, len = ref.length; i < len; i++) { |
| 35 | element = ref[i]; |
| 36 | if ((src = element.src) && (m = src.match(/^[^:]+:\/\/(.*)\/z?livereload\.js(?:\?(.*))?$/))) { |
| 37 | options = new Options(); |
| 38 | options.https = src.indexOf("https") === 0; |
| 39 | if (mm = m[1].match(/^([^\/:]+)(?::(\d+))?(\/+.*)?$/)) { |
| 40 | options.host = mm[1]; |
| 41 | if (mm[2]) { |
| 42 | options.port = parseInt(mm[2], 10); |
| 43 | } |
| 44 | } |
| 45 | if (m[2]) { |
| 46 | ref1 = m[2].split('&'); |
| 47 | for (j = 0, len1 = ref1.length; j < len1; j++) { |
| 48 | pair = ref1[j]; |
| 49 | if ((keyAndValue = pair.split('=')).length > 1) { |
| 50 | options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('=')); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | return options; |
| 55 | } |
| 56 | } |
| 57 | return null; |
| 58 | }; |
| 59 | |
| 60 | }).call(this); |