GGn Custom Request Vote

Vote on requests with custom amount from the list page

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 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
}