Rule34 Wiki Tag Linker

Turns the "Now Viewing: tag_name" text on Rule34 wiki entries into a clickable link to the tag's image posts.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Rule34 Wiki Tag Linker
// @namespace    http://tampermonkey.net
// @version      1.2
// @description  Turns the "Now Viewing: tag_name" text on Rule34 wiki entries into a clickable link to the tag's image posts.
// @author       uNderdog_101
// @license      MIT
// @match        https://rule34.xxx/index.php?page=wiki&s=view&*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // 1. Locate the header element. Rule34 wiki view headers typically use an <h2> element.
    const headers = document.querySelectorAll('h2');

    // 2. Loop through all <h2> elements on the page to find the one containing the tag name text.
    for (const h2 of headers) {

        // Check if the text inside the header starts with "Now Viewing:"
        if (h2.textContent.includes('Now Viewing:')) {

            // 3. Extract the clean tag name.
            // .replace() removes the "Now Viewing:" text and .trim() removes any accidental leading/trailing spaces.
            const tagName = h2.textContent.replace('Now Viewing:', '').trim();

            // Fail-safe: Ensure we actually extracted a tag string before creating elements.
            if (tagName.length > 0) {

                // 4. Construct the URL pointing to the image posts for this specific tag.
                // FIXED: Fully restored the correct path and query parameters you debugged.
                const postUrl = 'https://rule34.xxx/index.php?page=post&s=list&tags=' + encodeURIComponent(tagName);

                // 5. Create a new anchor (<a>) element to serve as our link.
                const tagLink = document.createElement('a');
                tagLink.href = postUrl;
                tagLink.textContent = tagName;
                tagLink.target = '_blank'; // Instructs the browser to open the link in a new tab.
                tagLink.rel = 'noopener noreferrer'; // Security best practice when opening links in new tabs.

                // 6. Style the new link to ensure it looks distinct and matches a standard hyperlink look.
                tagLink.style.color = '#007bff';
                tagLink.style.textDecoration = 'underline';

                // 7. Rebuild the header's contents safely.
                // Clear the existing text so we can split it cleanly into plain text and our new clickable link.
                h2.textContent = 'Now Viewing: ';

                // Append the link element right next to the "Now Viewing: " prefix text.
                h2.appendChild(tagLink);
            }

            // Exit the loop early since we found and modified the correct heading element.
            break;
        }
    }
})();