ChatGPT Shortcut Anywhere

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

当前为 2023-12-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ChatGPT Shortcut Anywhere
  3. // @namespace https://www.aishort.top/
  4. // @version 0.0.2
  5. // @description Toggle AiShort sidebar on the page
  6. // @author BensonLi
  7. // @name:zh-CN ChatGPT Shortcut Anywhere
  8. // @name:ja どこでもChatGPTショートカット
  9. // @name:pt Atalho ChatGPT Em Qualquer Lugar
  10. // @description:zh-CN ChatGPT Shortcut 扩展的增强版,任意网站都能打开 AiShort 侧边栏
  11. // @description:ja ChatGPT Shortcut 拡張の強化版、任意のウェブサイトで AiShort サイドバーを開くことができます
  12. // @description:pt Versão aprimorada da extensão ChatGPT Shortcut, abre a barra lateral AiShort em qualquer site
  13. // @match *://chat.openai.com/*
  14. // @match *://claude.ai/*
  15. // @match *://bard.google.com/*
  16. // @match *://yiyan.baidu.com/*
  17. // @match *://chatglm.cn/*
  18. // @exclude *://www.aishort.top/*
  19. // @icon https://www.aishort.top/img/logo.svg
  20. // @grant none
  21. // @license MIT
  22. // ==/UserScript==
  23.  
  24. (function() {
  25. 'use strict';
  26.  
  27. // You can directly set your preferred language by editing this variable.
  28. // For example, replace 'null' with 'zh' for Chinese, 'en' for English, 'ja' for Japanese, etc.
  29. // Supported language codes include: 'en', 'zh', 'ja', 'ko', 'es', 'fr', 'de', 'it', 'ru', 'pt', 'hi', 'ar', and 'bn'.
  30. // If set to 'null', the script will automatically use the browser's default language.
  31. const userSelectedLanguage = null; // Example: const userSelectedLanguage = 'zh';
  32.  
  33. // Array of available languages
  34. const AVAILABLE_LANGUAGES = ['en', 'zh', 'ja', 'ko', 'es', 'fr', 'de', 'it', 'ru', 'pt', 'hi', 'ar', 'bn'];
  35.  
  36. // Function to get the user-selected language or the browser's default language
  37. function getLanguage() {
  38. if (AVAILABLE_LANGUAGES.includes(userSelectedLanguage)) {
  39. return userSelectedLanguage;
  40. }
  41. const browserLanguage = navigator.language.split('-')[0];
  42. return AVAILABLE_LANGUAGES.includes(browserLanguage) ? browserLanguage : 'en';
  43. }
  44.  
  45. // Determine the language to use
  46. const userLanguage = getLanguage();
  47. // Set the URL for the iframe based on the selected language
  48. const iframeUrl = userLanguage === 'zh' ? 'https://www.aishort.top/' : `https://www.aishort.top/${userLanguage}/`;
  49.  
  50. // Create the iframe and set its source based on the language
  51. const iframe = document.createElement('iframe');
  52. iframe.style.width = '400px';
  53. iframe.style.height = '100%';
  54. iframe.style.position = 'fixed';
  55. iframe.style.right = '0';
  56. iframe.style.top = '0';
  57. iframe.style.zIndex = '999';
  58. iframe.style.border = 'none';
  59. iframe.style.display = 'none';
  60. iframe.src = iframeUrl;
  61. document.body.appendChild(iframe);
  62.  
  63. const toggleIcon = document.createElement('img');
  64. toggleIcon.src = 'https://img.newzone.top/toggle.svg';
  65. toggleIcon.style.position = 'fixed';
  66. toggleIcon.style.bottom = '60px';
  67. toggleIcon.style.right = '15px';
  68. toggleIcon.style.zIndex = '1000';
  69. toggleIcon.style.cursor = 'pointer';
  70. toggleIcon.style.width = '30px'; // Adjustable size
  71. toggleIcon.style.height = '30px';
  72. document.body.appendChild(toggleIcon);
  73.  
  74. toggleIcon.addEventListener('click', function() {
  75. // Toggle the display of the iframe
  76. iframe.style.display = (iframe.style.display === 'none') ? 'block' : 'none';
  77. });
  78. })();