options.js 1.6 KB

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