收集的GitHub上的 “那种” 项目并汇总,使用cloudflare worker搭建
地址:[链接登录后可见]
指定word字段以使用
示例:[链接登录后可见]
词库更新:[链接登录后可见]
使用special_list解决误封情况
原始码:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function JsonResponse(JsonString) {
return new Response(JSON.stringify(JsonString), {
headers: { 'content-type': 'application/json' },
})
}
async function handleRequest(request) {
let rep_json = {}
const url = new URL(request.url)
const queryString = url.search
if (!queryString) {
rep_json['status'] = 'error'
rep_json['body'] = {
is_found: false,
msg: 'no word to found'
}
return JsonResponse(rep_json)
}
const queryParams = new URLSearchParams(queryString)
const inputString = queryParams.get('word')
let found = false
for (const [key, value] of queryParams.entries()) {
if (key === "word") {
found = true
break
} else {
rep_json['status'] = 'error'
rep_json['body'] = {
is_found: false,
msg: 'no word to found'
}
return JsonResponse(rep_json)
}
}
const special_list = [
'bilibili',
'bilibili.com/video/av',
'bilibili.com/video/AV'
]
for (let keyword of special_list) {
if (inputString.includes(keyword)) {
rep_json['status'] = 'warning'
rep_json['body'] = {
is_found: false,
msg: 'word in white list'
}
return JsonResponse(rep_json)
}
}
const block_words_url = "http://blockd-words.ct.ws/words.txt"
const block_words_text = (await fetch(block_words_url)).text()
const block_words_list = (await block_words_text).split('\n')
for (let keyword of block_words_list) {
if (inputString.includes(keyword)) {
rep_json['status'] = 'success'
rep_json['body'] = {
is_found: true,
originalString: inputString,
matchedKeyword: keyword
}
return JsonResponse(rep_json)
}
}
rep_json['status'] = 'warning'
rep_json['body'] = {
is_found: false,
originalString: inputString,
msg: 'no matched keyword'
}
return JsonResponse(rep_json)
}