Bluesky Hashtag Page Auto-Click Latest Button

Automatically clicks the 'Latest' button on Bluesky hashtag pages

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bluesky Hashtag Page Auto-Click Latest Button
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automatically clicks the 'Latest' button on Bluesky hashtag pages
// @author       Claude 3.5 Sonnet
// @match        https://bsky.app/hashtag/*
// @match        https://bsky.app/search?q*
// @license MIT
// @grant        none
// ==/UserScript==

// Written with prompting instructions from Lauren @lauren1701.bsky.social

(function() {
    'use strict';

    // Function to check and click the 'Latest' button
    function clickLatestButton() {
        // Select the 'Latest' tab button
        const latestButton = document.querySelector('div[role="tablist"] div[role="tab"]:nth-child(2)');

        if (latestButton) {
            // If the 'Latest' button is found and not already selected, click it
            if (!latestButton.querySelector('[style*="border-bottom-color: rgb(16, 131, 254)"]')) {
                latestButton.click();
                console.log('Clicked Latest button');
            }
        }
    }

    // Use a MutationObserver to watch for changes in the page
    const observer = new MutationObserver((mutations) => {
        for (const mutation of mutations) {
            if (mutation.type === 'childList') {
                clickLatestButton();
            }
        }
    });

    // Start observing the page with the following configuration
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // Initial check in case the button is already present
    clickLatestButton();
})();