Tiny Customize

针对一些常用网站,例如 3DMGame、贴吧、卡饭、巴哈姆特、流亡编年史、Chiphell、等的反反广告检测、自动化、屏蔽网站功能等。

Versione datata 09/07/2016. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Tiny Customize
// @description 针对一些常用网站,例如 3DMGame、贴吧、卡饭、巴哈姆特、流亡编年史、Chiphell、等的反反广告检测、自动化、屏蔽网站功能等。
// @namespace   https://greasyfork.org/zh-CN/scripts/19823-tiny-customize
// @homepageURL https://greasyfork.org/zh-CN/scripts/19823-tiny-customize
// @author      nonoroazoro
// @include     /^https?\:\/\/(bbs)\.3dmgame\.com/
// @include     /^https?\:\/\/(bbs)\.kafan\.cn/
// @include     /^https?\:\/\/(forum)\.gamer\.com\.tw/
// @include     /^https?\:\/\/(www)\.chiphell\.com/
// @include     /^https?\:\/\/poedb\.tw(\/?.*)\/dps/
// @include     /^https?\:\/\/tieba\.baidu\.com/
// @version     1.1.0
// @grant       none
// ==/UserScript==

if (typeof unsafeWindow == "undefined")
{
    unsafeWindow = window;
}

/**
 * 获取立即执行的操作。
 */
const getInstantActions = function()
{
    const host = unsafeWindow.location.host;
    const href = unsafeWindow.location.href;
    const actions = [];

    if (host === "forum.gamer.com.tw")
    {
        // 巴哈姆特。

        // 反反广告检测。
        const action = function()
        {
            if (unsafeWindow.AntiAd)
            {
                unsafeWindow.AntiAd.check = function() {};
            }
        };
        actions.push(action);
    }
    else if (
        host === "bbs.kafan.cn" ||
        host === "bbs.3dmgame.com" ||
        host === "www.chiphell.com"
    )
    {
        // 卡饭、3DMGame、Chiphell 论坛(Discuz 驱动的论坛)。

        // 屏蔽方向键翻页。
        const action = function()
        {
            if (unsafeWindow.keyPageScroll)
            {
                unsafeWindow.keyPageScroll = function() {};
            }
        };
        actions.push(action);
    }
    else if (/^https?\:\/\/poedb\.tw(\/?.*)\/dps/.test(href))
    {
        // 流亡编年史。

        // 屏蔽默认自动全选物品信息、自动查询物品信息。
        const action = function()
        {
            const elem = document.querySelector(`#iteminfo`);
            elem.addEventListener("click", (e) =>
            {
                e.stopPropagation();
            }, true);

            elem.addEventListener("keydown", (e) =>
            {
                if (e.key === "Enter")
                {
                    document.querySelector(`form[action^="dps"]`).submit();
                    e.preventDefault();
                }
            }, true);

            elem.addEventListener("keyup", (e) =>
            {
                if (e.ctrlKey && (e.key === "v" || e.key === "V"))
                {
                    document.querySelector(`form[action^="dps"]`).submit();
                }
            });
        };
        actions.push(action);
    }

    return actions;
};

/**
 * 获取延迟执行的操作。
 */
const getLazyActions = function()
{
    const host = unsafeWindow.location.host;
    const actions = [];

    if (host === "forum.gamer.com.tw")
    {
        // 巴哈姆特。

        // 自动开启图片。
        let action = function()
        {
            if (unsafeWindow.forumShowAllMedia)
            {
                unsafeWindow.forumShowAllMedia();
            }
        };
        actions.push(action);
    }
    else if (host === "tieba.baidu.com")
    {
        // 贴吧。

        // 个人中心新标签打开。
        let action = function()
        {
            const timer = unsafeWindow.setInterval(() =>
            {
                const elem = document.querySelector(`a.u_menu_wrap[title^="点击到个人中心"`);
                if (elem)
                {
                    elem.target = "_blank";
                    unsafeWindow.clearInterval(timer);
                }
            }, 100);
        };
        actions.push(action);
    }

    return actions;
};

/**
 * 立即执行指定的操作。
 */
const exec = function(p_actions)
{
    if (p_actions)
    {
        p_actions.forEach(function(p_action)
        {
            p_action();
        });
    }
};

// 1. 立即执行。
exec(getInstantActions());


// 2. 延迟执行。
unsafeWindow.addEventListener("load", function()
{
    exec(getLazyActions());
}, true);