Greasy Fork

Greasy Fork is available in English.

GGn Custom Request Vote

Vote on requests with custom amount from the list page

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GGn Custom Request Vote
// @namespace    none
// @version      1
// @description  Vote on requests with custom amount from the list page
// @author       ingts
// @grant        unsafeWindow
// @grant        GM_setValue
// @grant        GM_getValue
// @match        https://gazellegames.net/requests.php*
// @exclude      https://gazellegames.net/requests.php?action=view&id=*
// @exclude      https://gazellegames.net/requests.php?action=new*
// ==/UserScript==
const submit = document.querySelector('input[type=submit]')
const rows = document.querySelectorAll("#requests_list > tbody > tr:not(.colhead_dark)")

submit.insertAdjacentHTML('afterend', `
<div>Custom vote amount:
<input type="number" id="goldVote" placeholder="Gold" style="width: 90px;">
<input type="number" id="uploadVote" placeholder="Upload (GB)" style="width: 90px;">
`
    )

const goldVote = document.getElementById('goldVote')
const uploadVote = document.getElementById('uploadVote')

goldVote.onblur = setAmount
uploadVote.onblur = setAmount
let goldPrev, uploadPrev

if (GM_getValue('gold_vote')) {
    goldVote.value = GM_getValue('gold_vote')
    goldVote.dispatchEvent(new Event('blur'))
}
if (GM_getValue('upload_vote')) {
    uploadVote.value = GM_getValue('upload_vote')
    uploadVote.dispatchEvent(new Event('blur'))
}

function setAmount() {
    const goldVal = goldVote.value
    const uploadVal = uploadVote.value
    GM_setValue('gold_vote', goldVal)
    GM_setValue('upload_vote', uploadVal)
    const s = IndexVote.toString()
    unsafeWindow.IndexVote = Function ('requestid', 'type', s
        .replace(/^function[^{]+\{|}$/g, '') // if not it'll be a function inside another
        .replace(uploadPrev ? uploadPrev : '20 * 1024 * 1024', `${uploadVal * 1073741824 || 20 * 1024 * 1024}`) // convert to bytes
        .replace(goldPrev ? `amount = ${goldPrev}` : 'amount = 20;', `amount = ${goldVal || 20};`)
    )
    goldPrev = goldVal
    uploadPrev = uploadVal
}