谷歌搜索、百度搜索、必应搜索的聚合跳转集合工具

最新版本的集合谷歌、百度、必应的搜索引擎跳转工具,必应跳转可在菜单进行自定义设置。此版本无外部脚本调用,更快速和准确的进行按钮定位,显示速度大大提升。如有异常请清空浏览器缓存,再次载入使用,感谢使用!

当前为 2020-12-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google & baidu Switcher (ALL in One)
  3. // @name:en Google & baidu & Bing Switcher (ALL in One)
  4. // @name:zh-CN 谷歌搜索、百度搜索、必应搜索的聚合跳转集合工具
  5. // @name:zh-TW 谷歌搜索、百度搜索、必應搜索的聚合跳轉集合工具
  6. // @version 2.0.20201201.1
  7. // @author F9y4ng
  8. // @description 最新版本的集合谷歌、百度、必应的搜索引擎跳转工具,必应跳转可在菜单进行自定义设置。此版本无外部脚本调用,更快速和准确的进行按钮定位,显示速度大大提升。如有异常请清空浏览器缓存,再次载入使用,感谢使用!
  9. // @description:zh-TW 最新版本的集合谷歌、百度、必應的搜索引擎跳轉工具,必應跳轉可在菜單進行自定義設置。此版本無外部腳本調用,更快速和準確的進行按鈕定位,顯示速度大大提升。如有異常請清空瀏覽器緩存,再次載入使用,感謝使用!
  10. // @description:en The latest version of Google, Baidu, Bing`s search engine, Bing option can be switched in the menu settings. If any exception or error, please clear the browser cache and reload it. again. Thank you!
  11. // @namespace https://openuserjs.org/scripts/t3xtf0rm4tgmail.com/Google_baidu_Switcher_(ALL_in_One)
  12. // @supportURL https://github.com/F9y4ng/GreasyFork-Scripts/issues
  13. // @icon https://www.google.com/favicon.ico
  14. // @include *://encrypted.google.*/search*
  15. // @include *://*.google*/search*
  16. // @include *://*.google*/webhp*
  17. // @include *://*.baidu.com/*
  18. // @include *://*.bing.com/*
  19. // @compatible Chrome 兼容TamperMonkey, ViolentMonkey
  20. // @compatible Firefox 兼容Greasemonkey, TamperMonkey, ViolentMonkey
  21. // @compatible Opera 兼容TamperMonkey, ViolentMonkey
  22. // @compatible Safari 兼容Tampermonkey • Safari
  23. // @grant GM_info
  24. // @grant GM_registerMenuCommand
  25. // @grant GM_unregisterMenuCommand
  26. // @grant GM_openInTab
  27. // @grant GM_getValue
  28. // @grant GM_setValue
  29. // @grant GM_notification
  30. // @license GPL-3.0-only
  31. // @create 2015-10-07
  32. // @copyright 2015-2020, F9y4ng
  33. // @run-at document-start
  34. // ==/UserScript==
  35.  
  36. 'use strict';
  37.  
  38. !(function () {
  39. let isdebug = false;
  40. let debug = isdebug ? console.log.bind(console) : function () {};
  41.  
  42. /* Perfectly Compatible For Greasemonkey, TamperMonkey, ViolentMonkey * F9y4ng * 20201127 */
  43.  
  44. let GMsetValue, GMgetValue, GMregisterMenuCommand, GMunregisterMenuCommand, GMnotification, GMopenInTab;
  45. const GMinfo = GM_info;
  46. let handlerInfo = GMinfo.scriptHandler;
  47. const isGM = Boolean(handlerInfo.toLowerCase() === 'greasemonkey');
  48.  
  49. debug('//-> CheckGM: ' + isGM + ' >> ' + handlerInfo);
  50.  
  51. if (isGM) {
  52. let Storage = window.localStorage;
  53. if (Storage) {
  54. GMsetValue = function (key, value) {
  55. Storage.setItem(key, value);
  56. };
  57. GMgetValue = function (key) {
  58. return Storage.getItem(key);
  59. };
  60. }
  61. GMregisterMenuCommand = function (caption, commandFunc, accessKey) {
  62. if (!document.body) {
  63. if (document.readyState === 'loading' && document.documentElement && document.documentElement.localName === 'html') {
  64. new MutationObserver(function (mutations, observer) {
  65. if (document.body) {
  66. observer.disconnect();
  67. GMregisterMenuCommand(caption, commandFunc, accessKey);
  68. debug('//-> Mutation: ' + mutations);
  69. }
  70. }).observe(document.documentElement, { childList: true });
  71. } else {
  72. debug('GMregisterMenuCommand got no body.');
  73. }
  74. return;
  75. }
  76. let contextMenu = document.body.getAttribute('contextmenu');
  77. let menu = contextMenu ? document.querySelector('menu#' + contextMenu) : null;
  78. if (!menu) {
  79. menu = document.createElement('menu');
  80. menu.setAttribute('id', 'gm-registered-menu');
  81. menu.setAttribute('type', 'context');
  82. document.body.appendChild(menu);
  83. document.body.setAttribute('contextmenu', 'gm-registered-menu');
  84. }
  85. let menuItem = document.createElement('menuitem');
  86. menuItem.setAttribute('icon', 'https://wiki.greasespot.net/favicon.ico');
  87. menuItem.textContent = caption;
  88. menuItem.addEventListener('click', commandFunc, true);
  89. menu.appendChild(menuItem);
  90. };
  91. GMunregisterMenuCommand = function () {
  92. let contextMenu = document.body.getAttribute('contextmenu');
  93. let menu = contextMenu ? document.querySelector('menu#' + contextMenu) : null;
  94. if (menu) {
  95. document.body.removeChild(menu);
  96. }
  97. };
  98. GMnotification = function (options) {
  99. const opts = {};
  100. if (typeof options === 'string') {
  101. opts.text = options;
  102. opts.title = arguments[1];
  103. opts.image = arguments[2];
  104. opts.onclick = arguments[3];
  105. } else {
  106. Object.keys(options).forEach(function (key) {
  107. opts[key] = options[key];
  108. });
  109. }
  110.  
  111. checkPermission();
  112.  
  113. function checkPermission() {
  114. if (Notification.permission === 'granted') {
  115. fireNotice(opts);
  116. } else if (Notification.permission === 'denied') {
  117. debug('//-> User has denied notifications for this page/site!');
  118. return;
  119. } else {
  120. Notification.requestPermission(function (permission) {
  121. debug('//-> New permission: ' + permission);
  122. checkPermission();
  123. });
  124. }
  125. }
  126.  
  127. function fireNotice(ntcOptions) {
  128. if (ntcOptions.text && !ntcOptions.body) {
  129. ntcOptions.body = ntcOptions.text;
  130. }
  131. let ntfctn = new Notification(ntcOptions.title, ntcOptions);
  132.  
  133. if (ntcOptions.onclick) {
  134. ntfctn.onclick = ntcOptions.onclick;
  135. }
  136. if (ntcOptions.timeout) {
  137. setTimeout(function () {
  138. ntfctn.close();
  139. }, ntcOptions.timeout);
  140. }
  141. }
  142. };
  143. GMopenInTab = function (a, b) {
  144. window.open(a, Math.random().toString(36).slice(-6), '', b instanceof String);
  145. };
  146. } else {
  147. GMsetValue = GM_setValue;
  148. GMgetValue = GM_getValue;
  149. GMregisterMenuCommand = GM_registerMenuCommand;
  150. GMunregisterMenuCommand = GM_unregisterMenuCommand;
  151. GMnotification = GM_notification;
  152. GMopenInTab = GM_openInTab;
  153. }
  154.  
  155. const defaultConfig = {
  156. Version: GMinfo.script.version,
  157. lastRuntime: new Date().toLocaleString('chinese', { hour12: false }),
  158. };
  159.  
  160. console.log(
  161. '%c[GB-Init]%c\nVersion: ' + defaultConfig.Version + '\nlastRuntime: ' + defaultConfig.lastRuntime,
  162. 'font-weight:bold;color:dodgerblue',
  163. 'color:0'
  164. );
  165.  
  166. !(function () {
  167. let CONST = {
  168. isSecurityPolicy: false,
  169. isUseBing: (function () {
  170. let temp = parseInt(GMgetValue('_if_Use_Bing_'));
  171. if (isNaN(temp)) {
  172. GMsetValue('_if_Use_Bing_', 0);
  173. console.log(
  174. '%c[GB-Warning]%c\nThis is your first visit, the Bing search button will not be inserted by default.',
  175. 'font-weight:bold;color:salmon',
  176. 'color:1'
  177. );
  178. return false;
  179. } else {
  180. return Boolean(temp);
  181. }
  182. })(),
  183. };
  184.  
  185. debug('//-> ' + CONST.isUseBing);
  186.  
  187. let curretSite = {
  188. SiteTypeID: 1,
  189. SiteName: '',
  190. SplitName: '',
  191. MainType: '',
  192. HtmlCode: '',
  193. StyleType: '',
  194. };
  195.  
  196. const listSite = {
  197. baidu: {
  198. SiteTypeID: 1,
  199. SiteName: 'Baidu',
  200. SplitName: 'tn',
  201. MainType: '.s_btn_wr',
  202. HtmlCode: CONST.isUseBing
  203. ? `
  204. <span id="ggyx">
  205. <input type="button" title="Google一下" value="Google"/>
  206. </span>
  207. <span id="bbyx">
  208. <input type="button" title="Bing一下" value="Bing ®"/>
  209. </span>`
  210. : `
  211. <span id="ggyx">
  212. <input type="button" title="Google一下" value="Google一下"/>
  213. </span>`,
  214. StyleCode: CONST.isUseBing
  215. ? `
  216. #form {
  217. white-space: nowrap;
  218. }
  219. #u {
  220. z-index: 1!important;
  221. }
  222. #for_Baidu #bbyx {
  223. margin-left: -1.5px;
  224. }
  225. #for_Baidu #ggyx {
  226. margin-left: 2px;
  227. }
  228. #bbyx input{
  229. background: #4e6ef2;
  230. border-top-right-radius: 10px;
  231. border-bottom-right-radius: 10px;
  232. cursor: pointer;
  233. height: 40px;
  234. color: #fff;
  235. width: 80px;
  236. border: 1px solid #3476d2;
  237. font-size: 16px;
  238. font-weight:bold;
  239. }
  240. #ggyx input {
  241. background: #4e6ef2;
  242. border-top-left-radius: 10px;
  243. border-bottom-left-radius: 10px;
  244. cursor: pointer;
  245. height: 40px;
  246. color: #fff;
  247. width: 80px;
  248. border: 1px solid #3476d2;
  249. font-size: 16px;
  250. font-weight:bold;
  251. }
  252. #ggyx input:hover, #bbyx input:hover {
  253. background: #4662D9;
  254. border: 1px solid #3476d2;
  255. }`
  256. : `
  257. #form {
  258. white-space: nowrap;
  259. }
  260. #u {
  261. z-index: 1!important;
  262. }
  263. #for_Baidu {
  264. margin-left: 6px
  265. }
  266. #ggyx input {
  267. background: #4e6ef2;
  268. border-radius: 10px;
  269. cursor: pointer;
  270. height: 40px;
  271. color: #fff;
  272. width: 112px;
  273. border: 1px solid #3476d2;
  274. text-shadow: 0 0 2px #ffffff!important;
  275. font-size: 16px
  276. }
  277. #ggyx input:hover {
  278. background: #4662D9;
  279. border: 1px solid #3476d2;
  280. }`,
  281. },
  282. google: {
  283. SiteTypeID: 2,
  284. SiteName: 'Google',
  285. SplitName: 'tbm',
  286. MainType: "form button[type='submit']",
  287. HtmlCode: CONST.isUseBing
  288. ? `
  289. <span id="bdyx">
  290. <input type="button" title="百度一下" value="百度一下"/>
  291. </span>
  292. <span id="bbyx">
  293. <input type="button" title="Bing一下" value="Bing一下"/>
  294. </span>`
  295. : `
  296. <span id="bdyx">
  297. <input type="button" title="百度一下" value="百度一下"/>
  298. </span>`,
  299. StyleCode: CONST.isUseBing
  300. ? `
  301. #for_Google {
  302. margin: 3px 4px 0 -5px;
  303. }
  304. #for_Google #bdyx {
  305. padding:5px 0 4px 18px;
  306. border-left:1px solid #ddd;
  307. }
  308. #for_Google #bbyx {
  309. margin-left:-2px
  310. }
  311. .scrollspan{
  312. padding:1px 0 0 18px!important
  313. }
  314. .scrollbars {
  315. height: 26px!important;
  316. font-size: 13px!important;
  317. font-weight: normal!important;
  318. text-shadow: 0 0 1px #ffffff!important;
  319. }
  320. #bdyx input {
  321. cursor: pointer;
  322. padding: 1px 1px 1px 6px!important;
  323. border: 1px solid transparent;
  324. background: #1a73e8;
  325. box-shadow: none;
  326. border-top-left-radius: 24px;
  327. border-bottom-left-radius: 24px;
  328. width: 90px;
  329. height: 38px;
  330. font-size: 15px;
  331. font-weight: 600;
  332. color: #fff
  333. }
  334. #bbyx input {
  335. cursor: pointer;
  336. padding: 1px 6px 1px 1px!important;
  337. border: 1px solid transparent;
  338. background: #1a73e8;
  339. box-shadow: none;
  340. border-top-right-radius: 24px;
  341. border-bottom-right-radius: 24px;
  342. width: 90px;
  343. height: 38px;
  344. font-size: 15px;
  345. font-weight: 600;
  346. color: #fff
  347. }
  348. #bdyx input:hover, #bbyx input:hover {
  349. background: #2b7de9;
  350. }`
  351. : `
  352. #for_Google {
  353. margin: 3px 4px 0 -5px;
  354. }
  355. #for_Google #bdyx {
  356. padding:5px 0 4px 18px;
  357. border-left:1px solid #ddd;
  358. }
  359. .scrollspan{
  360. padding:1px 0 0 18px!important
  361. }
  362. .scrollbars {
  363. height: 26px!important;
  364. font-size: 13px!important;
  365. font-weight: normal!important;
  366. text-shadow: 0 0 1px #ffffff!important;
  367. }
  368. #bdyx input {
  369. cursor: pointer;
  370. border: 1px solid transparent;
  371. background: #1a73e8;
  372. box-shadow: none;
  373. border-radius: 24px;
  374. width: 90px;
  375. height: 38px;
  376. font-size: 14px;
  377. font-weight: 600;
  378. color: #ffffff;
  379. }
  380. #bdyx input:hover {
  381. background: #2b7de9;
  382. }`,
  383. },
  384. bing: {
  385. SiteTypeID: 3,
  386. SiteName: 'Bing',
  387. SplitName: 'undefined',
  388. MainType: '#sb_go_par',
  389. HtmlCode: `
  390. <span id="bdyx">
  391. <input type="button" title="百度一下" value="百度"/>
  392. </span>
  393. <span id="ggyx">
  394. <input type="button" title="Google一下" value="Google"/>
  395. </span>`,
  396. StyleCode: `
  397. #for_Bing {
  398. height: 44px;
  399. width: 120px;
  400. margin: 2px 10px 2px 0;
  401. }
  402. #bdyx input, #ggyx input {
  403. cursor: pointer;
  404. width: auto 60px;
  405. height: 36px;
  406. background-color: #f7faff;
  407. border: 1px solid #b4ddea;
  408. color: #2996b0;
  409. margin-left: -2px;
  410. font-family: 'Microsoft YaHei'!important;
  411. text-shadow: 1px 1px 2px #999!important;
  412. font-size: 16px;
  413. }
  414. #bdyx input:hover, #ggyx input:hover {
  415. background-color: #ffffff;
  416. transition:border linear .1s,box-shadow linear .3s;
  417. box-shadow: 1px 1px 8px #5f5f5f;
  418. border: 2px solid #00809d;
  419. text-shadow: 0 0 1px #00809d!important;
  420. color:#00809d;
  421. }`,
  422. },
  423. other: { SiteTypeID: 0 },
  424. };
  425.  
  426. let newSiteType = {
  427. BAIDU: listSite.baidu.SiteTypeID,
  428. GOOGLE: listSite.google.SiteTypeID,
  429. BING: listSite.bing.SiteTypeID,
  430. OTHERS: 0,
  431. };
  432.  
  433. debug('//-> The program begins to execution phase.');
  434.  
  435. if (location.host.includes('.baidu.com')) {
  436. curretSite = listSite.baidu;
  437. } else if (location.host.includes('google')) {
  438. curretSite = listSite.google;
  439. } else if (location.host.includes('bing')) {
  440. curretSite = listSite.bing;
  441. } else {
  442. curretSite = listSite.other;
  443. }
  444. if (
  445. (curretSite.SiteTypeID === newSiteType.GOOGLE && location.href.replace(/tbm=(isch|lcl|flm)/, '') !== location.href) ||
  446. (curretSite.SiteTypeID === newSiteType.BING && location.href.replace(/maps\?/, '') !== location.href) ||
  447. (curretSite.SiteTypeID === newSiteType.BAIDU &&
  448. (/(b2b|map|wenku|tieba)/.test(location.hostname) ||
  449. location.href.replace(/tn=(baiduimage|news|ikaslist|vsearch)/, '') !== location.href))
  450. ) {
  451. CONST.isSecurityPolicy = true;
  452. }
  453.  
  454. let menuManager = {
  455. menuDisplay: function () {
  456. let _Use_Bing_ = CONST.isUseBing;
  457. let _use_Bing_ID, in_Use_feedBack_ID;
  458.  
  459. registerMenuCommand();
  460. debug('//-> ' + _Use_Bing_);
  461.  
  462. function registerMenuCommand() {
  463. let _Use_Bing__;
  464. if (in_Use_feedBack_ID) {
  465. GMunregisterMenuCommand(_use_Bing_ID);
  466. GMunregisterMenuCommand(in_Use_feedBack_ID);
  467. }
  468. if (_Use_Bing_) {
  469. _Use_Bing__ = '√';
  470. } else {
  471. _Use_Bing__ = '×';
  472. }
  473. _use_Bing_ID = GMregisterMenuCommand(` [${_Use_Bing__}] \u6dfb\u52a0 Bing \u641c\u7d22\u8df3\u8f6c`, function () {
  474. inUse_switch(_Use_Bing_, '_if_Use_Bing_', 'Bing\u6309\u94ae');
  475. });
  476. in_Use_feedBack_ID = GMregisterMenuCommand('\u4f7f\u7528\u53cd\u9988', function () {
  477. GMopenInTab('https://greasyfork.org/zh-CN/scripts/12909-google-baidu-switcher-all-in-one/feedback', {
  478. active: true,
  479. insert: true,
  480. setParent: true,
  481. });
  482. });
  483.  
  484. console.log(
  485. '%c[GB-Status]%c\nInsert the Bing Search Button: %c%s%c',
  486. 'font-weight:bold;color:darkorange',
  487. 'color:0',
  488. 'font-weight:bold;color:red',
  489. _Use_Bing_.toString().toUpperCase(),
  490. 'font-weight:normal;color:0'
  491. );
  492. }
  493.  
  494. function inUse_switch(_status, Name, Tips) {
  495. const title = `\u6e29\u99a8\u63d0\u793a\uff1a`;
  496. if (_status) {
  497. GMsetValue(`${Name}`, 0);
  498. GMnotification(`${Tips}\u5df2\u5173\u95ed\uff0c\u4e09\u79d2\u540e\u5c06\u5237\u65b0\uff01`, title);
  499. } else {
  500. GMsetValue(`${Name}`, 1);
  501. GMnotification(`${Tips}\u5df2\u5f00\u542f\uff0c\u4e09\u79d2\u540e\u5c06\u5237\u65b0\uff01`, title);
  502. }
  503. registerMenuCommand();
  504. window.setTimeout(function () {
  505. let loc = location.href.replace(/&timestamp=(\d+)/, '');
  506. location.replace(loc + `&timestamp=` + new Date().getTime());
  507. }, 3000);
  508. }
  509. },
  510. init: function () {
  511. this.menuDisplay();
  512. },
  513. };
  514.  
  515. let searchManager = {
  516. doSwitch: function () {
  517. try {
  518. const idName = '#for_' + curretSite.SiteName;
  519. if (curretSite.SiteTypeID !== newSiteType.OTHERS) {
  520. if (CONST.isSecurityPolicy) {
  521. console.log(
  522. '%c[GB-Prohibit]%c\nBlocked By: %c%s Security Policy%c.',
  523. 'font-weight:bold;color:indigo',
  524. 'color:0',
  525. 'color:darkred',
  526. curretSite.SiteName,
  527. 'color:0'
  528. );
  529. return;
  530. } else {
  531. if (curretSite.SiteTypeID === newSiteType.BAIDU) {
  532. document.addEventListener('DOMNodeInserted', Callback, false);
  533. }
  534. RAFInterval(
  535. function () {
  536. if (document.querySelector(idName) === null) {
  537. return insertSearchButton() && scrollDetect();
  538. }
  539. },
  540. 500,
  541. true
  542. );
  543.  
  544. console.log(
  545. '%c[GB-Switch]%c\nWe Are Using The %c%s%c Search Engine.',
  546. 'font-weight:bold;color:Green',
  547. 'color:0',
  548. 'font-weight:bold;color:darkcyan',
  549. curretSite.SiteName,
  550. 'font-weight:normal;color:0'
  551. );
  552. }
  553. }
  554. } catch (e) {
  555. debug('//-> ' + e.name);
  556. }
  557.  
  558. function Callback(e) {
  559. if (e.target !== null && typeof e.target.className === 'string' && e.target.className.indexOf('InsertTo') === 0) {
  560. return;
  561. }
  562. setTimeout(function () {
  563. insertSearchButton();
  564. }, 100);
  565. }
  566.  
  567. function insertSearchButton() {
  568. try {
  569. const getTarget = curretSite.MainType;
  570. const doHtml = curretSite.HtmlCode;
  571. const doStyName = 'InsertTo' + curretSite.SiteName;
  572. const doStyle = curretSite.StyleCode;
  573. const vim = GetUrlParam(curretSite.SplitName);
  574. const userSpan = document.createElement('span');
  575. let Target = document.querySelector(getTarget);
  576. userSpan.id = 'for_' + curretSite.SiteName;
  577. userSpan.innerHTML = doHtml;
  578. const SpanID = '#' + userSpan.id;
  579.  
  580. addStyle(doStyle, doStyName, 'head', true);
  581.  
  582. if (document.querySelector(SpanID) === null && getSearchValue().length > 0) {
  583. if (/^(nws|vid|fin|bks)$/.test(vim.trim())) {
  584. Target = Target.parentNode.parentNode.firstChild;
  585. Target.insertBefore(userSpan, Target.firstChild);
  586. document.querySelector(SpanID).setAttribute('style', 'float:right');
  587. debug('//-> ' + Target);
  588. } else {
  589. insterAfter(userSpan, Target);
  590. }
  591. document.querySelectorAll('#ggyx, #bbyx, #bdyx').forEach(function (per) {
  592. per.addEventListener('click', function () {
  593. let gotoUrl = 'about:blank';
  594. switch (per.id) {
  595. case 'ggyx':
  596. gotoUrl = 'https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp&q=';
  597. break;
  598. case 'bbyx':
  599. gotoUrl = 'https://cn.bing.com/search?q=';
  600. break;
  601. case 'bdyx':
  602. gotoUrl = 'https://www.baidu.com/s?ie=utf-8&rqlang=cn&wd=';
  603. break;
  604. default:
  605. break;
  606. }
  607. debug('//-> ' + per.id);
  608. GMopenInTab(decodeURI(gotoUrl + getSearchValue()), {
  609. active: true,
  610. insert: true,
  611. setParent: true,
  612. });
  613. });
  614. });
  615. }
  616. return true;
  617. } catch (e) {
  618. debug('//-> ' + e.name);
  619. return false;
  620. }
  621. }
  622.  
  623. function scrollDetect() {
  624. try {
  625. if (curretSite.SiteTypeID === newSiteType.GOOGLE) {
  626. const nodeName = '#for_' + curretSite.SiteName;
  627. debug('//-> Turn on google scrolling detecting.');
  628. if (document.querySelector(nodeName).parentNode) {
  629. document.querySelector(nodeName).parentNode.setAttribute('style', 'width:700px!important');
  630. }
  631. scrollButton(nodeName + ' #bdyx', 'scrollspan');
  632. scrollButton(nodeName + ' #bdyx input', 'scrollbars');
  633. if (CONST.isUseBing) {
  634. scrollButton(nodeName + ' #bbyx input', 'scrollbars');
  635. }
  636. }
  637. return true;
  638. } catch (e) {
  639. debug('//-> ' + e.name);
  640. return false;
  641. }
  642. }
  643.  
  644. function scrollButton(paraName, classNameIn) {
  645. let oDiv = document.querySelector(paraName);
  646. let H = 0;
  647. let Y = oDiv;
  648. if (Y !== null) {
  649. while (Y) {
  650. H += Y.offsetTop;
  651. Y = Y.offsetParent;
  652. }
  653. document.addEventListener('scroll', function () {
  654. let s = document.body.scrollTop || document.documentElement.scrollTop;
  655. debug('//-> H-' + H);
  656. debug('//-> S-' + s);
  657. if (s > H + 35) {
  658. oDiv.setAttribute('class', classNameIn);
  659. } else {
  660. oDiv.removeAttribute('class');
  661. }
  662. });
  663. }
  664. }
  665.  
  666. function addStyle(css, className, addToTarget, isReload, initType) {
  667. RAFInterval(
  668. function () {
  669. let addTo = document.querySelector(addToTarget);
  670. if (typeof addToTarget === 'undefined') {
  671. addTo = document.head || document.body || document.documentElement || document;
  672. }
  673. isReload = isReload || false;
  674. initType = initType || 'text/css';
  675. if (
  676. typeof addToTarget === 'undefined' ||
  677. (typeof addToTarget !== 'undefined' && document.querySelector(addToTarget) !== null)
  678. ) {
  679. if (isReload === true) {
  680. safeRemove('.' + className);
  681. } else if (isReload === false && document.querySelector('.' + className) !== null) {
  682. return true;
  683. }
  684. let cssNode = document.createElement('style');
  685. if (className !== null) {
  686. cssNode.className = className;
  687. }
  688. cssNode.setAttribute('type', initType);
  689. cssNode.innerHTML = css;
  690. try {
  691. addTo.appendChild(cssNode);
  692. } catch (e) {
  693. debug('//-> ' + e.name);
  694. }
  695. return true;
  696. }
  697. },
  698. 20,
  699. true
  700. );
  701. }
  702.  
  703. function safeRemove(Css) {
  704. safeFunction(() => {
  705. let removeNodes = document.querySelectorAll(Css);
  706. for (let i = 0; i < removeNodes.length; i++) {
  707. removeNodes[i].remove();
  708. }
  709. });
  710. }
  711.  
  712. function safeFunction(func) {
  713. try {
  714. func();
  715. } catch (e) {
  716. debug('//-> ' + e.name);
  717. }
  718. }
  719.  
  720. function getSearchValue() {
  721. let val = '';
  722. document.querySelectorAll('input[name="wd"], input[name="q"]').forEach(function (things) {
  723. val = things.getAttribute('value');
  724. debug('//-> INPUT:' + val);
  725. });
  726. if (val === null || val === '' || typeof val === 'undefined') {
  727. let kvl = location.search.substr(1).split('&');
  728. for (let i = 0; i < kvl.length; i++) {
  729. let value = kvl[i].replace(/^(wd|word|kw|query|q)=/, '');
  730. if (value !== kvl[i]) {
  731. val = value;
  732. }
  733. }
  734. val = val.replace('+', ' ');
  735. debug('//-> QUERY:' + val);
  736. }
  737. return encodeURIComponent(val);
  738. }
  739.  
  740. function RAFInterval(callback, period, runNow) {
  741. const needCount = (period / 1000) * 60;
  742. let times = 0;
  743. if (runNow === true) {
  744. const shouldFinish = callback();
  745. if (shouldFinish) {
  746. return;
  747. }
  748. }
  749.  
  750. function step() {
  751. if (times < needCount) {
  752. times++;
  753. requestAnimationFrame(step);
  754. } else {
  755. const shouldFinish = callback() || false;
  756. if (!shouldFinish) {
  757. times = 0;
  758. requestAnimationFrame(step);
  759. } else {
  760. return;
  761. }
  762. }
  763. }
  764. requestAnimationFrame(step);
  765. }
  766.  
  767. function insterAfter(newElement, targetElement) {
  768. let parent = targetElement.parentNode;
  769. if (parent.lastChild === targetElement) {
  770. parent.appendChild(newElement);
  771. } else {
  772. parent.insertBefore(newElement, targetElement.nextSibling);
  773. }
  774. }
  775.  
  776. function GetUrlParam(paraName) {
  777. if (paraName === 'undefined') {
  778. const parameter = document.location.pathname.toString();
  779. let arr = parameter.split('/');
  780. return arr[1];
  781. } else {
  782. const url = document.location.toString();
  783. let arrObj = url.split('?');
  784. if (arrObj.length > 1) {
  785. let arrPara = arrObj[1].split('&');
  786. let arr;
  787. for (let i = 0; i < arrPara.length; i++) {
  788. arr = arrPara[i].split('=');
  789. if (arr !== null && arr[0] === paraName) {
  790. return arr[1];
  791. }
  792. }
  793. return '';
  794. } else {
  795. return '';
  796. }
  797. }
  798. }
  799. },
  800.  
  801. init: function () {
  802. debug('//-> Call the load menu option.');
  803. menuManager.init();
  804. debug('//-> Execute insert jump button.');
  805. this.doSwitch();
  806. },
  807. };
  808.  
  809. (function () {
  810. try {
  811. searchManager.init();
  812. } catch (e) {
  813. console.error(
  814. '%c[GB-Error]%c\nConsole: %c%s%c.',
  815. 'font-weight:bold;color:red',
  816. 'color:0',
  817. 'font-weight:bold;color:darkred',
  818. e,
  819. 'color:0'
  820. );
  821. }
  822. })();
  823. })();
  824. })();