Sleazy Fork is available in English.

駿河屋海外品切れ自動ON、検索バー移動、品番表示

Enhance Suruga-ya.com browsing experience

// ==UserScript==
// @name         駿河屋海外品切れ自動ON、検索バー移動、品番表示
// @name:en      Suruga-ya Overseas: Out-of-Stock Auto-Enable, Search Bar Movement, Product Number Display
// @name:zh-CN  駿河屋国外站点:自动启用缺货、搜索栏移动、产品编号显示
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Enhance Suruga-ya.com browsing experience
// @description:en  Enhance Suruga-ya.com browsing experience
// @description:zh-CN  提升駿河屋網站的瀏覽體驗
// @author       Kim
// @match        https://www.suruga-ya.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to display management numbers next to product links
    function displayManagementNumbers() {
        // 商品リンクの要素を取得
        var productLinks = document.querySelectorAll('a[data-info]');

        // 各商品リンクに対して処理を行う
        productLinks.forEach(function(link) {
            // data-info属性の値を取得
            var info = link.getAttribute('data-info');
            if (info) {
                // data-info属性の値をJSONとして解析
                var productInfo = JSON.parse(info.replace(/"/g, '"'));
                // 管理番号を取得
                var productId = productInfo.id;
                if (productId) {
                    // 管理番号を取得できた場合、リンクの隣に表示する要素を作成して追加
                    var managementNumber = document.createElement('span');
                    managementNumber.textContent = '管理番号: ' + productId;
                    // リンクの後ろに追加
                    link.parentNode.insertBefore(managementNumber, link.nextSibling);
                }
            }
        });
    }

    // Function to update the position of the search bar
    function updateSearchBarPosition() {
        var searchBar = document.getElementById('search_mobile');
        var initialOffsetTop = searchBar.offsetTop;

        var scrollTop = window.pageYOffset || document.documentElement.scrollTop; // Get the current scroll position
        if (scrollTop > initialOffsetTop) {
            searchBar.style.position = 'fixed';
            searchBar.style.top = '0';
            searchBar.style.left = '0';
            searchBar.style.zIndex = '9999';
        } else {
            searchBar.style.position = 'static';
        }
    }

    // Display management numbers when the page loads
    window.addEventListener('load', function() {
        displayManagementNumbers(); // Display management numbers when the page loads
        updateSearchBarPosition(); // Update the search bar position when the page loads
    });

    // Re-update the search bar position on window resize
    window.addEventListener('resize', function() {
        updateSearchBarPosition(); // Update the search bar position when the window is resized
    });

    // Update the search bar position when scrolling
    window.addEventListener('scroll', function() {
        updateSearchBarPosition(); // Update the search bar position when scrolling
    });

})();

// Function to automatically enable out of stock filter if it's off when the page loads
function autoEnableOutOfStockFilter() {
    // Get the current URL
    const currentUrl = window.location.href;

    // If the URL does not contain "in_stock=t" and the page is not a product detail page, add it and reload the page
    if (!currentUrl.includes("in_stock=t") && !currentUrl.includes("/item/detail/")) {
        // Add "in_stock=t" and reload
        window.location.href = currentUrl + (currentUrl.includes("?") ? "&" : "?") + "in_stock=t";
    }
}

// Auto-enable out of stock filter when the page loads
window.addEventListener('load', function() {
    autoEnableOutOfStockFilter(); // Call the function when the page loads
});