content.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2011 Gildas Lormeau
  3. * contact : gildas.lormeau <at> gmail.com
  4. *
  5. * This file is part of SingleFile.
  6. *
  7. * SingleFile is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * SingleFile is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. (function() {
  21. var MASK_ID = "__SingleFile_mask__", topWindow = window == top;
  22. function processStart() {
  23. var div = document.getElementById(MASK_ID);
  24. if (!div) {
  25. div = document.createElement("div");
  26. div.id = "__SingleFile_mask__";
  27. div.style.position = "fixed";
  28. div.style.top = "0px";
  29. div.style.left = "0px";
  30. div.style.height = "100%";
  31. div.style.width = "100%";
  32. div.style.backgroundColor = "black";
  33. div.style.zIndex = 2147483647;
  34. div.style.opacity = 0;
  35. div.style["-webkit-transition"] = "opacity 250ms";
  36. document.body.appendChild(div);
  37. div.offsetWidth;
  38. div.style.opacity = .3;
  39. }
  40. }
  41. function processEnd() {
  42. var div = document.getElementById(MASK_ID);
  43. if (div)
  44. document.body.removeChild(div);
  45. }
  46. window.addEventListener("keyup", function(event) {
  47. if (event.ctrlKey && event.shiftKey && event.keyCode == 83)
  48. chrome.extension.sendRequest({});
  49. }, true);
  50. if (topWindow)
  51. chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
  52. if (request.processStart)
  53. processStart();
  54. if (request.processEnd)
  55. processEnd();
  56. });
  57. })();