Skip to content

Instantly share code, notes, and snippets.

@sparrowhe
Created January 25, 2023 06:47
Show Gist options
  • Save sparrowhe/1dd4d004563e75ac5cb81e00b8a46fe8 to your computer and use it in GitHub Desktop.
Save sparrowhe/1dd4d004563e75ac5cb81e00b8a46fe8 to your computer and use it in GitHub Desktop.
锤子检测器
// ==UserScript==
// @name 我想锤的管制
// @namespace https://atc.vatprc.net/
// @version 0.1
// @description 检测本次活动有没有我想锤的管制
// @author 1429444
// @match https://atc.vatprc.net/events/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=vatprc.net
// @grant none
// @run-at document-end
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// ==/UserScript==
function findHammer(e) {
let ammerList = [
// 在这里加入检测列表
'Xukun Cai',
'Zihei Xiao'
]
e.disabled = true;
let htmlBtns = document.getElementsByTagName('button')
if (htmlBtns.length > 0) {
e.innerHTML = '有 '
for (let i = 0; i < htmlBtns.length; i++) {
// if (htmlBtns[i].innerText == 'Ziyang Wang') {
// e.innerHTML += htmlBtns[i].innerText + ' '
// }
if (hammerList.includes(htmlBtns[i].innerText)) {
e.innerHTML += htmlBtns[i].innerText + ', '
}
}
e.innerHTML = e.innerHTML.slice(0, -2)
e.innerHTML += ' 锤子'
} else {
e.innerHTML = '没有锤子'
}
}
function waitForKeyElements(selectorTxt, actionFunction, bWaitOnce, iframeSelector) {
var targetNodes, btargetsFound;
if (typeof iframeSelector == "undefined")
targetNodes = $(selectorTxt);
else
targetNodes = $(iframeSelector).contents()
.find(selectorTxt);
if (targetNodes && targetNodes.length > 0) {
btargetsFound = true;
targetNodes.each(function () {
var jThis = $(this);
var alreadyFound = jThis.data('alreadyFound') || false;
if (!alreadyFound) {
//--- Call the payload function.
var cancelFound = actionFunction(jThis);
if (cancelFound) btargetsFound = false;
else jThis.data('alreadyFound', true);
}
});
} else {
btargetsFound = false;
}
//--- Get the timer-control variable for this selector.
var controlObj = waitForKeyElements.controlObj || {};
var controlKey = selectorTxt.replace(/[^\w]/g, "_");
var timeControl = controlObj[controlKey];
//--- Now set or clear the timer as appropriate.
if (btargetsFound && bWaitOnce && timeControl) {
//--- The only condition where we need to clear the timer.
clearInterval(timeControl);
delete controlObj[controlKey]
} else {
//--- Set a timer, if needed.
if (!timeControl) {
timeControl = setInterval(function () {
waitForKeyElements(selectorTxt, actionFunction, bWaitOnce, iframeSelector);
}, 300);
controlObj[controlKey] = timeControl;
}
}
waitForKeyElements.controlObj = controlObj;
}
(function() {
'use strict';
waitForKeyElements(".event-title", function (element){
let node = `<div class="ant-space ant-space-horizontal ant-space-align-center" style="gap: 8px; margin-left: 8px"><div class="ant-space-item"><button class="ant-btn ant-btn-primary" onclick="findHammer(this)">检测锤子</button></div><!----></div>`
let row = document.getElementsByClassName('ant-row')[1].children[0]
row.innerHTML += node;
$(".findHammer").onclick = findHammer
return;
// row.appendChild(document.createElement('button'))
// row.lastChild.innerText = '检测锤'
// row.lastChild.onclick = findHammer
// row.lastChild.style = 'margin-left: 10px;'
// row.lastChild.className = 'ant-btn ant-btn-primary'
}, true)
$("body").append(`<script>${findHammer.toString()}</script>`)
}
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment