Rewrite MetArt Network Links

Rewrites all gallery/movie links so they go to the original studio's page

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

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

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

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

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

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Rewrite MetArt Network Links
// @description  Rewrites all gallery/movie links so they go to the original studio's page
// @namespace    https://greasyfork.org/users/1393919
// @version      1.0
// @license      MIT
// @match        *://www.metartnetwork.net/archive/*
// @match        *://www.metartnetwork.net/movies/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Find all anchor elements on the page
    var anchors = document.querySelectorAll('.gallery_image_cell_container > a');
    // Loop through each anchor element
    anchors.forEach((anchor) => {
        // Get the href and src attributes of the anchor's child image element
        var href = anchor.href;
        var imgSrc = anchor.querySelector('img').src;
  
        // Check if the href contains "metartnetwork.net" and the imgSrc contains "thumb="
        if (href.includes('metartnetwork.net') && imgSrc.includes('thumb=')) {
            // Get the domain from the thumb query parameter
            var thumbParam = new URLSearchParams(imgSrc.split('?')[1]).get('thumb');
            var thumbHostname = new URL(thumbParam).hostname.replace("static.", "www.");
            // Replace the domain in the href with the thumb domain
            var newHref = href.replace('www.metartnetwork.net', thumbHostname);
            // Update the href attribute of the anchor
            anchor.href = newHref;
            anchor.target = "_blank";

            const parentEl = anchor.parentElement.parentElement
            parentEl.querySelectorAll('div.gallery_information > a').forEach((el) => el.href = el.href.replace('www.metartnetwork.net', thumbHostname));
            
        }
    })
})();