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.

96 lines
2.8 KiB

  1. /*******************************************************************************
  2. µBlock - a Chromium browser extension to block requests.
  3. Copyright (C) 2014 The µBlock authors
  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/uBlock
  15. */
  16. // For background page or non-background pages
  17. /******************************************************************************/
  18. (function() {
  19. 'use strict';
  20. self.vAPI = self.vAPI || {};
  21. /******************************************************************************/
  22. // http://www.w3.org/International/questions/qa-scripts#directions
  23. var setScriptDirection = function(language) {
  24. document.body.setAttribute(
  25. 'dir',
  26. ['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) !== -1 ? 'rtl' : 'ltr'
  27. );
  28. };
  29. /******************************************************************************/
  30. vAPI.download = function(details) {
  31. if ( !details.url ) {
  32. return;
  33. }
  34. var a = document.createElement('a');
  35. if ( 'download' in a ) {
  36. a.href = details.url;
  37. a.setAttribute('download', details.filename || '');
  38. a.dispatchEvent(new MouseEvent('click'));
  39. return;
  40. }
  41. var messager = vAPI.messaging.channel('_download');
  42. messager.send({
  43. what: 'gotoURL',
  44. details: {
  45. url: details.url,
  46. index: -1
  47. }
  48. });
  49. messager.close();
  50. };
  51. /******************************************************************************/
  52. vAPI.getURL = function(path) {
  53. return 'chrome://ublock/content/' + path.replace(/^\/+/, '');
  54. };
  55. vAPI.i18n = (function() {
  56. var stringBundle = Components.classes['@mozilla.org/intl/stringbundle;1']
  57. .getService(Components.interfaces.nsIStringBundleService)
  58. .createBundle('chrome://ublock/locale/messages.properties');
  59. return function(s) {
  60. try {
  61. return stringBundle.GetStringFromName(s);
  62. } catch (ex) {
  63. return s;
  64. }
  65. };
  66. })();
  67. setScriptDirection(navigator.language);
  68. /******************************************************************************/
  69. })();
  70. /******************************************************************************/