Siam博客

腾讯云杂货摊脚本

2021-05-26

// ==UserScript==
// @name         腾讯云活动测试
// @namespace    http://blog.siammm.cn
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://cloud.tencent.com/developer/video/*
// @icon         https://www.google.com/s2/favicons?domain=tencent.com
// @grant        none
// @require      https://code.jquery.com/jquery-1.12.4.min.js
/* globals jQuery, $, waitForKeyElements */
// ==/UserScript==

(function() {
    'use strict';

    // 先获取url的id
    let url = window.location.href;
    let urlArray = url.split("/")
    let id = urlArray.pop();

    // 今日已处理数量 = 20,则不运行
    if (todayNumberGet() >= 20){
        alert("今日处理已达标,请记录最后id ->" + id);
        todayNumberClear();
        return false;
    }
    let commentContent = "666牛逼啊";
    let csrfCode = 488460237;
    let uin = 100002600007;
    let commentUrl = `https://cloud.tencent.com/developer/services/ajax/creator/creator?action=AddVideoComment&uin=${uin}&csrfCode=${csrfCode}`;


    function runCondition(){
        // 先判断是否点过赞,没有则点赞
        let hasStart = !$(".video-operations.com-operations a.com-opt-link.operation-like").hasClass("dark");
        if (!hasStart){
            clickStart();
            setTimeout(function(){
                comment();
            }, randomNum(1200, 2500));

            // 今日已处理数量++
            todayNumberAdd();

            setTimeout(function(){
                urlArray.push(++id);
                window.location.href = urlArray.join("/");
            }, randomNum(2500, 4500));
        }else{
            console.log(id + " -> 文章已处理过");
            // 延迟1000毫秒跳转下一个链接
            setTimeout(function(){
                urlArray.push(++id);
                window.location.href = urlArray.join("/");
            }, randomNum(1200, 2500));
        }
    }

    function clickStart(){
        $(".video-operations.com-operations a")[0].click();
        console.log(id + " -> 点赞完成");
    }
    function comment()
    {
        $(".edit-textarea").val(commentContent)
        $(".edit-btns .c-btn-disabled").removeClass("c-btn-disabled");
        $.ajax({
            url: commentUrl,
            type: "post",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify({
                action: "AddVideoComment",
                payload: {
                    videoId: id,
                    parentCommentId: 0,
                    content: commentContent
                }
            }),
            dataType: "json",
            success: function(res) {
                console.log(id + " -> 评论结果");
                console.log(res);
            }
        })
    }

    function todayNumberAdd(){
        let originNumber = localStorage.getItem("siam_number");
        if (!originNumber) originNumber = 0;
        originNumber++;
        localStorage.setItem("siam_number", originNumber);
    }
    function todayNumberClear()
    {
        localStorage.setItem("siam_number", 0);
    }
    function todayNumberGet()
    {
        let originNumber = localStorage.getItem("siam_number");
        if (!originNumber) originNumber = 0;
        return originNumber;
    }
    function randomNum(minNum,maxNum){
        switch(arguments.length){
            case 1:
                return parseInt(Math.random()*minNum+1,10);
                break;
            case 2:
                return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10);
                break;
            default:
                return 0;
                break;
        }
    }


    // 等待2秒 防止还没加载好
    setTimeout(function(){
        runCondition();
    }, 1500 );
})();
本文链接:
版权声明: 本文由 Siam原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权

扫描二维码,分享此文章