Amiami Redirect Link Button

Add buttons to redirect between Amiami.jp and Amiami.com.

目前為 2024-12-25 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Amiami Redirect Link Button
// @name:zh-CN   Amiami跳转链接按钮
// @namespace    https://greasyfork.org/zh-CN/scripts/521740
// @version      0.4
// @description  Add buttons to redirect between Amiami.jp and Amiami.com.
// @description:zh-cn  在Amiami商品页右下角添加一个实现amiami.jp与amiami.com互相跳转的链接按钮。
// @author       Mr_Ebonycat
// @match        https://www.amiami.jp/top/detail/detail?scode=*
// @match        https://www.amiami.com/cn/detail*
// @match        https://www.amiami.com/eng/detail*
// @grant        none
// @license      MIT

// ==/UserScript==

(function() {
    'use strict';

    // 提取URL中的scode或gcode参数
    function extractCode(url) {
        const urlObj = new URL(url);
        const params = urlObj.searchParams;
        return params.get('scode') || params.get('gcode');
    }

    // 根据当前页面的URL决定跳转的URL
    const currentUrl = window.location.href;
    const code = extractCode(currentUrl);
    let redirectUrl;

    if (currentUrl.includes('amiami.jp')) {
        // 如果当前在amiami.jp页面,跳转到amiami.com的detail页面
        // 假设scode和gcode之间可以相互转换,这里需要具体的转换逻辑
        redirectUrl = `https://www.amiami.com/detail?scode=${code}`;
    } else {
        // 如果当前在amiami.com页面,跳转到amiami.jp的top/detail页面
        redirectUrl = `https://www.amiami.jp/top/detail/detail?scode=${code}`;
    }

    // 创建按钮
    const redirectButton = document.createElement('a');
    redirectButton.href = redirectUrl; // 设置链接地址
    redirectButton.textContent = currentUrl.includes('amiami.com') ? 'Go to JP' : 'Go to COM';
    redirectButton.style.position = 'fixed';
    redirectButton.style.bottom = '20px';
    redirectButton.style.right = '20px';
    redirectButton.style.zIndex = '9999';
    redirectButton.style.padding = '2px 4px'; // 修改按钮内边距为2px 4px
    redirectButton.style.border = 'none';
    redirectButton.style.backgroundColor = '#4CAF50';
    redirectButton.style.color = 'white';
    redirectButton.style.borderRadius = '5px';
    redirectButton.style.cursor = 'pointer';
    redirectButton.style.display = 'inline-block'; // 使链接表现得像按钮
    redirectButton.style.textDecoration = 'none'; // 去除超链接的下划线

    // 将按钮添加到页面中
    document.body.appendChild(redirectButton);
})();