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.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 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;
        }
    }
})();