Press "g" to Google (DuckDuckGo)

Press "g" to Google in DuckDuckGo

目前為 2021-09-08 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Press "g" to Google (DuckDuckGo)
  3. // @namespace https://wiki.gslin.org/wiki/Google
  4. // @version 0.20210908.0
  5. // @description Press "g" to Google in DuckDuckGo
  6. // @author Gea-Suan Lin
  7. // @match https://duckduckgo.com/*
  8. // @grant GM_addStyle
  9. // @grant GM_getValue
  10. // @grant GM_openInTab
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_setValue
  13. // @require https://greasyfork.org/scripts/38445-monkeyconfig/code/MonkeyConfig.js?version=251319
  14. // @license MIT
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. const cfg = new MonkeyConfig({
  21. menuCommand: true,
  22. params: {
  23. search_engine: {
  24. type: 'text',
  25. default: 'https://www.google.com/search?q=',
  26. },
  27. },
  28. title: 'Press "g" to Google in DuckDuckGo',
  29. });
  30.  
  31. document.addEventListener('keyup', function(event) {
  32. if ('input' === document.activeElement.tagName.toLowerCase()) {
  33. return;
  34. }
  35. if ('g' !== event.key) {
  36. return;
  37. }
  38.  
  39. let q = document.getElementById('search_form_input').value;
  40. let q_encoded = encodeURIComponent(q).replace(/%20/g, '+');
  41. let url = cfg.get('search_engine') + q_encoded;
  42.  
  43. document.location = url;
  44. });
  45. })();