select plus account

方便选取plus共享账号

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         select plus account
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  方便选取plus共享账号
// @author       You
// @match        https://*.zhile.io/shared.html
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zhile.io
// @grant        none
// @license      MIT License
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    let accountNodes
    let try_max = 100
    let try_times = 0
    const func = () => {
        try_times++
        accountNodes = document.querySelectorAll(".account-list .plus");
        if (accountNodes==null && try_times < try_max) {
            setTimeout(func, 100)
        }
    }
    const div = document.createElement('div')
    div.style = "position: fixed;top: 20px;left: 20px;"
    const btnUp = document.createElement('button')
    const btnDown = document.createElement('button')
    const btnFirst = document.createElement('button')
    const btnLast = document.createElement('button')
    btnUp.innerText = '<'
    btnDown.innerText = '>'
    btnFirst.innerText = '|<'
    btnLast.innerText = '>|'
    let selectIndex = 0;
    const fnClick = (op) => () => {
        if(accountNodes == null) {
            func()
        }
        if(accountNodes == null) {
            console.log("accountNodes get fail")
            return
        }
        if("first" === op) {
            selectIndex = 0
        } else if("up" === op && selectIndex > 0) {
            selectIndex--
        } else if("last" === op) {
            selectIndex = accountNodes.length - 1
        } else if("down" === op && selectIndex < accountNodes.length - 1) {
            selectIndex++
        }
        const account = accountNodes[selectIndex];
        if(account == null) {
            console.log("account get fail")
            return
        }
        scrollTo(0, selectIndex > accountNodes.length / 2 ? account.offsetTop + account.offsetHeight + 20
                 : account.offsetTop - 20)
    }
    btnUp.onclick = fnClick("up")
    btnDown.onclick = fnClick("down")
    btnFirst.onclick = fnClick("first")
    btnLast.onclick = fnClick("last")
    div.appendChild(btnFirst)
    div.appendChild(btnUp)
    div.appendChild(btnDown)
    div.appendChild(btnLast)
    document.body.appendChild(div)
})();