Google to YouTube Search

Use your Google Search terms to search YouTube by clicking a new YouTube link added to your Google Search page.

  1. // ==UserScript==
  2. // @name Google to YouTube Search
  3. // @namespace https://greatest.deepsurf.us/en/users/10118-drhouse
  4. // @version 6.6
  5. // @description Use your Google Search terms to search YouTube by clicking a new YouTube link added to your Google Search page.
  6. // @run-at document-start
  7. // @include https://www.google.*/search*
  8. // @include https://potato.net/*
  9. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  10. // @require https://greatest.deepsurf.us/scripts/439099-monkeyconfig-modern-reloaded/code/MonkeyConfig%20Modern%20Reloaded.js?version=1012538
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @grant GM_addStyle
  14. // @grant GM_info
  15. // @grant GM_registerMenuCommand
  16. // @author drhouse
  17. // @license CC-BY-NC-SA-4.0
  18. // @icon https://www.google.com/s2/favicons?domain=google.com
  19. // ==/UserScript==
  20. /* global jQuery, MonkeyConfig, $ */
  21. $(document).ready(function () {
  22.  
  23. var cfg = new MonkeyConfig({
  24. title: 'Configure',
  25. menuCommand: true,
  26. params: {
  27. 'YouTube': {
  28. type: 'checkbox',
  29. default: true
  30. },
  31. 'Reddit': {
  32. type: 'checkbox',
  33. default: true
  34. },
  35. 'Github': {
  36. type: 'checkbox',
  37. default: true
  38. },
  39. },
  40. })
  41.  
  42. function createLink(site, url, query) {
  43. $('<a class="LatpMc nPDzT T3FoJb" id="above" href="' + url + encodeURIComponent(query) + '"><div class="YmvwI">' + site + '</div></a>')
  44. // .insertBefore("#uddia_1")
  45. // #hdtb-sc > div > div > div.crJ18e
  46. .insertAfter(".crJ18e")
  47. .last();
  48. }
  49. var gquery = $("textarea").text()
  50. // const elementLength = $("#cnt > div:nth-child(8)").length;
  51. const elementLength = $("#cnt > div:nth-child(20)").length;
  52. const nthChildValue = elementLength === 1 ? 8 : 10;
  53.  
  54. if (cfg.get('Github')) {
  55. createLink('Github', 'https://'+$(location).attr('hostname')+'/search?q=site%3Agithub.com+', gquery + '&type=repositories');
  56. }
  57.  
  58. if (cfg.get('Reddit')) {
  59. createLink('Reddit', 'https://'+$(location).attr('hostname')+'/search?q=site%3Areddit.com+', gquery);
  60. }
  61.  
  62. if (cfg.get('YouTube')) {
  63. createLink('YouTube', 'https://www.youtube.com/results?search_query=', gquery);
  64. }
  65. });