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.

54 lines
2.0 KiB

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. // Helper to deal with the i18n'ing of HTML files.
  17. // jQuery must be present at this point.
  18. window.addEventListener('load', function() {
  19. // http://en.wikipedia.org/wiki/Right-to-left
  20. var rtlLanguages = {
  21. 'ar': true,
  22. 'fa': true,
  23. 'he': true
  24. };
  25. uDom('html').toggleClass('rtl', rtlLanguages.hasOwnProperty(navigator.language));
  26. uDom('html').toggleClass('ltr', rtlLanguages.hasOwnProperty(navigator.language) === false);
  27. var nodeList = document.querySelectorAll('[data-i18n]');
  28. var i = nodeList.length;
  29. var node;
  30. while ( i-- ) {
  31. node = nodeList[i];
  32. node.innerHTML = chrome.i18n.getMessage(node.getAttribute('data-i18n'));
  33. }
  34. // copy text of <h1> if any to document title
  35. node = document.querySelector('h1');
  36. if ( node !== null ) {
  37. document.title = node.textContent;
  38. }
  39. // Tool tips
  40. nodeList = document.querySelectorAll('[data-i18n-tip]');
  41. i = nodeList.length;
  42. while ( i-- ) {
  43. node = nodeList[i];
  44. node.setAttribute('data-tip', chrome.i18n.getMessage(node.getAttribute('data-i18n-tip')));
  45. }
  46. });