统一战线史网络知识竞赛
// ==UserScript==
// @name 统一战线史网络知识竞赛
// @namespace nawlgzs@gmail.com
// @version 1.0.2
// @description 统一战线史和《统一战线工作条例》网络知识竞赛,学油猴脚本来油猴中文网就对了。
// @author Ne-21
// @match *://*.hntv.tv/*
// @connect api.gocos.cn
// @run-at document-end
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @supportURL https://script.521daigua.cn/UserGuide/faq.html
// @homepage https://script.521daigua.cn
// @license MIT
// ==/UserScript==
var _w = unsafeWindow,
_l = location,
router,
_host = "https://api.gocos.cn";
var t = setInterval(() => {
router = document.querySelector('uni-app').__vue__.$router;
if (typeof router != undefined) {
clearInterval(t)
init()
}
}, 1000)
function init() {
if (_l.pathname == '/total/tzdt/') {
router.afterHooks.push(() => {
console.log('Fuck Router!!!!!!!!')
if (router.history.current.path.indexOf('answer/answer') != -1) {
setTimeout(() => {
doQuestion()
}, 2000)
} else if (router.history.current.path.indexOf('answerResult') != -1) {
setTimeout(() => {
document.querySelector('body > uni-app > uni-page > uni-page-wrapper > uni-page-body > uni-view > uni-view.wrap > uni-view > uni-view.wrap-content-bottom > uni-button').click()
}, 5000)
} else {
console.log(router.history.current.path)
}
})
}
}
function doQuestion() {
let q = chineseChar2englishChar(document.querySelector('body > uni-app > uni-page > uni-page-wrapper > uni-page-body > uni-view > uni-view.wrap-question > uni-view.u-text > uni-text > span').textContent)
console.log(q)
if (q == '') {
setTimeout(doQuestion, 3000)
return
}
getAnswer(q).then((res) => {
let p = document.createElement("p");
p.style.color = "red";
p.textContent = "参考答案:" + res;
document.querySelector('body > uni-app > uni-page > uni-page-wrapper > uni-page-body > uni-view > uni-view.wrap-question > uni-view.u-text > uni-text > span').appendChild(p);
let as = document.querySelectorAll('body > uni-app > uni-page > uni-page-wrapper > uni-page-body > uni-view > uni-view.wrap-question > uni-view.wrap-question-list > uni-view')
as.forEach((item) => {
let a = item.textContent.replace(/^[A-Z]、/, '').trim()
if (res.indexOf(a) != -1) {
item.click()
}
})
setTimeout(() => {
next()
}, 5000)
}).catch((e) => {
let p = document.createElement("p");
p.style.color = "red";
p.textContent = "参考答案:" + e;
document.querySelector('body > uni-app > uni-page > uni-page-wrapper > uni-page-body > uni-view > uni-view.wrap-question > uni-view.u-text > uni-text > span').appendChild(p);
})
}
function next() {
let nextclass = document.querySelector('body > uni-app > uni-page > uni-page-wrapper > uni-page-body > uni-view > uni-view.wrap-question > uni-button').getAttribute('class')
if (nextclass.indexOf('u-button--disabled') != -1) {
setTimeout(next, 3000)
return
}
document.querySelector('body > uni-app > uni-page > uni-page-wrapper > uni-page-body > uni-view > uni-view.wrap-question > uni-button').click()
}
function getAnswer(q) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'POST',
url: _host + '/index.php/cxapi/hnzjjs/getanswer?v=2',
data: 'q=' + q,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function (xhr) {
let data = JSON.parse(xhr.responseText)
if (data.code == 1) {
resolve(data.data[0].a)
} else {
reject(data.msg)
}
}
})
})
}
function chineseChar2englishChar(chineseChar){
// 将单引号‘’都转换成',将双引号“”都转换成"
let str = chineseChar.replace(/[’|‘]/g,"'").replace(/[“|”]/g,"\"");
// 将中括号【】转换成[],将大括号{}转换成{}
str = str.replace(/【/g,"[").replace(/】/g,"]").replace(/{/g,"{").replace(/}/g,"}");
// 将逗号,转换成,,将:转换成:
str = str.replace(/,/g,",").replace(/:/g,":");
//将《转换为<,将》转换为>
str=str.replace(/《/g,"<").replace(/》/g,">");
//将句号。转换成.,将问号?转换为?
str=str.replace(/。/g,".").replace(/?/g,"?");
//将!转换为!
str=str.replace(/!/g,"!");
//将¥转换为$
str=str.replace(/¥/g,"$");
str = str.replace(/\s/g,'');
return str;
}