prefs.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const { on } = require("../system/events");
  6. const core = require("./core");
  7. const { id: jetpackId} = require('../self');
  8. const OPTIONS_DISPLAYED = "addon-options-displayed";
  9. function onOptionsDisplayed({ subject: document, data: addonId }) {
  10. if (addonId !== jetpackId)
  11. return;
  12. let query = 'setting[data-jetpack-id="' + jetpackId + '"][pref-name], ' +
  13. 'button[data-jetpack-id="' + jetpackId + '"][pref-name]';
  14. let nodes = document.querySelectorAll(query);
  15. for (let node of nodes) {
  16. let name = node.getAttribute("pref-name");
  17. if (node.tagName == "setting") {
  18. let desc = core.get(name + "_description");
  19. if (desc)
  20. node.setAttribute("desc", desc);
  21. let title = core.get(name + "_title");
  22. if (title)
  23. node.setAttribute("title", title);
  24. for (let item of node.querySelectorAll("menuitem, radio")) {
  25. let key = name + "_options." + item.getAttribute("label");
  26. let label = core.get(key);
  27. if (label)
  28. item.setAttribute("label", label);
  29. }
  30. }
  31. else if (node.tagName == "button") {
  32. let label = core.get(name + "_label");
  33. if (label)
  34. node.setAttribute("label", label);
  35. }
  36. }
  37. }
  38. on(OPTIONS_DISPLAYED, onOptionsDisplayed);