Ex-Hentai: Frame Popups

Embed popup window instead of another window.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Ex-Hentai: Frame Popups
// @namespace    Org.Jixun
// @version      0.2
// @description  Embed popup window instead of another window.
// @author       Jixun
// @include      http://exhentai.org/g/*
// @include      http://g.e-hentai.org/g/*
// @grant        none
// ==/UserScript==

////////////////////////////////////////////////
///                                 样式表   ///
////////////////////////////////////////////////
var style = document.createElement('style');
style.textContent = (function(){/*
#lb-oberlay {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    position: fixed;
    z-index: 100000;
    overflow: hidden;
    background: rgba(35,35,35,.7);
}

#lb-frame {
    box-shadow: 5px 5px 10px black;
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 100001;
    border: 0;
}
*/}).toString().slice(15,-4);
document.head.appendChild(style);

////////////////////////////////////////////////
///                           重叠元素就绪   ///
////////////////////////////////////////////////
var oberlay = document.createElement('div');
oberlay.id='lb-oberlay';
oberlay.style.display = 'none';

var popup = document.createElement('iframe');
popup.id  = 'lb-frame';
popup.style.display = 'none';
popup.setAttribute('seamless', true);

document.body.appendChild(oberlay);
document.body.appendChild(popup);

////////////////////////////////////////////////
///                           绑定元素事件   ///
////////////////////////////////////////////////
function hideOberlay () {
    oberlay.style.display = popup.style.display = 'none';
}
oberlay.onclick = hideOberlay;
popup.onload = function () {
    var wnd = popup.contentWindow;
    wnd.close = hideOberlay;
    
    [].map.call(wnd.document.querySelectorAll('[style*="height"]'), function (x) {
        x.style.height = '';
    });
};

////////////////////////////////////////////////
///                            仿 LightBox   ///
////////////////////////////////////////////////
window.popUp = function (url, w, h) {
    // 强行重写 /w\
    w += 20;
    h += 20;
    
    if (popup.src != url)
        popup.src = url;
    
    popup.style.width  = w + 'px';
    popup.style.height = h + 'px';
    popup.style.marginLeft = -w/2 + 'px';
    popup.style.marginTop  = -h/2 + 'px';
    oberlay.style.display = popup.style.display = 'block';
};