Apina.biz improved

Browse apina.biz with full-sized images. Plus other tweaks.

当前为 2014-09-09 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Apina.biz improved
// @namespace   Rennex/apina.biz
// @description Browse apina.biz with full-sized images. Plus other tweaks.
// @include     http://apina.biz/*
// @version     2.1
// @run-at      document-start
// @grant       none
// ==/UserScript==

var m
if (m = location.href.match(/apina\.biz\/(\d+\.(jpg|gif|png))/)) {
    // we've somehow landed on the zoom-in page (from an external link?)
    // -> redirect to the picture
    location.replace("http://termite.apcdn.com/full/" + m[1])
}
// also remove that ?ref=randoms bullshit from the address bar
if (m = location.href.match(/apina\.biz\/(.+)\?ref=randoms/)) {
    history.replaceState(null, "", m[1])
}

// hide the picture before it even starts loading
var head = document.querySelector("head")
// (can the head still be non-existent at this point?)
//if (!head) { alert("headless") }
var style = document.createElement("style")
style.type = "text/css"
style.innerHTML = "#big_image { display: none; }"
head.appendChild(style)

// call this when the DOM has loaded
addEventListener("DOMContentLoaded", function () {
    // if we are in the image browsing mode, viewing a medium-sized image,
    // this will find an element
    var m, img, a = document.querySelector("#big_image a")
    if (a) {
        if (m = a.href.match(/\/\d+[^\/]+$/)) {
            // fix the link to point directly to the image
            a.href = "http://termite.apcdn.com/full" + m[0]
            // and remove that annoying title popup while we're at it
            a.removeAttribute("title")

            // change the img element to use the full-sized image and appear wider
            img = a.querySelector("img")
            if (img) {
                // seems that we have to remove this image and create a new one,
                // to prevent it from visibly growing moments later
                a.removeChild(img)

                // re-enable displaying the div
                head.removeChild(style)

                // create the new image element
                img = new Image()
                img.src = a.href
                img.style = "max-width: 100%"
                a.appendChild(img)
            }

        }
    }
}, false)