NickGPT

Use NickGPT on Google Search page!

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

QingJ © 2025

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