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.

104 lines
3.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. /*******************************************************************************
  2. uMatrix - a browser extension to block requests.
  3. Copyright (C) 2014-2017 The uMatrix/uBlock Origin 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/uMatrix
  15. */
  16. // For background page or non-background pages
  17. 'use strict';
  18. /******************************************************************************/
  19. /******************************************************************************/
  20. (function(self) {
  21. /******************************************************************************/
  22. // https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10
  23. if ( self.vAPI === undefined || self.vAPI.uMatrix !== true ) {
  24. self.vAPI = { uMatrix: true };
  25. }
  26. var vAPI = self.vAPI;
  27. var chrome = self.chrome;
  28. /******************************************************************************/
  29. // http://www.w3.org/International/questions/qa-scripts#directions
  30. var setScriptDirection = function(language) {
  31. document.body.setAttribute(
  32. 'dir',
  33. ['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) !== -1 ? 'rtl' : 'ltr'
  34. );
  35. };
  36. /******************************************************************************/
  37. vAPI.download = function(details) {
  38. if ( !details.url ) {
  39. return;
  40. }
  41. var a = document.createElement('a');
  42. a.href = details.url;
  43. a.setAttribute('download', details.filename || '');
  44. a.dispatchEvent(new MouseEvent('click'));
  45. };
  46. /******************************************************************************/
  47. vAPI.insertHTML = function(node, html) {
  48. node.innerHTML = html;
  49. };
  50. /******************************************************************************/
  51. vAPI.getURL = chrome.runtime.getURL;
  52. /******************************************************************************/
  53. vAPI.i18n = chrome.i18n.getMessage;
  54. setScriptDirection(vAPI.i18n('@@ui_locale'));
  55. /******************************************************************************/
  56. vAPI.closePopup = function() {
  57. window.open('','_self').close();
  58. };
  59. /******************************************************************************/
  60. // A localStorage-like object which should be accessible from the
  61. // background page or auxiliary pages.
  62. // This storage is optional, but it is nice to have, for a more polished user
  63. // experience.
  64. vAPI.localStorage = self.localStorage;
  65. /******************************************************************************/
  66. vAPI.setTimeout = vAPI.setTimeout || window.setTimeout.bind(window);
  67. /******************************************************************************/
  68. })(this);
  69. /******************************************************************************/