// ==UserScript==
// @name Steam Comments ErrorProofing
// @namespace steam
// @author 伟大鱼塘
// @description 防止留言被误删
// @include https://steamcommunity.com/
// @match https://steamcommunity.com/*
// @version 1.0.1
// @downloadURL none
// ==/UserScript==
{
const appendModal = fun => {
const html = '
';
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();
}
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();
}