Ex-Hentai: Frame Popups

Embed popup window instead of another window.

  1. // ==UserScript==
  2. // @name Ex-Hentai: Frame Popups
  3. // @namespace Org.Jixun
  4. // @version 0.2
  5. // @description Embed popup window instead of another window.
  6. // @author Jixun
  7. // @include http://exhentai.org/g/*
  8. // @include http://g.e-hentai.org/g/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. ////////////////////////////////////////////////
  13. /// 样式表 ///
  14. ////////////////////////////////////////////////
  15. var style = document.createElement('style');
  16. style.textContent = (function(){/*
  17. #lb-oberlay {
  18. top: 0;
  19. left: 0;
  20. width: 100%;
  21. height: 100%;
  22. position: fixed;
  23. z-index: 100000;
  24. overflow: hidden;
  25. background: rgba(35,35,35,.7);
  26. }
  27.  
  28. #lb-frame {
  29. box-shadow: 5px 5px 10px black;
  30. position: fixed;
  31. left: 50%;
  32. top: 50%;
  33. z-index: 100001;
  34. border: 0;
  35. }
  36. */}).toString().slice(15,-4);
  37. document.head.appendChild(style);
  38.  
  39. ////////////////////////////////////////////////
  40. /// 重叠元素就绪 ///
  41. ////////////////////////////////////////////////
  42. var oberlay = document.createElement('div');
  43. oberlay.id='lb-oberlay';
  44. oberlay.style.display = 'none';
  45.  
  46. var popup = document.createElement('iframe');
  47. popup.id = 'lb-frame';
  48. popup.style.display = 'none';
  49. popup.setAttribute('seamless', true);
  50.  
  51. document.body.appendChild(oberlay);
  52. document.body.appendChild(popup);
  53.  
  54. ////////////////////////////////////////////////
  55. /// 绑定元素事件 ///
  56. ////////////////////////////////////////////////
  57. function hideOberlay () {
  58. oberlay.style.display = popup.style.display = 'none';
  59. }
  60. oberlay.onclick = hideOberlay;
  61. popup.onload = function () {
  62. var wnd = popup.contentWindow;
  63. wnd.close = hideOberlay;
  64. [].map.call(wnd.document.querySelectorAll('[style*="height"]'), function (x) {
  65. x.style.height = '';
  66. });
  67. };
  68.  
  69. ////////////////////////////////////////////////
  70. /// 仿 LightBox ///
  71. ////////////////////////////////////////////////
  72. window.popUp = function (url, w, h) {
  73. // 强行重写 /w\
  74. w += 20;
  75. h += 20;
  76. if (popup.src != url)
  77. popup.src = url;
  78. popup.style.width = w + 'px';
  79. popup.style.height = h + 'px';
  80. popup.style.marginLeft = -w/2 + 'px';
  81. popup.style.marginTop = -h/2 + 'px';
  82. oberlay.style.display = popup.style.display = 'block';
  83. };