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

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

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

  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.20201219.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) : () => {};
  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 = (key, value) => {
  55. Storage.setItem(key, value);
  56. };
  57. GMgetValue = key => {
  58. return Storage.getItem(key);
  59. };
  60. }
  61. GMregisterMenuCommand = (caption, commandFunc, accessKey) => {
  62. if (!document.body) {
  63. if (document.readyState === 'loading' && document.documentElement && document.documentElement.localName === 'html') {
  64. new MutationObserver((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 = () => {
  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 = 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(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(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(() => {
  138. ntfctn.close();
  139. }, ntcOptions.timeout);
  140. }
  141. }
  142. };
  143. GMopenInTab = (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: (() => {
  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: #fff;
  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: #fff;
  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.com')) {
  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) || location.href.replace(/tn=(baiduimage|news|ikaslist|vsearch)/, '') !== location.href))
  449. ) {
  450. CONST.isSecurityPolicy = true;
  451. }
  452.  
  453. let menuManager = {
  454. menuDisplay: function () {
  455. let _Use_Bing_ = CONST.isUseBing;
  456. let _use_Bing_ID, in_Use_feedBack_ID;
  457.  
  458. registerMenuCommand();
  459. debug('//-> ' + _Use_Bing_);
  460.  
  461. function registerMenuCommand() {
  462. let _Use_Bing__;
  463. if (in_Use_feedBack_ID) {
  464. GMunregisterMenuCommand(_use_Bing_ID);
  465. GMunregisterMenuCommand(in_Use_feedBack_ID);
  466. }
  467. if (_Use_Bing_) {
  468. _Use_Bing__ = '√';
  469. } else {
  470. _Use_Bing__ = '×';
  471. }
  472. _use_Bing_ID = GMregisterMenuCommand(` [${_Use_Bing__}] \u6dfb\u52a0 Bing \u641c\u7d22\u8df3\u8f6c`, () => {
  473. inUse_switch(_Use_Bing_, '_if_Use_Bing_', 'Bing\u6309\u94ae');
  474. });
  475. in_Use_feedBack_ID = GMregisterMenuCommand('\u4f7f\u7528\u53cd\u9988', () => {
  476. GMopenInTab('https://greasyfork.org/zh-CN/scripts/12909-google-baidu-switcher-all-in-one/feedback', {
  477. active: true,
  478. insert: true,
  479. setParent: true,
  480. });
  481. });
  482.  
  483. console.log(
  484. '%c[GB-Status]%c\nInsert the Bing Search Button: %c%s%c',
  485. 'font-weight:bold;color:darkorange',
  486. 'color:0',
  487. 'font-weight:bold;color:red',
  488. _Use_Bing_.toString().toUpperCase(),
  489. 'font-weight:normal;color:0'
  490. );
  491. }
  492.  
  493. function inUse_switch(_status, Name, Tips) {
  494. const title = `\u6e29\u99a8\u63d0\u793a\uff1a`;
  495. if (_status) {
  496. GMsetValue(`${Name}`, 0);
  497. GMnotification(`${Tips}\u5df2\u5173\u95ed\uff0c\u4e09\u79d2\u540e\u5c06\u5237\u65b0\uff01`, title);
  498. } else {
  499. GMsetValue(`${Name}`, 1);
  500. GMnotification(`${Tips}\u5df2\u5f00\u542f\uff0c\u4e09\u79d2\u540e\u5c06\u5237\u65b0\uff01`, title);
  501. }
  502. registerMenuCommand();
  503. setTimeout(() => {
  504. let loc = location.href.replace(/&timestamp=(\d+)/, '');
  505. location.replace(loc + `&timestamp=` + new Date().getTime());
  506. }, 3000);
  507. }
  508. },
  509. init: function () {
  510. this.menuDisplay();
  511. },
  512. };
  513.  
  514. let searchManager = {
  515. doSwitch: function () {
  516. try {
  517. const idName = '#for_' + curretSite.SiteName;
  518. if (curretSite.SiteTypeID !== newSiteType.OTHERS) {
  519. if (CONST.isSecurityPolicy) {
  520. console.log(
  521. '%c[GB-Prohibit]%c\nBlocked By: %c%s Security Policy%c.',
  522. 'font-weight:bold;color:indigo',
  523. 'color:0',
  524. 'color:darkred',
  525. curretSite.SiteName,
  526. 'color:0'
  527. );
  528. return;
  529. } else {
  530. RAFInterval(
  531. () => {
  532. if (document.querySelector(idName) === null) {
  533. return insertSearchButton() && scrollDetect();
  534. }
  535. },
  536. 500,
  537. true
  538. );
  539. if (curretSite.SiteTypeID === newSiteType.BAIDU) {
  540. const callback = () => {
  541. if (document.querySelector('.InsertTo' + curretSite.SiteName)) {
  542. debug('//-> found with selector ["InsertTo' + curretSite.SiteName + '"]');
  543. } else {
  544. insertSearchButton();
  545. }
  546. };
  547. const opts = { childList: true, subtree: true };
  548. new MutationObserver(callback).observe(document, opts);
  549. }
  550. console.log(
  551. '%c[GB-Switch]%c\nWe Are Using The %c%s%c Search Engine.',
  552. 'font-weight:bold;color:Green',
  553. 'color:0',
  554. 'font-weight:bold;color:darkcyan',
  555. curretSite.SiteName,
  556. 'font-weight:normal;color:0'
  557. );
  558. }
  559. }
  560. } catch (e) {
  561. debug('//-> ' + e.name);
  562. }
  563.  
  564. function insertSearchButton() {
  565. try {
  566. const getTarget = curretSite.MainType;
  567. const doHtml = curretSite.HtmlCode;
  568. const doStyName = 'InsertTo' + curretSite.SiteName;
  569. const doStyle = curretSite.StyleCode;
  570. const vim = GetUrlParam(curretSite.SplitName);
  571. const userSpan = document.createElement('span');
  572. let Target = document.querySelector(getTarget);
  573. userSpan.id = 'for_' + curretSite.SiteName;
  574. userSpan.innerHTML = doHtml;
  575. const SpanID = '#' + userSpan.id;
  576.  
  577. addStyle(doStyle, doStyName, 'head', true);
  578.  
  579. if (document.querySelector(SpanID) === null && getSearchValue().length > 0) {
  580. if (/^(nws|vid|fin|bks)$/.test(vim.trim())) {
  581. Target = Target.parentNode.parentNode.firstChild;
  582. Target.insertBefore(userSpan, Target.firstChild);
  583. document.querySelector(SpanID).setAttribute('style', 'float:right');
  584. debug('//-> ' + Target);
  585. } else {
  586. insterAfter(userSpan, Target);
  587. }
  588. document.querySelectorAll('#ggyx, #bbyx, #bdyx').forEach(per => {
  589. per.addEventListener('click', () => {
  590. let gotoUrl = 'about:blank';
  591. switch (per.id) {
  592. case 'ggyx':
  593. gotoUrl = 'https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp&q=';
  594. break;
  595. case 'bbyx':
  596. gotoUrl = 'https://cn.bing.com/search?q=';
  597. break;
  598. case 'bdyx':
  599. gotoUrl = 'https://www.baidu.com/s?ie=utf-8&rqlang=cn&wd=';
  600. break;
  601. default:
  602. break;
  603. }
  604. debug('//-> ' + per.id);
  605. GMopenInTab(decodeURI(gotoUrl + getSearchValue()), {
  606. active: true,
  607. insert: true,
  608. setParent: true,
  609. });
  610. });
  611. });
  612. }
  613. return true;
  614. } catch (e) {
  615. debug('//-> ' + e.name);
  616. return false;
  617. }
  618. }
  619.  
  620. function scrollDetect() {
  621. try {
  622. if (curretSite.SiteTypeID === newSiteType.GOOGLE) {
  623. const nodeName = '#for_' + curretSite.SiteName;
  624. debug('//-> Turn on google scrolling detecting.');
  625. scrollButton(nodeName + ' #bdyx', 'scrollspan');
  626. scrollButton(nodeName + ' #bdyx input', 'scrollbars');
  627. if (CONST.isUseBing) {
  628. scrollButton(nodeName + ' #bbyx input', 'scrollbars');
  629. }
  630. }
  631. return true;
  632. } catch (e) {
  633. debug('//-> ' + e.name);
  634. return false;
  635. }
  636. }
  637.  
  638. function scrollButton(paraName, classNameIn) {
  639. let oDiv = document.querySelector(paraName);
  640. let H = 0;
  641. let Y = oDiv;
  642. if (Y !== null) {
  643. while (Y) {
  644. H += Y.offsetTop;
  645. Y = Y.offsetParent;
  646. }
  647. document.addEventListener('scroll', () => {
  648. let s = document.body.scrollTop || document.documentElement.scrollTop;
  649. debug('//-> H-' + H);
  650. debug('//-> S-' + s);
  651. if (s > H + 35) {
  652. oDiv.setAttribute('class', classNameIn);
  653. } else {
  654. oDiv.removeAttribute('class');
  655. }
  656. });
  657. }
  658. }
  659.  
  660. function addStyle(css, className, addToTarget, isReload, initType) {
  661. RAFInterval(
  662. () => {
  663. let addTo = document.querySelector(addToTarget);
  664. if (typeof addToTarget === 'undefined') {
  665. addTo = document.head || document.body || document.documentElement || document;
  666. }
  667. isReload = isReload || false;
  668. initType = initType || 'text/css';
  669. if (typeof addToTarget === 'undefined' || (typeof addToTarget !== 'undefined' && document.querySelector(addToTarget) !== null)) {
  670. if (isReload === true) {
  671. safeRemove('.' + className);
  672. } else if (isReload === false && document.querySelector('.' + className) !== null) {
  673. return true;
  674. }
  675. let cssNode = document.createElement('style');
  676. if (className !== null) {
  677. cssNode.className = className;
  678. }
  679. cssNode.setAttribute('type', initType);
  680. cssNode.innerHTML = css;
  681. try {
  682. addTo.appendChild(cssNode);
  683. } catch (e) {
  684. debug('//-> ' + e.name);
  685. }
  686. return true;
  687. }
  688. },
  689. 20,
  690. true
  691. );
  692. }
  693.  
  694. function safeRemove(Css) {
  695. safeFunction(() => {
  696. let removeNodes = document.querySelectorAll(Css);
  697. for (let i = 0; i < removeNodes.length; i++) {
  698. removeNodes[i].remove();
  699. }
  700. });
  701. }
  702.  
  703. function safeFunction(func) {
  704. try {
  705. func();
  706. } catch (e) {
  707. debug('//-> ' + e.name);
  708. }
  709. }
  710.  
  711. function getSearchValue() {
  712. let val = '';
  713. document.querySelectorAll('input[name="wd"], input[name="q"]').forEach(things => {
  714. val = things.getAttribute('value');
  715. debug('//-> INPUT:' + val);
  716. });
  717. if (val === null || val === '' || typeof val === 'undefined') {
  718. let kvl = location.search.substr(1).split('&');
  719. for (let i = 0; i < kvl.length; i++) {
  720. let value = kvl[i].replace(/^(wd|word|kw|query|q)=/, '');
  721. if (value !== kvl[i]) {
  722. val = value;
  723. }
  724. }
  725. val = val.replace('+', ' ');
  726. debug('//-> QUERY:' + val);
  727. }
  728. return encodeURIComponent(val);
  729. }
  730.  
  731. function RAFInterval(callback, period, runNow) {
  732. const needCount = (period / 1000) * 60;
  733. let times = 0;
  734. if (runNow === true) {
  735. const shouldFinish = callback();
  736. if (shouldFinish) {
  737. return;
  738. }
  739. }
  740.  
  741. function step() {
  742. if (times < needCount) {
  743. times++;
  744. requestAnimationFrame(step);
  745. } else {
  746. const shouldFinish = callback() || false;
  747. if (!shouldFinish) {
  748. times = 0;
  749. requestAnimationFrame(step);
  750. } else {
  751. return;
  752. }
  753. }
  754. }
  755. requestAnimationFrame(step);
  756. }
  757.  
  758. function insterAfter(newElement, targetElement) {
  759. let parent = targetElement.parentNode;
  760. if (parent.lastChild === targetElement) {
  761. parent.appendChild(newElement);
  762. } else {
  763. parent.insertBefore(newElement, targetElement.nextSibling);
  764. }
  765. }
  766.  
  767. function GetUrlParam(paraName) {
  768. if (paraName === 'undefined') {
  769. const parameter = document.location.pathname.toString();
  770. let arr = parameter.split('/');
  771. return arr[1];
  772. } else {
  773. const url = document.location.toString();
  774. let arrObj = url.split('?');
  775. if (arrObj.length > 1) {
  776. let arrPara = arrObj[1].split('&');
  777. let arr;
  778. for (let i = 0; i < arrPara.length; i++) {
  779. arr = arrPara[i].split('=');
  780. if (arr !== null && arr[0] === paraName) {
  781. return arr[1];
  782. }
  783. }
  784. return '';
  785. } else {
  786. return '';
  787. }
  788. }
  789. }
  790. },
  791.  
  792. init: function () {
  793. debug('//-> Call the load menu option.');
  794. menuManager.init();
  795. debug('//-> Execute insert jump button.');
  796. this.doSwitch();
  797. },
  798. };
  799.  
  800. (function () {
  801. try {
  802. searchManager.init();
  803. } catch (e) {
  804. console.error('%c[GB-Error]%c\nConsole: %c%s%c.', 'font-weight:bold;color:red', 'color:0', 'font-weight:bold;color:darkred', e, 'color:0');
  805. }
  806. })();
  807. })();
  808. })();