Acfun Extension

acfun插件

目前为 2022-05-30 提交的版本。查看 最新版本

// ==UserScript==
// @name         Acfun Extension
// @namespace    https://github.com/aoi-umi
// @version      0.2
// @description  acfun插件
// @author       aoi-umi
// @match        *.acfun.cn/*
// @grant        none
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
// @license MIT
// ==/UserScript==
(function (exports) {
	'use strict';

	function unwrapExports (x) {
		return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
	}

	function createCommonjsModule(fn, module) {
		return module = { exports: {} }, fn(module, module.exports), module.exports;
	}

	var config = createCommonjsModule(function (module, exports) {
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.prefix = void 0;
	exports.prefix = 'ac-ext';

	});

	unwrapExports(config);
	config.prefix;

	var live = createCommonjsModule(function (module, exports) {
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.AcLiveExt = void 0;

	let prefix = `${config.prefix}-live-`;
	let acceptBtnName = `${prefix}accept`;
	let cancelBtnName = `${prefix}cancel`;
	let timeInputName = `${prefix}time`;
	let dialogName = `${prefix}dialog`;
	let defaultTime = 100;
	let likeBtn = document.querySelector('.like-heart');
	class AcLiveExt {
	    constructor() { }
	    get acLikeExt() {
	        return window.acLiveExt;
	    }
	    static globalInit() {
	        let acLikeExt = window.acLiveExt = new AcLiveExt();
	        acLikeExt.init();
	    }
	    toggle(dom, show) {
	        if (show === undefined)
	            dom.toggle();
	        else
	            show ? dom.show() : dom.hide();
	    }
	    // 样式
	    initStyle() {
	        $('style').append(`
      .${prefix}menu {
        background: white;
        position: fixed; top: 100px; right: 10px;
        border-radius: 50%; border: 1px solid #dcdee2;
        width: 40px; height: 40px;
        z-index: 1000;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
      }

      .${prefix}dialog-box {
        position: fixed; top: 100px; right: 10px;
        display: flex; justify-content: center;
        z-index: 1000;
      }
      .${prefix}dialog {
        background: white; width: 250px; height:100px; 
        border: 1px solid #dcdee2; border-radius: 5px;
        padding: 10px;
      }
      
      .${prefix}dialog > * {
        margin-bottom: 5px;
      }
      .${prefix}input {
        background-color: #f8f8f8 !important;
        color: #333;
        border-radius: 5px;
        padding: 2px 10px;
        font-size: 14px;
        font-weight: 400;
        text-align: left;
        line-height: 20px;
        border: 0;
      }
      .${prefix}btn {
        box-sizing: border-box;
        height: 28px;
        border-radius: 4px;
        padding: 3px 10px;
        font-size: 14px;
        line-height: 14px;
        cursor: pointer;
        position: relative;
        display: inline-flex;
        align-items: center;
        font-weight: 400;
        white-space: nowrap;
        text-align: center;
        background-image: none;
        background-color: #fff;
        border: 1px solid #e5e5e5;
        color: #999;
      }
      .${prefix}btn-primary {
        background: #fd4c5d;
        color: #fff;
      }
    `);
	    }
	    initView() {
	        this.addDialog();
	    }
	    ;
	    addDialog() {
	        let dialog = $(`
      <div id="${dialogName}" class="${prefix}dialog-box">
        <div  class="${prefix}dialog">
          <div>时间(毫秒/次, 大于等于100的数)</div>
          <div>
            <input class="${prefix}input" id="${timeInputName}" value=${defaultTime} autocomplete="off"  type="text" /> 
          </div>
          <div>
            <button id="${cancelBtnName}" type="button" class="${prefix}btn">取消</button>
            <button id="${acceptBtnName}" type="button" class="${prefix}btn ${prefix}btn-primary" >确定</button>
          </div>
        </div>
      </div>`);
	        this.toggle(dialog, false);
	        let acceptBtn = dialog.find(`#${acceptBtnName}`);
	        acceptBtn.on('click', () => {
	            this.acceptClick();
	        });
	        let cancelBtn = dialog.find(`#${cancelBtnName}`);
	        cancelBtn.on('click', () => {
	            this.toggle(dialog);
	        });
	        $('body').append(dialog);
	        this.acLikeExt.dialog = dialog;
	    }
	    acceptClick() {
	        let dialog = this.acLikeExt.dialog;
	        let time = dialog.find(`#${timeInputName}`).attr('value');
	        time = new Number(time);
	        if (isNaN(time) || time < 100) {
	            return alert('请输入正确的时间');
	        }
	        this.toggle(dialog);
	        this.toggleLike(time);
	    }
	    toggleLike(time) {
	        if (!likeBtn)
	            return alert('当前页面不支持');
	        if (this.acLikeExt.acLike) {
	            console.log('停止点赞');
	            clearInterval(this.acLikeExt.acLike);
	            this.acLikeExt.acLike = 0;
	        }
	        else {
	            console.log('开始点赞');
	            this.acLikeExt.acLike = setInterval(function () {
	                if (window.acMainExt.shouldPause)
	                    return;
	                likeBtn.click();
	            }, time);
	        }
	    }
	    init() {
	        this.initStyle();
	        this.initView();
	    }
	    run() {
	        // 运行中,停止
	        if (this.acLikeExt.acLike) {
	            this.toggleLike();
	        }
	        else {
	            let dialog = this.acLikeExt.dialog;
	            this.toggle(dialog, true);
	        }
	    }
	    ;
	}
	exports.AcLiveExt = AcLiveExt;

	});

	unwrapExports(live);
	live.AcLiveExt;

	var utils = createCommonjsModule(function (module, exports) {
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.clipboardCopy = void 0;
	const clipboardCopy = (data) => {
	    return navigator && navigator.clipboard && navigator.clipboard.writeText(data);
	};
	exports.clipboardCopy = clipboardCopy;

	});

	unwrapExports(utils);
	utils.clipboardCopy;

	var lib = createCommonjsModule(function (module, exports) {
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.AcMainExt = void 0;



	const prefix = `${config.prefix}-main-`;
	class AcMainExt {
	    constructor() {
	        this.init();
	    }
	    initStyle() {
	        $('style').append(`
    .${prefix}context-menu {
      display: none;
      min-width: 100px;
      min-height: 20px;
      position: fixed;
      background: white;
      border-radius: 5px;
      z-index: 3;
      padding: 15px 15px;
      cursor: pointer;
      box-shadow: 1px 1px 5px #888888;
    }
    
    .${prefix}menu {
      position: fixed; top: 100px; right: 10px;
    }
    .${prefix}menu > * {
      margin-bottom: 10px;
    }
    .${prefix}menu-item {
      background: white;
      border-radius: 50%; border: 1px solid #dcdee2;
      width: 40px; height: 40px;
      z-index: 1000;
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      animation:${prefix}show 1s;
    }
    .${prefix}hide {
      display: none;
    }
    @keyframes ${prefix}show {
      from {opacity:0;}
      to {opacity:1;}
    }
    `);
	    }
	    get isLive() {
	        return /live\/[\d]+/.test(location.href);
	    }
	    get shouldPause() {
	        return $(`.${prefix}menu-sub-item`).is(`:visible`)
	            // 礼物
	            || $('.container-gifts').hasClass('unfold')
	            // 牌子详情
	            || !$('.medal-panel-wrapper').hasClass('hide');
	    }
	    initView() {
	        this.addMenu();
	    }
	    addMenu() {
	        let dom = $(`<div class="${prefix}menu"></div>`);
	        let items = [];
	        // 直播
	        if (this.isLive) {
	            let liveBtn = $(`
      <svg width="20" viewBox="0 0 70 60">
        <path d="M0 10 L10 10 L10 0 L30 0 L30 10 L40 10 L40 0 L60 0 L60 10 L70 10 L70 30 L60 30 L60 40 L50 40 L50 50 L40 50 L40 60 L30 60 L30 50 L20 50 L20 40 L10 40 L10 30 L0 30 Z" fill="red" fill-rule="evenodd" />
      </svg>
      `);
	            liveBtn.on('click', () => {
	                window.acLiveExt.run();
	                return false;
	            });
	            items.push(liveBtn);
	            live.AcLiveExt.globalInit();
	        }
	        // 多菜单
	        if (items.length > 1) {
	            let mainMenuItem = $(`
      <svg viewBox="0 0 100 80" width="20" height="40">
        <rect width="100" height="20"></rect>
        <rect y="30" width="100" height="20"></rect>
        <rect y="60" width="100" height="20"></rect>
      </svg>
      `);
	            mainMenuItem.on('click', () => {
	                this.toggle($(`.${prefix}menu-sub-item`));
	                return false;
	            });
	            $(document).on('click', () => {
	                this.toggle($(`.${prefix}menu-sub-item`), false);
	            });
	            items.unshift(mainMenuItem);
	        }
	        if (items.length) {
	            items = items.map((ele, idx) => {
	                let dom = $('<div></div>');
	                if (idx > 0) {
	                    dom.addClass(`${prefix}menu-sub-item`).addClass(`${prefix}hide`);
	                }
	                dom.addClass(`${prefix}menu-item`).append(ele);
	                return dom;
	            });
	            dom.append(items);
	            $('body').append(dom);
	        }
	    }
	    init() {
	        this.initStyle();
	        this.initView();
	        let that = this;
	        $(document).on('click', `:not(.${prefix}context-menu)`, function () {
	            that.getMenu().hide();
	        });
	        $(document).on('click', `.${prefix}context-menu-item`, function (e) {
	            let dom = $(this);
	            let item = dom.data('item');
	            that.handleMenuItem(item);
	        });
	        this.initAvatar();
	        this.initDanmaku();
	    }
	    // 查看头像
	    initAvatar() {
	        let that = this;
	        $(document).on('contextmenu', function (e) {
	            let dom = $(e.target);
	            // console.log(dom)
	            let list = [{
	                    // 直播up主
	                    selector: '.live-author-avatar',
	                    getUrl: (dom) => {
	                        return dom.find('.live-author-avatar-img').attr('src');
	                    }
	                }, {
	                    // 榜单
	                    selector: '.avatar',
	                    getUrl: (dom) => {
	                        return dom.find('.head-img').attr('src');
	                    }
	                }, {
	                    // 主页
	                    selector: '.container-cover',
	                    getUrl: (dom) => {
	                        let url = dom.find('.user-photo').css('background-image');
	                        // 格式为url("......")
	                        url = url.substring(5, url.length - 2);
	                        return url;
	                    }
	                }, {
	                    // 稿件up
	                    selector: '.up-avatar',
	                    getUrl: (dom) => {
	                        return dom.find('.avatar').attr('src');
	                    }
	                }, {
	                    // 评论
	                    selector: '.area-comment-left .thumb',
	                    getUrl: (dom) => {
	                        return dom.find('.avatar').attr('src');
	                    }
	                }, {
	                    // 盖楼评论
	                    selector: '.mci-avatar',
	                    getUrl: (dom) => {
	                        return dom.find('img.fc-avatar').attr('src');
	                    }
	                }, {
	                    // 我的消息
	                    selector: '.avatar-section',
	                    getUrl: (dom) => {
	                        return dom.find('.avatar').attr('src');
	                    }
	                },];
	            for (let ele of list) {
	                let matchedDom;
	                if (dom.is(ele.selector)) {
	                    matchedDom = dom;
	                }
	                else {
	                    let p = dom.parents(ele.selector);
	                    if (p.length)
	                        matchedDom = p;
	                }
	                if (matchedDom) {
	                    let avatar = ele.getUrl(matchedDom);
	                    if (avatar) {
	                        avatar = avatar.split('?')[0];
	                        that.showContextMenu({
	                            e,
	                            avatar
	                        });
	                        return false;
	                    }
	                }
	            }
	        });
	    }
	    // 弹幕
	    initDanmaku() {
	        let that = this;
	        $(document).on('contextmenu', '.comment', function (e) {
	            let dom = $(this).find('.nickname');
	            let danmaku = dom.data('comment');
	            that.showContextMenu({
	                e,
	                danmaku
	            });
	            return false;
	        });
	    }
	    toggle(dom, show) {
	        let hideCls = `${prefix}hide`;
	        show = show !== null && show !== void 0 ? show : dom.hasClass(hideCls);
	        if (show)
	            dom.removeClass(hideCls);
	        else
	            dom.addClass(hideCls);
	    }
	    showContextMenu(opt) {
	        let { e, avatar, danmaku } = opt;
	        let pos = {
	            x: e.originalEvent.x || 0,
	            y: e.originalEvent.y || 0,
	        };
	        let list = [];
	        if (avatar) {
	            list.push({
	                text: '查看头像',
	                key: 'openImg',
	                data: avatar
	            });
	        }
	        if (danmaku) {
	            list.push({
	                text: '复制弹幕',
	                key: 'copyDanmaku',
	                data: danmaku
	            });
	        }
	        this.createMenu(list, pos);
	    }
	    getMenu() {
	        let menu = $(`.${prefix}context-menu`);
	        if (!menu.length) {
	            menu = $(`<div class="${prefix}context-menu"></div>`);
	            $('body').append(menu);
	        }
	        return menu;
	    }
	    createMenu(item, pos) {
	        let menu = this.getMenu();
	        menu
	            .css({
	            left: pos.x + 'px',
	            top: pos.y + 'px',
	        })
	            .empty()
	            .append(item.map(ele => {
	            let dom = $(`<div class="${prefix}context-menu-item">${ele.text}</div>`);
	            dom.data('item', ele);
	            return dom;
	        })).show();
	    }
	    handleMenuItem(item) {
	        switch (item.key) {
	            case 'openImg':
	                window.open(item.data, '__blank');
	                break;
	            case 'copyDanmaku':
	                utils.clipboardCopy(item.data);
	                break;
	        }
	    }
	}
	exports.AcMainExt = AcMainExt;
	window.acMainExt = new AcMainExt();

	});

	var index = unwrapExports(lib);
	var lib_1 = lib.AcMainExt;

	exports.AcMainExt = lib_1;
	exports["default"] = index;

	Object.defineProperty(exports, '__esModule', { value: true });

	return exports;

})({});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址