TA的每日心情 | 开心 2022-11-5 13:01 |
---|
签到天数: 3 天 [LV.2]偶尔看看I
荣誉开发者
- 积分
- 59
|
发表于
2021-8-19 09:31:17
|
显示全部楼层
- // ==UserScript==
- // @name bt搜索
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description 视频自动点赞,网页自动宽屏播放
- // @author 木羊羽
- // @include *
- // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
- // @run-at document-body
- // @grant GM_xmlhttpRequest
- // ==/UserScript==
- (function () {
- let header = {
- 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
- 'accept-encoding': 'gzip, deflate, br',
- 'accept-language': 'zh-CN,zh;q=0.9',
- 'cookie': 'JSESSIONID=0B904B22B2D367022FCE51C1104E25E3; aywcUid=P5R6Nrycwm_20210819090408; tet=1629338648883; tetm=29100',
- 'dnt': '1',
- 'referer': 'https://skrbtba.xyz/',
- 'sec-fetch-dest': 'document',
- 'sec-fetch-mode': 'navigate',
- 'sec-fetch-site': 'same-origin',
- 'sec-fetch-user': '?1',
- 'upgrade-insecure-requests': '1',
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
- }
- let content = $($('.tpc_cont')[0])
- let flag = content.find('a:even').css('color', 'red')
- let reg = /【影片名称】([\s\S]*?)<br>/g
- let title_list = content.html().match(reg)
- for (let i = 0; i < flag.length; i++) {
- let keywords = title_list[i].replace('【影片名称】', '')
- keywords = keywords.replace(':', '')
- keywords = keywords.replace('<br>', '')
- let search_url = `https://iskrbt08.xyz/search?keyword=${keywords}`
- // console.log(`开搜索【${url}】`)
- GM_xmlhttpRequest({
- method: 'GET',
- url: search_url,
- headers: header,
- synchronous: true,
- onload: function (response) {
- let data_list = []
- let doc = $(response.responseText)
- console.clear()
- console.log(`搜索页url【${search_url}】`)
- console.log(`搜索页请求头【${header.referer}】`)
- // console.log(response.responseText)
- let search_results = $(doc.find('.list-unstyled'))
- let count = search_results.length
- if (doc.find('.sr-only').length) {
- console.log('【【【【【【更新cookie】】】】】】')
- } else if (count === 0) {
- } else {
- count <= 5 ? count : count = 5
- for (let i = 0; i < count; i++) {
- let title = $(search_results[i]).children('li')[0].innerText
- let info = $(search_results[i]).children('li')[1].innerText
- let href = 'https://skrbtaa.xyz/' + $($(search_results[i]).children('li')[0]).children('a').attr("href")
- data_list[data_list.length] = title
- data_list[data_list.length] = info
- data_list[data_list.length] = href
- }
- for (let k = 0; k < data_list.length; k = k + 3) {
- // console.log(`${data_list[k]} ${data_list[k + 1]}`)
- header.referer = search_url
- let content_url = data_list[k + 2]
- GM_xmlhttpRequest({
- method: 'GET',
- url: content_url,
- headers: header,
- synchronous: true,
- onload: function (response) {
- let doc = $(response.responseText)
- // console.log(response.responseText)
- // let doc = $('html')
- try {
- data_list.splice(k + 3, 0, $(doc.find('.list-unstyled')[0]).children('li')[3].innerText.match(/[A-Z0-9]{40,40}$/)[0])
- }
- catch (err) {
- console.log(header.referer)
- // console.log(response.responseText)
- return console.log(`出错啦【${err.message}】`)
- }
- console.log(data_list)
- $(flag[i]).after(`<br>${data_list[k]} ${data_list[k + 1]} ${data_list[k + 3]}`)
- header.referer = 'https://skrbtba.xyz/'
- }
- })
- }
- }
- }
- })
- }
- })()
复制代码
我需要使用GM_xmlhttpRequest请求搜索关键词,获取搜索结果列表网页的数据,然后再次使用GM_xmlhttpRequest请求具体的搜索结果。需要在GM_xmlhttpRequest中嵌套GM_xmlhttpRequest,但是由于GM_xmlhttpRequest是异步的,将会导致第二个GM_xmlhttpRequest的请求头无法正确修改。我之前尝试了新建一个包含GM_xmlhttpRequest的函数,使用
async和await语法糖,但是在GM_xmlhttpRequest中的数据无法传出,我哭了 |
|