Greasy Fork

Greasy Fork is available in English.

音乐磁场自动回复隐藏帖

自动回复音乐磁场论坛上的隐藏帖

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         音乐磁场自动回复隐藏帖
// @namespace    http://greasyfork.icu/zh-CN/scripts/507531
// @version      1.2.1
// @description  自动回复音乐磁场论坛上的隐藏帖
// @author       zhenhappy<[email protected]>
// @match        https://*.hifiti.com/thread-*.htm
// @match        https://*.hifiki.com/thread-*.htm
// @icon         https://www.hifini.com/favicon.ico
// @require      https://unpkg.com/jquery/dist/jquery.slim.min.js
// @run-at       document-body
// @license      MIT
// ==/UserScript==

$(document).ready(function () {
    reply()
    optimizeLink()
})

function waitForElm(selector) {
    let time1, time2
    return new Promise(resolve => {
        if ($(selector).length > 0) return resolve($(selector))
        time1 = setTimeout(() => {
            resolve(null)
            clearTimeout(time1)
            clearInterval(time2)
        }, 3000)
        time2 = setInterval(() => {
            console.log(selector, $(selector).length)
            if ($(selector).length > 0) {
                resolve($(selector))
                clearTimeout(time1)
                clearInterval(time2)
            }
        }, 20)
    })
}

async function reply() {
    const warning = await waitForElm('.alert-warning')
    if (warning) {
        const message = await waitForElm('#message')
        if (message) {
            message.val('谢谢分享')
            setTimeout(() => {
                $('#submit').trigger('click')
            }, 500)
        }
    }
}

async function optimizeLink() {
    let pwd = ''
    const success = await waitForElm('.alert-success')
    if (success) {
        pwd = success.first().text().trim()
    }

    let href = ''
    let newHref = ''
    if (pwd) {
        href = $('p > a').first().attr('href')
        if (href && href.includes('pan.baidu.com')) {
            newHref = href.includes('?') ? `${href}&pwd=${pwd}` : `${href}?pwd=${pwd}`
        }
    }

    const downloadH5 = $('h5').filter(function () {
        return $(this).text().trim() === '下载'
    }).first()
    if (downloadH5.length) {
        downloadH5.next().remove()
        downloadH5.remove()
    }

    const passwordH5 = $('h5').filter(function () {
        return $(this).text().trim() === '提取码'
    }).first()
    if (passwordH5.length) {
        passwordH5.text('百度网盘')
        const newContent = `链接: <a href="${newHref}" target="_blank">${newHref}</a> 提取码: ${pwd}`
        passwordH5.next().next().html(newContent)
    }
}