Show Location on ChatGPT

在ChatGPT官方网站的顶部显示当前用户IP所在的地区,如果是非ChatGPT支持的地区会红色标识提示,以免被封号。

  1. // ==UserScript==
  2. // @name Show Location on ChatGPT
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description 在ChatGPT官方网站的顶部显示当前用户IP所在的地区,如果是非ChatGPT支持的地区会红色标识提示,以免被封号。
  6. // @author Daotin
  7. // @match https://chat.openai.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=chat.openai.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Define the list of regions to check against
  17. const regions = [
  18. "Albania",
  19. "Algeria",
  20. "Andorra",
  21. "Angola",
  22. "Antigua and Barbuda",
  23. "Argentina",
  24. "Armenia",
  25. "Australia",
  26. "Austria",
  27. "Azerbaijan",
  28. "Bahamas",
  29. "Bangladesh",
  30. "Barbados",
  31. "Belgium",
  32. "Belize",
  33. "Benin",
  34. "Bhutan",
  35. "Bolivia",
  36. "Bosnia and Herzegovina",
  37. "Botswana",
  38. "Brazil",
  39. "Brunei",
  40. "Bulgaria",
  41. "Burkina Faso",
  42. "Cabo Verde",
  43. "Canada",
  44. "Chile",
  45. "Colombia",
  46. "Comoros",
  47. "Congo (Congo-Brazzaville)",
  48. "Costa Rica",
  49. "Côte d'Ivoire",
  50. "Croatia",
  51. "Cyprus",
  52. "Czechia (Czech Republic)",
  53. "Denmark",
  54. "Djibouti",
  55. "Dominica",
  56. "Dominican Republic",
  57. "Ecuador",
  58. "El Salvador",
  59. "Estonia",
  60. "Fiji",
  61. "Finland",
  62. "France",
  63. "Gabon",
  64. "Gambia",
  65. "Georgia",
  66. "Germany",
  67. "Ghana",
  68. "Greece",
  69. "Grenada",
  70. "Guatemala",
  71. "Guinea",
  72. "Guinea-Bissau",
  73. "Guyana",
  74. "Haiti",
  75. "Holy See (Vatican City)",
  76. "Honduras",
  77. "Hungary",
  78. "Iceland",
  79. "India",
  80. "Indonesia",
  81. "Iraq",
  82. "Ireland",
  83. "Israel",
  84. "Italy",
  85. "Jamaica",
  86. "Japan",
  87. "Jordan",
  88. "Kazakhstan",
  89. "Kenya",
  90. "Kiribati",
  91. "Kuwait",
  92. "Kyrgyzstan",
  93. "Latvia",
  94. "Lebanon",
  95. "Lesotho",
  96. "Liberia",
  97. "Liechtenstein",
  98. "Lithuania",
  99. "Luxembourg",
  100. "Madagascar",
  101. "Malawi",
  102. "Malaysia",
  103. "Maldives",
  104. "Mali",
  105. "Malta",
  106. "Marshall Islands",
  107. "Mauritania",
  108. "Mauritius",
  109. "Mexico",
  110. "Micronesia",
  111. "Moldova",
  112. "Monaco",
  113. "Mongolia",
  114. "Montenegro",
  115. "Morocco",
  116. "Mozambique",
  117. "Myanmar",
  118. "Namibia",
  119. "Nauru",
  120. "Nepal",
  121. "Netherlands",
  122. "New Zealand",
  123. "Nicaragua",
  124. "Niger",
  125. "Nigeria",
  126. "North Macedonia",
  127. "Norway",
  128. "Oman",
  129. "Pakistan",
  130. "Palau",
  131. "Palestine",
  132. "Panama",
  133. "Papua New Guinea",
  134. "Paraguay",
  135. "Peru",
  136. "Philippines",
  137. "Poland",
  138. "Portugal",
  139. "Qatar",
  140. "Romania",
  141. "Rwanda",
  142. "Saint Kitts and Nevis",
  143. "Saint Lucia",
  144. "Saint Vincent and the Grenadines",
  145. "Samoa",
  146. "San Marino",
  147. "Sao Tome and Principe",
  148. "Senegal",
  149. "Serbia",
  150. "Seychelles",
  151. "Sierra Leone",
  152. "Singapore",
  153. "Slovakia",
  154. "Slovenia",
  155. "Solomon Islands",
  156. "South Africa",
  157. "South Korea",
  158. "Spain",
  159. "Sri Lanka",
  160. "Suriname",
  161. "Sweden",
  162. "Switzerland",
  163. "Taiwan",
  164. "Tanzania",
  165. "Thailand",
  166. "Timor-Leste (East Timor)",
  167. "Togo",
  168. "Tonga",
  169. "Trinidad and Tobago",
  170. "Tunisia",
  171. "Turkey",
  172. "Tuvalu",
  173. "Uganda",
  174. "Ukraine (with certain exceptions)",
  175. "United Arab Emirates",
  176. "United Kingdom",
  177. "United States of America",
  178. "Uruguay",
  179. "Vanuatu",
  180. "Zambia"
  181. ];
  182.  
  183. // Your code here...
  184. // Make an HTTP request to https://chat.openai.com/cdn-cgi/trace
  185. fetch('https://chat.openai.com/cdn-cgi/trace')
  186. .then(response => response.text())
  187. .then(data => {
  188. // Extract the user's location and IP address from the returned string
  189. const locationRegex = /loc=([a-zA-Z]+)/;
  190. const countryCode = data.match(locationRegex)[1];
  191. const ipRegex = /ip=([0-9\.]+)/;
  192. const ipAddress = data.match(ipRegex)[1];
  193.  
  194. // Make an HTTP request to the REST Countries API to get the full country name
  195. fetch(`https://restcountries.com/v3.1/alpha/${countryCode}`)
  196. .then(response => response.json())
  197. .then(data => {
  198. const countryName = data[0]?.name?.official || data[0]?.name?.common;
  199.  
  200. // 循环regions,判断countryName是否包含regions中的元素
  201. const isInRegion = regions.some(region => countryName.includes(region));
  202.  
  203. // Display the user's location and IP address at the top of the browser
  204. const locationDiv = document.createElement('div');
  205. locationDiv.textContent = `Your location: ${countryName} (${ipAddress}) ${isInRegion ? '✅' : '⛔'}`;
  206. locationDiv.style.position = 'fixed';
  207. locationDiv.style.top = '10px';
  208. locationDiv.style.left = '50%';
  209. locationDiv.style.transform = 'translateX(-50%)';
  210. locationDiv.style.padding = '10px 20px';
  211. locationDiv.style.backgroundColor = isInRegion ? '#10a37fb3' : '#ef4146b3';
  212. locationDiv.style.color = '#fff';
  213. locationDiv.style.fontSize = '16px';
  214. locationDiv.style.fontWeight = 'bold';
  215. locationDiv.style.textAlign = 'center';
  216. locationDiv.style.zIndex = '9999';
  217. locationDiv.style.borderRadius = '8px';
  218. document.body.appendChild(locationDiv);
  219.  
  220. // Add a close button to the locationDiv
  221. const closeButton = document.createElement('div');
  222. closeButton.textContent = '×';
  223. closeButton.style.position = 'absolute';
  224. closeButton.style.top = '-3px';
  225. closeButton.style.right = '-6px';
  226. closeButton.style.backgroundColor = 'rgba(231, 195, 195, 0.5)';
  227. closeButton.style.border = 'none';
  228. closeButton.style.color = '#fff';
  229. closeButton.style.fontSize = '16px';
  230. closeButton.style.cursor = 'pointer';
  231. closeButton.style.borderRadius = '50%';
  232. closeButton.style.width = '16px';
  233. closeButton.style.height = '16px';
  234. closeButton.style.lineHeight = '16px';
  235. closeButton.style.textAlign = 'center';
  236. locationDiv.appendChild(closeButton);
  237.  
  238. // Add a click event listener to the closeButton to remove the locationDiv
  239. closeButton.addEventListener('click', () => {
  240. locationDiv.remove();
  241. });
  242. });
  243. });
  244. })();