GGn GOTY Search Linker

Links GOTY nominations/votes to search

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GGn GOTY Search Linker
// @namespace    none
// @version      1
// @description  Links GOTY nominations/votes to search
// @author       ingts
// @match        https://gazellegames.net/forums.php*action=viewthread&threadid=*
// ==/UserScript==

const threadTitle = document.querySelector("#content > div > h2 > a:nth-child(2)").nextSibling.nodeValue

function getHref(title) {
    return `https://gazellegames.net/torrents.php?artistname=&action=advanced&groupname=${encodeURIComponent(title)}&filter_cat%5B1%5D=1`
}

if (/GOTY \d+ (?:Nomination|Voting) Thread/.test(threadTitle)) {
    const posts = document.querySelectorAll('table.forum_post div[id^=content]')

    if (threadTitle.includes('Nomination')) {
        for (const post of posts) {
            const firstChild = post.firstChild
            const title = firstChild.nodeValue.trim()
            const a = document.createElement('a')
            a.href = getHref(title)
            a.textContent = title
            a.target = '_blank'
            firstChild.replaceWith(a)
        }
    } else {
        for (const post of posts) {
            let lastWasBr = false

            for (const child of post.childNodes) {
                if (child.nodeName === 'BR') {
                    if (lastWasBr) break
                    lastWasBr = true
                    continue
                }

                lastWasBr = false
                const val = child.nodeValue?.trim()
                const exec = /(.*?): ?(.*)/.exec(val)
                if (!exec) continue

                const span = document.createElement('span')
                span.innerHTML = `${exec[1]}: <a href=${getHref(exec[2])} target="_blank">${exec[2]}</a>`
                child.replaceWith(span)
            }
        }
    }
}