Greasy Fork

Greasy Fork is available in English.

ChatGPT Shortcut Anywhere

ChatGPT Shortcut 扩展的增强版,任意网站都能打开 AiShort 侧边栏

目前为 2023-12-23 提交的版本。查看 最新版本

// ==UserScript==
// @name         ChatGPT Shortcut Anywhere
// @namespace    https://www.aishort.top/
// @version      0.0.2
// @description  Toggle AiShort sidebar on the page
// @author       BensonLi
// @name:zh-CN   ChatGPT Shortcut Anywhere
// @name:ja      どこでもChatGPTショートカット
// @name:pt      Atalho ChatGPT Em Qualquer Lugar
// @description:zh-CN ChatGPT Shortcut 扩展的增强版,任意网站都能打开 AiShort 侧边栏
// @description:ja ChatGPT Shortcut 拡張の強化版、任意のウェブサイトで AiShort サイドバーを開くことができます
// @description:pt Versão aprimorada da extensão ChatGPT Shortcut, abre a barra lateral AiShort em qualquer site
// @match        *://chat.openai.com/*
// @match        *://claude.ai/*
// @match        *://bard.google.com/*
// @match        *://yiyan.baidu.com/*
// @match        *://chatglm.cn/*
// @exclude      *://www.aishort.top/*
// @icon         https://www.aishort.top/img/logo.svg
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // You can directly set your preferred language by editing this variable.
    // For example, replace 'null' with 'zh' for Chinese, 'en' for English, 'ja' for Japanese, etc.
    // Supported language codes include: 'en', 'zh', 'ja', 'ko', 'es', 'fr', 'de', 'it', 'ru', 'pt', 'hi', 'ar', and 'bn'.
    // If set to 'null', the script will automatically use the browser's default language.
    const userSelectedLanguage = null; // Example: const userSelectedLanguage = 'zh';

    // Array of available languages
    const AVAILABLE_LANGUAGES = ['en', 'zh', 'ja', 'ko', 'es', 'fr', 'de', 'it', 'ru', 'pt', 'hi', 'ar', 'bn'];

    // Function to get the user-selected language or the browser's default language
    function getLanguage() {
        if (AVAILABLE_LANGUAGES.includes(userSelectedLanguage)) {
            return userSelectedLanguage;
        }
        const browserLanguage = navigator.language.split('-')[0];
        return AVAILABLE_LANGUAGES.includes(browserLanguage) ? browserLanguage : 'en';
    }

    // Determine the language to use
    const userLanguage = getLanguage();
    // Set the URL for the iframe based on the selected language
    const iframeUrl = userLanguage === 'zh' ? 'https://www.aishort.top/' : `https://www.aishort.top/${userLanguage}/`;

    // Create the iframe and set its source based on the language
    const iframe = document.createElement('iframe');
    iframe.style.width = '400px';
    iframe.style.height = '100%';
    iframe.style.position = 'fixed';
    iframe.style.right = '0';
    iframe.style.top = '0';
    iframe.style.zIndex = '999';
    iframe.style.border = 'none';
    iframe.style.display = 'none';
    iframe.src = iframeUrl;
    document.body.appendChild(iframe);

    const toggleIcon = document.createElement('img');
    toggleIcon.src = 'https://img.newzone.top/toggle.svg';
    toggleIcon.style.position = 'fixed';
    toggleIcon.style.bottom = '60px';
    toggleIcon.style.right = '15px';
    toggleIcon.style.zIndex = '1000';
    toggleIcon.style.cursor = 'pointer';
    toggleIcon.style.width = '30px'; // Adjustable size
    toggleIcon.style.height = '30px';
    document.body.appendChild(toggleIcon);

    toggleIcon.addEventListener('click', function() {
        // Toggle the display of the iframe
        iframe.style.display = (iframe.style.display === 'none') ? 'block' : 'none';
    });
})();