Guest User

Tapermonkey: Nhentai Gallery link for comments

a guest
Feb 8th, 2025
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.75 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         NHentai Comment Gallery Linker
  3. // @namespace    https://nhentai.net/
  4. // @version      1.0
  5. // @description  Adds a link to the gallery for each comment on NHentai user pages
  6. // @author       erasels
  7. // @match        https://nhentai.net/users/*/*
  8. // @icon         https://nhentai.net/favicon.ico
  9. // @license      none
  10. // @grant        none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.     'use strict';
  15.  
  16.     // Select all comments
  17.     document.querySelectorAll('.comment').forEach(comment => {
  18.         try {
  19.             // Extract the data-state attribute which contains JSON
  20.             const dataState = JSON.parse(comment.getAttribute('data-state'));
  21.  
  22.             // Ensure gallery_id exists
  23.             if (dataState && dataState.gallery_id) {
  24.                 const galleryId = dataState.gallery_id;
  25.                 const galleryLink = `https://nhentai.net/g/${galleryId}`;
  26.  
  27.                 // Find the timestamp element
  28.                 const timeElement = comment.querySelector('.header .left time');
  29.                 if (timeElement) {
  30.                     // Create a link element
  31.                     const linkElement = document.createElement('a');
  32.                     linkElement.href = galleryLink;
  33.                     linkElement.textContent = ' [View Gallery]';
  34.                     linkElement.style.marginLeft = '5px';
  35.                     linkElement.style.color = 'gray';
  36.                     linkElement.style.fontWeight = 'bold';
  37.  
  38.                     // Append the link next to the time element
  39.                     timeElement.parentNode.appendChild(linkElement);
  40.                 }
  41.             }
  42.         } catch (error) {
  43.             console.error('Error processing comment:', error);
  44.         }
  45.     });
  46. })();
  47.  
Advertisement
Add Comment
Please, Sign In to add comment