something just like this ???
// ==UserScript==
// @name New Userscript
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description try to take over the world!
// @author You
// @match *
// @run-at document-end
// @grant unsafeWindow
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
function getRandomSecond(min = 1, max = 1) {
return Math.floor(Math.random() * (max + 1 - min) + min) * 1000
}
function getRandomHanzi() {
const codePoint = Math.floor(Math.random() * (0x9FFF - 0x4E00 + 1)) + 0x4E00
return String.fromCodePoint(codePoint)
}
function generateRandomHanzi(min = 1, max = 18) {
const length = Math.floor(Math.random() * (max - min + 1)) + min
let result = ""
for (let i = 0; i < length; i++) {
result += getRandomHanzi()
}
return result
}
function openUrl() {
setTimeout(() => {
window.open(`https://bing.com/search?q=${generateRandomHanzi()}&form=QBLH`, "_self")
}, getRandomSecond(6, 9))
}
const DATA_LINK = ".bing.com/search?q="
if (location.href.includes(DATA_LINK)) {
const links = document.querySelectorAll(`li h2 a:not([class*="adTA"])`)
if (links.length > 0) {
GM_setValue("host", links[2].host)
GM_setValue("status", 0)
setTimeout(() => {
links[2].click()
console.log("Click Done!")
}, 1e3)
const isOpened = setInterval(() => {
if (GM_getValue("status", 0) == 1) {
console.log("Open Done!")
GM_setValue("status", 0)
clearInterval(isOpened)
}
}, 1e3)
const isClosed = setInterval(() => {
if (GM_getValue("status", 0) == 2) {
console.log("Close Done!")
clearInterval(isClosed)
openUrl()
}
}, 1e3)
setTimeout(() => {
if (GM_getValue("status", 0) == 0) {
console.log("Timeout!")
clearInterval(isOpened)
clearInterval(isClosed)
openUrl()
}
}, 3e4)
} else {
console.log("Can not find links!")
openUrl()
}
}
const DATA_HOST = GM_getValue("host", null)
if (DATA_HOST && location.href.includes(DATA_HOST)) {
GM_setValue("status", 1)
setTimeout(() => {
window.close()
GM_setValue("host", null)
GM_setValue("status", 2)
}, getRandomSecond(3, 6))
}