Hianime to mal + autofocus on searchbar

Autofocus on searchbar + breadcrumb navigate to mal

目前為 2025-02-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Hianime to mal + autofocus on searchbar
// @version      1.0
// @description  Autofocus on searchbar + breadcrumb navigate to mal
// @author       Kunal Jaiswal
// @icon         https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://hianime.to&size=64
// @match        https://hianime.to/*
// @grant        none
// @run-at       document-body
// @namespace https://greasyfork.org/users/1374464
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        setTimeout(function() {
            if (window.location.href.startsWith('https://hianime.to/')) {
                var breadcrumbItem = document.querySelector('li.breadcrumb-item.dynamic-name.active');
                if (breadcrumbItem) {
                    var text = breadcrumbItem.textContent.trim();
                    var extractedText = text.replace(/^Watching\s+/i, ''); // Removes "Watching" from the text

                    // Create a new anchor element for the extracted text
                    var link = document.createElement('a');
                    link.href = `https://myanimelist.net/search/all?q=${encodeURIComponent(extractedText)}&cat=all`;
                    link.textContent = extractedText;
                    link.target = '_blank'; // Open link in a new tab

                    // Clear the existing text in the li element and reassemble it with the link
                    breadcrumbItem.innerHTML = ''; // Clear the existing content
                    breadcrumbItem.appendChild(document.createTextNode('Watching ')); // Add the text "Watching "
                    breadcrumbItem.appendChild(link); // Append the new link with the extracted text
                }
            }

            var mobileSearchDiv = document.getElementById('mobile_search');
            if (mobileSearchDiv) {
                mobileSearchDiv.addEventListener('click', function() {
                    var searchInput = document.querySelector('.form-control.search-input');
                    if (searchInput) {
                        searchInput.focus();
                    }
                });
            }
        }, 0);
    });
})();