收集的GitHub上的 “那种” 项目并汇总,使用cloudflare worker搭建
地址:https://block-words-api.runoneall.us.kg
指定word字段以使用
示例:https://block-words-api.runoneall.us.kg/?word=qwq
词库更新:https://www.nodeloc.com/d/16422
使用special_list解决误封情况
原始码:
```javascript
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')
console.log(inputString)
const isSource = queryParams.get("source")
console.log(isSource)
if (inputString === null && isSource === null) {
rep_json['status'] = 'error'
rep_json['body'] = {
is_found: false,
msg: 'no word to found'
}
return JsonResponse(rep_json)
}
if (inputString !== null && isSource === null) {
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 = "https://runoneall.serv00.net/Files/block-words.txt"
const block_words_rep_text = (await fetch(block_words_url)).text()
const block_words_text = await block_words_rep_text
if (inputString === null && isSource !== null) {
return new Response(block_words_text, {headers: { 'content-type': 'text/plain; charset=utf-8' }})
}
const block_words_list = 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)
}
```