chatGPT for Persians

Fix rtl text issues for Persian/Farsi language. Press R+RIGHT for full rtl. R+LEFT for rtl align left. and R + DOWN for deactivation.

目前为 2023-11-22 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name chatGPT for Persians
  3. // @name:fa راست چین chatgpt
  4. // @description Fix rtl text issues for Persian/Farsi language. Press R+RIGHT for full rtl. R+LEFT for rtl align left. and R + DOWN for deactivation.
  5. // @description:fa محیط چت جی پی تی رو راست چین میکنه و برای بلاک های کدینگ و استفاده ترکیبی دو زبانه بهینه شده. از دکمه های ترکیبی R و چپ R و راست و R پایین استفاده کنید.
  6. // @version 1
  7. // @namespace NIMABEHKARrtlchatgpt
  8. // @grant none
  9. // @author Nima Behkar
  10. // @license CC BY-NC-SA 4.0 DEED
  11. // @match *://chat.openai.com/*
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const styles = {
  18. 'rtlLeft': `
  19. body *:not(code):not(code *) {
  20. direction: rtl;
  21. text-align: left;
  22. }
  23. pre, pre *, code, code * {
  24. direction: ltr !important;
  25. text-align: left !important;
  26. }
  27. `,
  28. 'rtlRight': `
  29. body *:not(code):not(code *) {
  30. direction: rtl;
  31. text-align: right;
  32. }
  33. pre, pre *, code, code * {
  34. direction: ltr !important;
  35. text-align: left !important;
  36. }
  37. `
  38. };
  39.  
  40. const styleSheet = document.createElement('style');
  41. styleSheet.type = 'text/css';
  42. document.head.appendChild(styleSheet);
  43.  
  44. let currentStyle = '';
  45.  
  46. const FapplyStyle = (styleName) => {
  47. if (styles[styleName]) {
  48. styleSheet.innerText = styles[styleName];
  49. currentStyle = styleName;
  50. }
  51. };
  52.  
  53. const applyStyle = (styleName) => {
  54. if (styles[styleName]) {
  55. styleSheet.innerText = styles[styleName];
  56. currentStyle = styleName;
  57. alert(`استایل "${styleName}" فعال شد.`);
  58. }
  59. };
  60.  
  61. const disableStyle = () => {
  62. styleSheet.innerText = '';
  63. currentStyle = '';
  64. alert('استایل غیرفعال شد.');
  65. };
  66.  
  67. let lastKeyPressed = '';
  68.  
  69. document.addEventListener('keydown', (event) => {
  70. if (event.key === 'r' || event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown') {
  71. if (lastKeyPressed === 'r' && event.key === 'ArrowLeft') {
  72. applyStyle('rtlLeft');
  73. } else if (lastKeyPressed === 'r' && event.key === 'ArrowRight') {
  74. applyStyle('rtlRight');
  75. } else if (lastKeyPressed === 'r' && event.key === 'ArrowDown') {
  76. if (currentStyle) {
  77. disableStyle();
  78. }
  79. }
  80. lastKeyPressed = event.key;
  81. }
  82. });
  83.  
  84. document.addEventListener('keyup', (event) => {
  85. if (event.key === lastKeyPressed) {
  86. lastKeyPressed = '';
  87. }
  88. });
  89.  
  90. window.onload = () => {
  91. FapplyStyle('rtlRight');
  92. };
  93. })();