You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.9 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. /*******************************************************************************
  2. µMatrix - a Chromium browser extension to black/white list requests.
  3. Copyright (C) 2014 Raymond Hill
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see {http://www.gnu.org/licenses/}.
  14. Home: https://github.com/gorhill/uMatrix
  15. */
  16. /* global vAPI, uDom */
  17. /* jshint multistr: true */
  18. /******************************************************************************/
  19. (function() {
  20. 'use strict';
  21. /******************************************************************************/
  22. var messager = vAPI.messaging.channel('settings.js');
  23. var cachedUserSettings = {};
  24. /******************************************************************************/
  25. function changeUserSettings(name, value) {
  26. messager.send({
  27. what: 'userSettings',
  28. name: name,
  29. value: value
  30. });
  31. }
  32. /******************************************************************************/
  33. function prepareToDie() {
  34. }
  35. /******************************************************************************/
  36. var installEventHandlers = function() {
  37. // `data-range` allows to add/remove bool properties without
  38. // changing code.
  39. uDom('input[data-range="bool"]').on('change', function() {
  40. changeUserSettings(this.id, this.checked);
  41. });
  42. uDom('input[name="displayTextSize"]').on('change', function(){
  43. changeUserSettings('displayTextSize', this.value);
  44. });
  45. // https://github.com/gorhill/httpswitchboard/issues/197
  46. uDom(window).on('beforeunload', prepareToDie);
  47. };
  48. /******************************************************************************/
  49. uDom.onLoad(function() {
  50. var onUserSettingsReceived = function(userSettings) {
  51. // Cache copy
  52. cachedUserSettings = userSettings;
  53. // `data-range` allows to add/remove bool properties without
  54. // changing code.
  55. uDom('input[data-range="bool"]').forEach(function(elem) {
  56. elem.prop('checked', userSettings[elem.attr('id')] === true);
  57. });
  58. uDom('input[name="displayTextSize"]').forEach(function(elem) {
  59. elem.prop('checked', elem.val() === userSettings.displayTextSize);
  60. });
  61. installEventHandlers();
  62. };
  63. messager.send({ what: 'getUserSettings' }, onUserSettingsReceived);
  64. });
  65. /******************************************************************************/
  66. })();