Greasy Fork

Greasy Fork is available in English.

Diggy's Adventure - Game in full window

Remove useless widgets/panels in Diggy's Adventure

当前为 2017-05-21 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Diggy's Adventure - Game in full window
// @version      2.0
// @description  Remove useless widgets/panels in Diggy's Adventure
// @author       Vins
// @match        https://diggysadventure.com/miner/*
// @match        https://apps.facebook.com/diggysadventure/*
// @match        https://portal.pixelfederation.com/_da/miner/*
// @match        https://portal.pixelfederation.com/*/diggysadventure/*
// @grant        GM_setValue
// @grant        GM_getValue
// @namespace    http://greasyfork.icu/users/98672
// ==/UserScript==
(function() {
    'use strict';
    var isFullwindow = true, miner, btn, refresh, onResize, iframe, originalHeight;
	isFullwindow = GM_getValue("DAfullwindow") !== "0";
    function forceResize() { window.dispatchEvent(new Event('resize')); }
    function getById(id) { return document.getElementById(id); }
    function iterate(el, fn) { if(el) if(typeof el.length == "number") { for(var i = el.length - 1; i >= 0; i--) { iterate(el[i], fn); } } else { fn(el); } }
    function hide(el) { if(el && el.style) { el.style.display = isFullwindow ? "none" : ""; } }
    miner = getById("miner");
    if(miner) { // inner IFRAME has a "miner" object
        originalHeight = miner.height;
        btn = document.createElement("button");
        Object.assign(btn, { innerText:"\u058e", title:"Toggle Fullwindow" });
        Object.assign(btn.style, { position:"fixed", top:(miner.offsetTop + 4) + "px", left:"4px", opacity:"0.5", backgroundColor:"#66f", color:"white", fontSize:"16pt", borderRadius:"6px", padding:"0px 2px", cursor:"pointer" });
        document.body.appendChild(btn);
        onResize = function() { btn.style.top = (miner.offsetTop + 4) + "px"; miner.height = isFullwindow ? document.body.clientHeight : originalHeight; };
        refresh = function() {
            GM_setValue("DAfullwindow", isFullwindow ? "1" : "0");
            // display news in a floating box
            iterate(document.getElementsByClassName("news"), function(el) { if(el && el.style) { el.style.position = isFullwindow ? "fixed" : ""; } });
            iterate([document.getElementsByClassName("header-menu"), document.getElementsByClassName("cp_banner bottom_banner"), getById("bottom_news"), getById("footer"), getById("gems_banner")], hide);
            document.body.style.overflowY = isFullwindow ? "hidden" : "";
            Object.assign(btn.style, isFullwindow ? { backgroundColor:"white", color:"black", borderStyle:"inset" } : { backgroundColor:"#66f", color:"white", borderStyle:"outset" });
            var data = "fullwindow=" + (isFullwindow ? 1 : 0);
            try { window.parent.postMessage(data, "https://apps.facebook.com"); } catch(e) {}
            try { window.parent.postMessage(data, "https://portal.pixelfederation.com"); } catch(e) {}
            onResize();
        };
        btn.addEventListener("click", function() { isFullwindow = !isFullwindow; refresh(); });
        if(isFullwindow) { setTimeout(refresh, 5000); }
    }
    else if(getById("skrollr-body")) { // portal.pixelfederation
        onResize = function() { var t = document.getElementsByClassName("game-iframe game-iframe--da")[0]; if(t) t.style.height = isFullwindow ? window.innerHeight + "px" : ""; };
        refresh = function() {
            document.body.style.overflowY = isFullwindow ? "hidden" : "";  // remove vertical scrollbar
            iterate([getById("header"), getById("footer")], hide);
        };
    }
    else { // main document (Facebook)
		iframe = getById("iframe_canvas");
        onResize = function() {
			if(originalHeight === undefined) originalHeight = iframe && iframe.style.height;
			if(iframe) iframe.style.height = isFullwindow ? window.innerHeight + "px" : originalHeight;
		};
        refresh = function(event) {
            document.body.style.overflowY = isFullwindow ? "hidden" : "";  // remove vertical scrollbar
            iterate([getById("rightCol"),getById("pagelet_bluebar"),getById("pagelet_dock")], hide);
        };
    }
    if(onResize) window.addEventListener("resize", onResize);
    if(refresh && !btn) window.addEventListener("message", function(event) {
        if((event.origin === "https://portal.pixelfederation.com" || event.origin === "https://diggysadventure.com") && event.data.substr(0, 11) === "fullwindow=") {
            isFullwindow = event.data.substr(11) === "1";
            refresh();
            onResize();
            setTimeout(forceResize, 5000);
        }
    });
})();