// ==UserScript==
// @name Nyaa MyAnimeList Search Button
// @namespace https://greasyfork.org/users/whitewriter
// @version 1.0
// @description Adds a "MAL" button to Nyaa.si posts (main, search and inside posts) for quick MyAnimeList searches of Anime, Manga, and Light Novels.
// @author WhiteWriter
// @match https://nyaa.si/*
// @license MIT
// @icon https://nyaa.si/static/favicon.png
// @run-at document-end
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
// Check if we're inside a post (/view/ in the url) or the main/search page
const isViewPage = window.location.pathname.startsWith('/view/');
if (isViewPage) {
// Handle individual post page
processViewPage();
} else {
// Handle main/search page
processMainPage();
}
// Function to process main/search page
function processMainPage() {
// Select all post rows (any
)
const rows = document.querySelectorAll('tbody tr');
rows.forEach(row => {
// Get category from first
const categoryTd = row.children[0];
if (!categoryTd) return;
const categoryA = categoryTd.querySelector('a');
if (!categoryA) return;
const categoryTitle = categoryA.getAttribute('title').toLowerCase();
// Determine contentType (literature counts for both manga and light novel)
let contentType;
if (categoryTitle.includes('anime')) {
contentType = 'anime';
} else if (categoryTitle.includes('literature')) {
contentType = 'manga';
}
if (!contentType) return;
// Get title from second | , skipping comments if present
const titleTd = row.children[1];
if (!titleTd) return;
const titleA = Array.from(titleTd.querySelectorAll('a')).find(a => !a.classList.contains('comments'));
if (!titleA) return;
const title = titleA.getAttribute('title');
// Clean title and proceed. contentName is the best approximation to the
// content's title in order to search on MAL (doesn't need to be exact)
const contentName = cleanTitle(title);
if (contentName) {
addMalButton(row.children[2], contentType, contentName);
}
});
}
// Function to process individual view page (inside a post)
function processViewPage() {
// Get title from |