Sukebei MissAV Button

Adds a blue MissAV button with favicon and a single 'or' separator.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Sukebei MissAV Button
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  Adds a blue MissAV button with favicon and a single 'or' separator.
// @author       phnthnhnm
// @match        https://sukebei.nyaa.si/view/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 1. Find the torrent title element
    const titleElement = document.querySelector('h3.panel-title');
    if (!titleElement) return;

    const titleText = titleElement.textContent.trim();

    // 2. Extract the code using Regex
    // Pattern: alphanumeric chars, a dash, then numbers (e.g., abcd123-01234)
    const regex = /[a-zA-Z0-9]+-\d+/;
    const match = titleText.match(regex);

    // If no code is found, stop execution
    if (!match) {
        console.log('MissAV Button: No code found in title.');
        return;
    }

    const code = match[0];

    // 3. Find the Magnet button
    const magnetBtn = document.querySelector('a[href^="magnet:"]');
    if (!magnetBtn) return;

    // 4. Create the "or" text separator
    const orText = document.createTextNode(' or ');

    // 5. Create the "MissAV" button
    const missBtn = document.createElement('a');
    missBtn.href = `https://missav.ws/en/${code}`;
    missBtn.target = '_blank';
    missBtn.textContent = 'MissAV';

    // 6. Add the Favicon
    const favicon = document.createElement('img');
    favicon.src = 'https://www.google.com/s2/favicons?domain=missav.ws&sz=16';
    favicon.style.height = '14px';
    favicon.style.width = '14px';
    favicon.style.marginRight = '5px';
    favicon.style.verticalAlign = 'text-bottom';
    favicon.style.border = 'none';

    // Place icon before the text inside the button
    missBtn.prepend(favicon);

    // 7. Insert elements into the DOM
    // Order: [Magnet Button] -> [ or ] -> [MissAV Button]
    magnetBtn.parentNode.insertBefore(orText, magnetBtn.nextSibling);
    magnetBtn.parentNode.insertBefore(missBtn, orText.nextSibling);

})();