Greasy Fork

Greasy Fork is available in English.

Acfun ThrowBanana

一键5蕉

当前为 2021-06-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Acfun ThrowBanana
// @namespace    http://tampermonkey.net/
// @icon         https://tx-free-imgs.acfun.cn/content/2020_4_5/1.5860178587515075E9.png
// @version      1.0
// @description  一键5蕉
// @author       zyl315
// @match        *://www.acfun.cn/u/*
// @require      http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    addView();
})();

function addView() {
    let button = '<button id="throw-button" value="" style="position: absolute;top: 22px;left: 215px;border: 1px solid #fd4c5d;border-radius: 5px;background: #fff;color: #fd4c5d;cursor: pointer;">一键5蕉</button>'
    $('.ac-space-contribute-list').css('position', 'relative');
    $('.ac-space-contribute-list').append(button);
    $('#throw-button').click(function () {
        throwBanana();
    });
    getCurrentBananaNum(false);
}

// 获取当前页面所有视频或文章的链接,AC号
function getUrllList() {
    let urlList = [];
    $('.tag-content.active a').each(function () {
        let url = $(this).attr("href");
        if (url != null) {
            urlList.push(url);
        }
    })
    return urlList;
}

// 投香蕉
function throwBanana() {
    let urlList = getUrllList();
    let count = 0;
    let successCount = 0;

    if (urlList.length > 0) {
        $('#throw-button').html("投蕉中...");
        $('#throw-button').attr("diabled", 'true');
    }
    urlList.forEach(function (value) {
        let form = {
            resourceId: '',
            count: 5,
            resourceType: ''
        };
        let item = value.split("/");
        form['resourceId'] = item[2].substring(2);
        switch (item[1]) {
            case 'v':
                form['resourceType'] = 2;
                break;
            case 'a':
                form['resourceType'] = 3;
                break;
        }

        $.ajax({
            url: "https://www.acfun.cn/rest/pc-direct/banana/throwBanana",
            data: form,
            type: 'post',
            success: function (response) {
                if (response.result = '0') {
                    successCount++;
                } else {
                    console.log(response);
                }
            },
        }).done(function () {
            count++;
            if (count == urlList.length) {
                getCurrentBananaNum(true);
            }
        })
    });
}

// 获取用户的香蕉数
function getCurrentBananaNum(hint) {
    $.ajax({
        url: "https://www.acfun.cn/rest/pc-direct/user/personalInfo",
        success: function (data) {
            let bananaNum = data.info['banana'];
            if (!isNaN(bananaNum)) {
                if (hint == true) {
                    let lastBananaNum = $('#throw-button').val();
                    successThrow(lastBananaNum - bananaNum);
                }
                $('#throw-button').html("一键5蕉(" + bananaNum + ")");
                $('#throw-button').val(bananaNum);
                $('#throw-button').attr("diabled", 'false');
            };
        }
    })
}

function successThrow(throwCount) {
    alert("投蕉完毕!\n" + "总共消费" + throwCount + "根香蕉");
}