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.

101 lines
2.9 KiB

10 years ago
10 years ago
  1. /*******************************************************************************
  2. µBlock - a 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. /* global self */
  18. /******************************************************************************/
  19. /******************************************************************************/
  20. (function() {
  21. 'use strict';
  22. self.vAPI = self.vAPI || {};
  23. var chrome = self.chrome;
  24. var vAPI = self.vAPI;
  25. /******************************************************************************/
  26. // http://www.w3.org/International/questions/qa-scripts#directions
  27. var setScriptDirection = function(language) {
  28. document.body.setAttribute(
  29. 'dir',
  30. ['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) !== -1 ? 'rtl' : 'ltr'
  31. );
  32. };
  33. /******************************************************************************/
  34. vAPI.download = function(details) {
  35. if ( !details.url ) {
  36. return;
  37. }
  38. var a = document.createElement('a');
  39. if ( 'download' in a ) {
  40. a.href = details.url;
  41. a.setAttribute('download', details.filename || '');
  42. a.dispatchEvent(new MouseEvent('click'));
  43. return;
  44. }
  45. var messager = vAPI.messaging.channel('_download');
  46. messager.send({
  47. what: 'gotoURL',
  48. details: {
  49. url: details.url,
  50. index: -1
  51. }
  52. });
  53. messager.close();
  54. };
  55. /******************************************************************************/
  56. vAPI.insertHTML = function(node, html) {
  57. node.innerHTML = html;
  58. };
  59. /******************************************************************************/
  60. vAPI.getURL = chrome.runtime.getURL;
  61. /******************************************************************************/
  62. vAPI.i18n = chrome.i18n.getMessage;
  63. setScriptDirection(vAPI.i18n('@@ui_locale'));
  64. /******************************************************************************/
  65. vAPI.closePopup = function() {
  66. window.open('','_self').close();
  67. };
  68. /******************************************************************************/
  69. })();
  70. /******************************************************************************/