Amiami跳转链接按钮

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

当前为 2024-12-25 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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/*/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);
})();