Greasy Fork

Greasy Fork is available in English.

GGn Title and Screenshots Formatter

Formats title and sets alias if applicable. Removes screenshots until they are a multiple of 4

当前为 2023-11-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GGn Title and Screenshots Formatter
// @namespace    none
// @version      1
// @description  Formats title and sets alias if applicable. Removes screenshots until they are a multiple of 4
// @author       ingts
// @match        https://gazellegames.net/upload.php
// ==/UserScript==
function formatTitle(str) {
    const smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|v.?|vs.?|via)$/i
    const alphanumericPattern = /([A-Za-z0-9\u00C0-\u00FF])/
    const wordSeparators = /([ :–—-])/
    const p = /[^a-zA-Z0-9 .?!]/g
    const match = str.match(p)
    const aliases = document.getElementById('aliases')
    if (match)
        aliases.value = match.join('')
    str = str
        .replace(/\s/g, ' ')
        .replace(/ ~ /, ': ').replace(/ ~/, ': ').replace(/~$/, '').replace(/ ~$/, '').replace(/ - /, ': ').replace(/ -/, ': ').replace(/-$/, '')
        .replace(p, "")
        .trim().toLowerCase()

    return str.split(wordSeparators)
        .map(function (current, index, array) {
            if (
                /* Check for small words */
                current.search(smallWords) > -1 &&
                /* Skip first and last word */
                index !== 0 &&
                index !== array.length - 1 &&
                /* Ignore title end and subtitle start */
                array[index - 3] !== ':' &&
                array[index + 1] !== ':' &&
                /* Ignore small words that start a hyphenated phrase */
                (array[index + 1] !== '-' ||
                    (array[index - 1] === '-' && array[index + 1] === '-'))
            ) {
                return current.toLowerCase()
            }
            /* Capitalize the first letter */
            return current.replace(alphanumericPattern, function (match) {
                return match.toUpperCase()
            })
        })
        .join('')
}

const titleInput = document.getElementById('title')
const tInterval = setInterval(() => {
    if (document.activeElement === titleInput || !titleInput.value)
        return
    titleInput.value = formatTitle(titleInput.value)
    clearInterval(tInterval)
}, 1000)

const screenshotInputs = document.getElementsByName('screens[]')
const removeButton = document.querySelector("#image_block > a:nth-child(3)")
const sInterval = setInterval(() => {
    for (let i = 0; i < screenshotInputs.length; i++) {
        if (!screenshotInputs[i].value) {
            return
        }
    }
    const number = screenshotInputs.length < 4 ? screenshotInputs.length : Math.min(Math.floor(screenshotInputs.length / 4) * 4, 20)
    while (screenshotInputs.length > number) {
        removeButton.click()
    }
    clearInterval(sInterval)
}, 1000)

document.querySelector("#image_block > a:nth-child(2)").addEventListener('click', () => {
    clearInterval(sInterval)
})