// ==UserScript== // @name pixiv_manga_fit // @namespace http://mikan.sakura.tv // @description fit pixiv manga page to window // @include http://www.pixiv.net/member_illust.php?*mode=manga* // ==/UserScript== (function () { var source = function () { var screen_x = function () { return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft; }; var screen_y = function () { return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; }; var screen_w = function () { return window.innerWidth || document.documentElement.clientWidth || document.body.offsetWidth; }; var screen_h = function () { return window.innerHeight || document.documentElement.clientHeight || document.body.offsetHeight; }; var on = document.cookie.match(/(^|; )pixiv_manga_fit=on/); // add switch button var cont = document.getElementById("control-container"); var onclick; var li = document.createElement("li"); li.id = "toggle-pixiv-manga-layout"; li.style.marginLeft = "10px"; li.style.overflow = "hidden"; li.style.verticalAlign = "top"; li.style.fontSize = "18px"; li.style.textAlign = "center"; li.style.color = "#fff"; li.style.textShadow = "0px 1px .75px #666"; li.title = "⇔"; li.innerHTML = "⇔"; if (on) { onclick = function () { document.cookie= "pixiv_manga_fit=off;expires=Tue, 1-Jan-2038 00:00:00 GMT"; location.reload(); }; li.title = "end fitting"; li.style.backgroundColor = "#0096DB"; } else { onclick = function () { document.cookie= "pixiv_manga_fit=on;expires=Tue, 1-Jan-2038 00:00:00 GMT"; location.reload(); }; li.title = "fit to window"; } cont.getElementsByTagName("ul")[0].appendChild(li); li.addEventListener("click", onclick, false); // exit if switch is off if (on); else return; var meta = document.getElementById("meta"); // move title to bottom var title = meta.getElementsByClassName("title")[0];//.style.display = "none"; var footer = document.getElementsByTagName("footer")[0]; title.parentNode.removeChild(title); footer.appendChild(title); // verticalize controls var button_a = meta.getElementsByTagName("li"); for (var i = 0; i < button_a.length; ++i) { button_a[i].style.display = "block"; button_a[i].style.marginLeft = "0"; button_a[i].style.marginBottom = "3px"; } // move controls var cont = document.getElementById("control-container"); cont.style.top = "6px"; cont.style.right = "6px"; // move original size buttons var navi_a = document.getElementsByClassName("navigation-container"); for (var i = 0; i < navi_a.length; ++i) { var n = navi_a[i]; var p = n.parentNode; p.removeChild(n); p.appendChild(n); } // resize page number var page = document.getElementById("page-number"); page.style.padding = "3px"; page.style.right = "3px"; page.style.bottom = "3px"; page.style.backgroundColor = "transparent"; //total.innerHTML = total.innerHTML.match(/(.*)P/)[1]; // resize image var img_resize = function () { var img_c_a = document.getElementsByClassName("image-container"); var w = screen_w(); var h = screen_h(); for (var i = 0; i < img_c_a.length; ++i) { img_c_a[i].style.padding = "3px"; img_c_a[i].style.paddingRight = "36px"; var img = img_c_a[i].getElementsByTagName("img")[0]; img.style.maxWidth = w - 60 + "px"; img.style.maxHeight = h - 6 + "px"; } var scroll_reset = function () { pixiv.manga.move(pixiv.manga.position); }; setTimeout(scroll_reset, 0); }; img_resize(); window.addEventListener("resize", img_resize, false); // debug message //console.log && console.log("no error"); }; var text = document.createTextNode("(" + source.toString() + ")()"); var script = document.createElement('script'); script.appendChild(text); document.getElementsByTagName('head')[0].appendChild(script); })();