Like chéo, cày rank 11/3

Status
Not open for further replies.

tungtien

Member
JavaScript:
(function(){
/* Tùy chọn reaction, các bạn thay các số tương ứng vào là được (vd: REACTION = 2)
     0 : Random
1 : Like
2 : Love
3 : Haha
4 : Wow
5 : Sad
6 : Angry
*/
const REACTION = 1;

/* Tùy chọn trang bắt đầu (khỏi phải scan lại từ đầu =]]) */
const START_PAGE = 1;

/* Tùy chọn like cho Top reaction (https://next.voz.vn/members/?key=highest_reaction_score.
    Set bằng 'true' nếu muốn like cho top.
Vì một voz tân có like bằng nhau
*/

const LIKE_HIGHEST_REACTION = true;
  
/*
    Like theo id người post (https://next.voz.vn/members/{id}/)
ex: const WHITE_LIST = ["id1", "id2", "id3", "id...N"]
*/
const WHITE_LIST = [];

/*
    Không Like theo id người post
ex: const BLACK_LIST = ["id1", "id2", "id3", "id...N"]
*/

const BLACK_LIST = [];

function getHttpRequest() {
  try {return new XMLHttpRequest();}
  catch (error) {}
  try {return new ActiveXObject("Msxml2.XMLHTTP");}
  catch (error) {}
  try {return new ActiveXObject("Microsoft.XMLHTTP");}
  catch (error) {}

  throw new Error("Could not create HTTP request object.");
}

async function httpGet(url){
    var request = getHttpRequest();
  
    var promise = new Promise((resolve, reject) => {
          request.onreadystatechange = function() {
             if (request.readyState==4 && request.status==200)
                {
                    resolve(request.responseText);
                }
          }
    });

    request.open("GET", url, true);
    request.send(null);

    return await promise;
}

async function httpPost(url, data){
    var request = getHttpRequest();
    var promise = new Promise((resolve, reject) => {
          request.onreadystatechange = function() {
             if (request.readyState==4 && request.status==200)
                {
                    resolve(request.responseText);
                }
          }
    });

    request.open("POST", url, true);
    request.setRequestHeader('Accept', 'application/json, text/javascript, */*; q=0.01');
    request.setRequestHeader('content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
    request.send(data);

    return await promise;
}

function sleep (time) {
  return new Promise((resolve) => setTimeout(resolve, time));
}
/*------------------------------------------*/

function querySelectorAll(element, query){
    return Array.from(element.querySelectorAll(query));
}

async function getDocument(url){
    var text = await httpGet(url);
    var parser = new DOMParser();
  
    return parser.parseFromString(text, 'text/html');
}

async function getHighestReactionMembers(){
    var doc = await getDocument("/members/?key=highest_reaction_score");

    return querySelectorAll(doc, ".username").map(item=> /members\/(.*)\//gm.exec(item.href)[1]);
}

async function autoLike(reaction=1){
    var url = /(.*)\/(page)?/gm.exec(window.location.href)[1];
    var totalPage = 1;
    var pageNav = querySelectorAll(document, ".pageNav-page").pop();
    pageNav = pageNav ? pageNav.querySelector("a") : null;
  
    if(pageNav!=null){
        totalPage = /\/page-(.*)/gm.exec(pageNav.href)[1];
    }
    var pathName = /(.*)\/(page)?/gm.exec(window.location.pathname)+ "/";
  
    var highestReactionMembers = await getHighestReactionMembers();
  
    for(var i=START_PAGE;i<=totalPage;i++){
        console.log("-------- Like page: " + i + "--------");
        var htmlDoc = await getDocument(url+"/page-"+i);
        var token = htmlDoc.documentElement.getAttribute("data-csrf");
      
        querySelectorAll(htmlDoc, ".message.message--post").forEach(item=>{
            var postId = /js-post-(.*)/gm.exec(item.id)[1];
            var userId =  /members\/(.*)\//gm.exec(item.querySelector(".username").href)[1];
          
            if(WHITE_LIST!=null && WHITE_LIST.length > 0){
                if(WHITE_LIST.findIndex(item=>item==userId) == -1){
                    console.log("Ignore " + userId);
                    return;
                }
            }
          
            if(BLACK_LIST!=null && BLACK_LIST.length > 0){
                if(BLACK_LIST.findIndex(item=>item==userId) >= 0){
                    console.log("Ignore " + userId);
                  
                    return;
                }
            }
          
            if(!LIKE_HIGHEST_REACTION){
                if(highestReactionMembers.findIndex(item=>item==userId) >= 0){
                    console.log("Ignore " + userId);
                    return;
                }
            }
          
            if(item.querySelector("a.reaction.reaction--imageHidden")){
                 console.log("Like post: "+ postId);
                var r = reaction || Math.floor(Math.random() * 6)+1;
                httpPost("/posts/"+postId+"/react?reaction_id="+r, "_xfRequestUri="+pathName+"page-"+i+"&_xfWithData=1&_xfToken="+token+"&_xfResponseType=json");
            }
        }); 
      
        sleep(500);
    } 
  
    console.log("done");
}

autoLike(REACTION);
})();
code mới cho ae. dùng cái cũ bị unlike nhé
 
Last edited:
Status
Not open for further replies.
Top