Greasy Fork

Greasy Fork is available in English.

Steam Comments ErrorProofing

防止留言被误删

当前为 2018-06-04 提交的版本,查看 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Steam Comments ErrorProofing
// @namespace   steam
// @author      伟大鱼塘
// @description 防止留言被误删
// @include     https://steamcommunity.com/
// @match       https://steamcommunity.com/*
// @version     1.0.0
// ==/UserScript==

{
    const appendModal = fun => {
        const html = '<div id="del_modal" class="newmodal" style="position: fixed; z-index: 1000; width: 280px;left:50%;top:50%;transform: translate(-50%,-50%);">' +
            '<div class="newmodal_header_border">' +
            '<div class="newmodal_header">' +
            '<div data-action="close" class="newmodal_close close_modal"></div>' +
            '<div class="ellipsis">确认删除</div>' +
            '</div>' +
            '</div>' +
            '<div class="newmodal_content_border">' +
            '<div class="newmodal_content" style="text-align:center;">' +
            '<a class="btn_profile_action btn_medium" href="javascript:;" style="margin:0 10px;border-radius: 2px;color: #fff !important;padding: 1px;display: inline-block;text-decoration: none;cursor: pointer;border: 1px solid #212121;background: #373f4f;background: -webkit-linear-gradient( top, #7a8494 5%, #282f3d 95%);background: linear-gradient( to bottom, #7a8494 5%, #282f3d 95%);">' +
            '<span data-action="del" style="padding: 0 65px;border-radius: 2px;display: block;background: #2e394c;background: -webkit-linear-gradient( top, #33425a 5%, #282f3d 95%);background: linear-gradient( to bottom, #33425a 5%, #282f3d 95%);">是</span>' +
            '</a>' +
            '<a class="btn_profile_action btn_medium" href="javascript:;" style="margin:0 10px;border-radius: 2px;color: #fff !important;padding: 1px;display: inline-block;text-decoration: none;cursor: pointer;border: 1px solid #212121;background: #373f4f;background: -webkit-linear-gradient( top, #7a8494 5%, #282f3d 95%);background: linear-gradient( to bottom, #7a8494 5%, #282f3d 95%);">' +
            '<span data-action="close" style="padding: 0 65px;border-radius: 2px;display: block;background: #2e394c;background: -webkit-linear-gradient( top, #33425a 5%, #282f3d 95%);background: linear-gradient( to bottom, #33425a 5%, #282f3d 95%);">否</span>' +
            '</a>' +
            '</div>' +
            '</div>' +
            '</div>';
        document.querySelector('body').insertAdjacentHTML('afterBegin', html);
        bindEvent(fun);
    }

    const bindEvent = fun => {
        const modal = document.querySelector('#del_modal');
        modal.addEventListener('click', (e) => {
            const t = e.target;
            if (t.dataset.action == 'del') {
                const eventFun = new Function(fun);
                eventFun();
            }
            const modal = document.querySelector('#del_modal');
            document.querySelector('body').removeChild(modal);
        });
    }

    const resetClickEvent = () => {
        const del_nodeList = document.querySelectorAll('.actionlink');
        for (let el of del_nodeList) {
            const fun = el.href.substring(11);
            el.href = 'javascript:;'
            el.addEventListener('click', () => {
                appendModal(fun);
            });
        }
    }

    const obs = () => {
        const target = document.querySelector('.commentthread_comments');
        const observer = new MutationObserver(mutations => {
            mutations.forEach(mutation => {
                resetClickEvent();
            });
        });
        observer.observe(target, {
            childList: true,
            subtree: true
        });
    }

    resetClickEvent();
    obs();
}