Turns the "Now Viewing: tag_name" text on Rule34 wiki entries into a clickable link to the tag's image posts.
// ==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;
}
}
})();