NickGPT

Use NickGPT on Google Search page!

当前为 2023-04-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name NickGPT
  3. // @namespace https://ugpt.nickname4th.vip/
  4. // @version 0.9
  5. // @description Use NickGPT on Google Search page!
  6. // @author InJeCTrL
  7. // @match *://www.google.com/search*
  8. // @match *://www.google.com.hk/search*
  9. // @match *://www.google.co.uk/search*
  10. // @match *://www.baidu.com*
  11. // @match *://www.baidu.com/s*
  12. // @match *://so.toutiao.com/search*
  13. // @match *://cn.bing.com/search*
  14. // @match *://www.bing.com/search*
  15. // @match *://duckduckgo.com/?*
  16. // @match *://www.so.com/s?*
  17. // @match *://www.sogou.com/*
  18. // @grant window.onurlchange
  19. // @grant GM_addElement
  20. // @grant GM_setValue
  21. // @grant GM_getValue
  22. // @icon https://s1.ax1x.com/2023/04/21/p9E40Ve.png
  23. // @require https://code.jquery.com/jquery-3.6.0.js
  24. // @require https://cdn.bootcdn.net/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js
  25. // @resource css https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css
  26. // @run-at document-end
  27. // @license MIT
  28. // ==/UserScript==
  29.  
  30. (function () {
  31. 'use strict';
  32.  
  33. function getSearchContent() {
  34. var url = window.location.href;
  35. if (url.indexOf("www.baidu.com") != -1) {
  36. return document.getElementById('kw').value;
  37. } else if (url.indexOf("www.google.") != -1) {
  38. return document.getElementsByTagName('textarea')[0].textContent;
  39. } else if (url.indexOf("so.toutiao.com") != -1) {
  40. return document.getElementsByTagName('input')[0].value;
  41. } else if (url.indexOf("bing.com") != -1) {
  42. return document.getElementById('sb_form_q').value;
  43. } else if (url.indexOf("duckduckgo.com") != -1) {
  44. return document.getElementById('search_form_input').value;
  45. } else if (url.indexOf("www.so.com") != -1) {
  46. return document.getElementById('keyword').value;
  47. } else if (url.indexOf("www.sogou.com") != -1) {
  48. return document.getElementById('upquery').value;
  49. }
  50. }
  51.  
  52. function searchKeyword() {
  53. document.getElementById('nickgpt-wnd')
  54. .contentWindow.postMessage({
  55. "nickGPT": getSearchContent()
  56. }, '*');
  57. }
  58.  
  59. function nickgptHandler(message) {
  60. if (message.data == "chatready") {
  61. searchKeyword();
  62. }
  63. }
  64.  
  65. function insertWnd() {
  66. var box = document.createElement("div");
  67. box.id = "nickgpt-box";
  68. if (window.location.href.indexOf("www.so.com") != -1) {
  69. document.body.firstElementChild.appendChild(box);
  70. } else {
  71. document.body.insertBefore(box, document.body.firstChild);
  72. }
  73.  
  74. var funcBtn = document.createElement("div");
  75. funcBtn.innerText = "停用NickGPT";
  76. funcBtn.id = "funcBtn";
  77. box.appendChild(funcBtn);
  78.  
  79. var enabled = GM_getValue("enabled_nickgpt");
  80. insertStyle(enabled);
  81. if (enabled === true) {
  82. var ifr = document.createElement("iframe");
  83. ifr.id = "nickgpt-wnd";
  84. ifr.src = "https://ugpt.nickname4th.vip";
  85. GM_addElement(box, 'iframe', {
  86. src: "https://ugpt.nickname4th.vip",
  87. id: "nickgpt-wnd"
  88. });
  89. window.addEventListener("message", nickgptHandler);
  90. funcBtn.onclick = function(){
  91. GM_setValue("enabled_nickgpt", false);
  92. window.location.reload();
  93. }
  94.  
  95. if (window.onurlchange === null &&
  96. (window.location.href.indexOf("www.so.com") != -1 || window.location.href.indexOf("www.baidu.com") != -1)) {
  97. window.addEventListener('urlchange', (info) => {
  98. searchKeyword();
  99. });
  100. }
  101. } else {
  102. funcBtn.innerText = "启用NickGPT";
  103. funcBtn.onclick = function(){
  104. GM_setValue("enabled_nickgpt", true);
  105. window.location.reload();
  106. }
  107. }
  108.  
  109. $(function () {
  110. $("#nickgpt-box").draggable();
  111. });
  112. }
  113.  
  114. function insertStyle(enabled) {
  115. if (enabled === true) {
  116. var css = "\
  117. #nickgpt-box {\
  118. border: 1px solid #cceff5;\
  119. position: fixed;\
  120. right: 10%;\
  121. top: 8%;\
  122. width: 30%;\
  123. height: 80%;\
  124. z-index: 998;\
  125. background: #1E90FF;\
  126. cursor: grab;\
  127. border-radius: 25px;\
  128. box-shadow: 1px 1px 1px 1px grey;\
  129. }\
  130. #nickgpt-wnd {\
  131. border: none;\
  132. width: 100%;\
  133. height: calc(100% - 40px);\
  134. z-index: 999;\
  135. background: white;\
  136. border-radius: 0px 0px 25px 25px;\
  137. }\
  138. #funcBtn {\
  139. float: right;\
  140. color: black;\
  141. height: 40px;\
  142. width: 110px;\
  143. font-size: 16px;\
  144. display: flex;\
  145. justify-content: center;\
  146. align-items:center;\
  147. background: #7FFFD4;\
  148. border-radius: 0px 25px 0px 0px;\
  149. cursor: pointer;\
  150. }";
  151. } else {
  152. var css = "\
  153. #nickgpt-box {\
  154. border: 1px solid #cceff5;\
  155. position: fixed;\
  156. right: 10%;\
  157. top: 8%;\
  158. width: 30%;\
  159. height: 40px;\
  160. z-index: 998;\
  161. background: #1E90FF;\
  162. cursor: grab;\
  163. border-radius: 25px;\
  164. box-shadow: 1px 1px 1px 1px grey;\
  165. }\
  166. #funcBtn {\
  167. float: right;\
  168. color: black;\
  169. height: 40px;\
  170. width: 110px;\
  171. font-size: 16px;\
  172. display: flex;\
  173. justify-content: center;\
  174. align-items:center;\
  175. background: #7FFFD4;\
  176. border-radius: 0px 25px 25px 0px;\
  177. cursor: pointer;\
  178. }";
  179. }
  180.  
  181. const style = document.createElement('style');
  182. style.type = 'text/css';
  183. style.appendChild(document.createTextNode(css));
  184. document.children[0].appendChild(style);
  185. }
  186.  
  187. insertWnd();
  188. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址