Steam Comments ErrorProofing

防止留言被误删

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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

{
  const appendModal = fun => {
    const html =
      '<div id="del_confirm_modal" class="newmodal" style="position: fixed;z-index: 1000; max-width: 1826px;left: 681px;top: 346px;">' +
      '<div class="modal_top_bar"></div>' +
      '<div class="newmodal_header_border">' +
      '<div class="newmodal_header">' +
      '<div class="newmodal_close"></div>' +
      '<div class="title_text">确认删除?</div>' +
      '</div>' +
      '</div>' +
      '<div class="newmodal_content_border">' +
      '<div class="newmodal_content" style="max-height: 816px">' +
      '<div class="profileedit_SaveCancelButtons_2KJ8a">' +
      '<button type="button" id="confirm_btn" class="DialogButton _DialogLayout Primary">确认</button>' +
      '<button type="button" class="DialogButton _DialogLayout Secondary">取消</button>' +
      '</div>' +
      '</div>' +
      '</div>' +
      '</div>'
    document.querySelector('body').insertAdjacentHTML('afterBegin', html)
    bindEvent(fun)
  }

  const bindEvent = fun => {
    const modal = document.querySelector('#del_confirm_modal')
    modal.addEventListener('click', e => {
      const t = e.target
      if (t.id == 'confirm_btn') {
        const eventFun = new Function(fun)
        eventFun()
      }
      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 targetList = document.querySelectorAll('.commentthread_comments')
    const observer = new MutationObserver(mutations => {
      mutations.forEach(mutation => {
        resetClickEvent()
      })
    })
    for (let el of targetList) {
      observer.observe(el, {
        childList: true,
        subtree: true,
      })
    }
  }

  resetClickEvent()
  obs()
}