| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var customDomainsTextbox; | 5 var customDomainsTextbox; |
| 6 var saveButton; | 6 var saveButton; |
| 7 var cancelButton; | 7 var cancelButton; |
| 8 | 8 |
| 9 function init() { | 9 function init() { |
| 10 customDomainsTextbox = document.getElementById("custom-domain"); | 10 customDomainsTextbox = document.getElementById("custom-domain"); |
| 11 saveButton = document.getElementById("save-button"); | 11 saveButton = document.getElementById("save-button"); |
| 12 cancelButton = document.getElementById("cancel-button"); | 12 cancelButton = document.getElementById("cancel-button"); |
| 13 | 13 |
| 14 customDomainsTextbox.value = localStorage.customDomain || ""; | 14 customDomainsTextbox.value = localStorage.customDomain || ""; |
| 15 markClean(); | 15 markClean(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 function getBackgroundPage(callback) { | 18 function getBackgroundPage(callback) { |
| 19 if (chrome.runtime) { | 19 if (chrome.runtime) { |
| 20 chrome.runtime.getBackgroundPage(callback); | 20 chrome.runtime.getBackgroundPage(callback); |
| 21 } else { | 21 } else { |
| 22 callback(chrome.extension.getBackgroundPage()); | 22 callback(chrome.extension.getBackgroundPage()); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 function save() { | 26 function save() { |
| 27 localStorage.customDomain = customDomainsTextbox.value; | 27 localStorage.customDomain = |
| 28 customDomainsTextbox.value.replace(/^\/?(.*?)\/?$/, '$1'); |
| 28 markClean(); | 29 markClean(); |
| 29 getBackgroundPage(function(backgroundPage) { | 30 getBackgroundPage(function(backgroundPage) { |
| 30 backgroundPage.startRequest({ | 31 backgroundPage.startRequest({ |
| 31 scheduleRequest:false, | 32 scheduleRequest:false, |
| 32 showLoadingAnimation:true | 33 showLoadingAnimation:true |
| 33 }); | 34 }); |
| 34 }); | 35 }); |
| 35 } | 36 } |
| 36 | 37 |
| 37 function markDirty() { | 38 function markDirty() { |
| 38 saveButton.disabled = false; | 39 saveButton.disabled = false; |
| 39 } | 40 } |
| 40 | 41 |
| 41 function markClean() { | 42 function markClean() { |
| 42 saveButton.disabled = true; | 43 saveButton.disabled = true; |
| 43 } | 44 } |
| 44 | 45 |
| 45 document.addEventListener('DOMContentLoaded', function () { | 46 document.addEventListener('DOMContentLoaded', function () { |
| 46 init(); | 47 init(); |
| 47 saveButton.addEventListener('click', save); | 48 saveButton.addEventListener('click', save); |
| 48 cancelButton.addEventListener('click', init); | 49 cancelButton.addEventListener('click', init); |
| 49 customDomainsTextbox.addEventListener('input', markDirty); | 50 customDomainsTextbox.addEventListener('input', markDirty); |
| 50 }); | 51 }); |
| OLD | NEW |