当前位置 : 主页 > 网络编程 > JavaScript >

https:www.tucia.netshots

来源:互联网 收集:自由互联 发布时间:2021-06-30
https:www.tucia.netshots // ==UserScript==// @name tucia.net// @namespace minhill.com// @include https://www.tucia.net/shots/*// @version 1// @grant none// ==/UserScript==const fetchInit = { //请求参数, cookies method:'POST', credenti
https:www.tucia.netshots
// ==UserScript==
// @name        tucia.net
// @namespace   minhill.com
// @include     https://www.tucia.net/shots/*
// @version     1
// @grant       none
// ==/UserScript==
const fetchInit = { //请求参数, cookies

  method:'POST',
  credentials:'include'
}
var links = [];


function mainPage(){
  var nodesList = document.querySelectorAll('.block.widest.highest.absolute.editedThumb');
  for (let item of nodesList) {
  links.push(item.href.replace('shots','account/likes'));//替换成推荐地址
  }
  console.log(links.length);
}

function siglePage(){
  links.push(location.href.replace('shots','account/likes'));
  /* var targetButton =  document.querySelector('.f-md-90 button');
  console.log(targetButton);
  var clickEvt = document.createEvent('HTMLEvents');  
  clickEvt.initEvent('click',true,true);
  targetButton.dispatchEvent(clickEvt);
  */
}

function after1s(x) {//蛤蛤函数

  return new Promise(resolve => {
    setTimeout(() => {
      resolve(x);
    }, Math.round(x*1000));
  });
};

async function fetchAll(links){
  for (let url of links){
    await after1s(0.5); //停顿一秒后再抓取,防止被禁

    let res = await fetch(url,fetchInit);
    if(res.redirected) throw new Error('未登陆');
    let data = await res.json();
    //打印数据

    if(!data.error){
      console.log(data.callbacks[0].param);
      var permission = await Notification.requestPermission();
      if (permission === 'granted') {
         var options = {
            body: data.callbacks[0].param,
          }
         var n = new Notification('成功推荐',options);
         await after1s(3)
         n.close();
      }
    }
    else{
      console.log(data.popError.body);
    }
  }
}

function main(){
  //console.log(location.href);
  let singleTest = /shots\/\d{5,}/.test(location.href);
  //console.log(singleTest);
  if(singleTest){
    
    siglePage();
  }
  else{
    //mainPage();
  }
  fetchAll(links)
    .catch(err=>console.error(err));
}

main();
网友评论