mmmturkeybacon Numbered Google Results with Easy Copy

Numbers results in the format M.N to show the result number. If you are on the first page it divides the results up into groups of 10 and after every 10 results M is increased by 1. This allows you to quickly see which page a result would be on if there were 10 results per page. For any page after the first, M is the page number and N is the result number. Hold the pointer over a button for instructions on copying. Disable Google Instant (Gear>Search settings>Never show Instant results).

  1. // ==UserScript==
  2. // @name mmmturkeybacon Numbered Google Results with Easy Copy
  3. // @version 1.13
  4. // @description Numbers results in the format M.N to show the result number. If you are on the first page it divides the results up into groups of 10 and after every 10 results M is increased by 1. This allows you to quickly see which page a result would be on if there were 10 results per page. For any page after the first, M is the page number and N is the result number. Hold the pointer over a button for instructions on copying. Disable Google Instant (Gear>Search settings>Never show Instant results).
  5. // Click button to copy link URL, Ctrl-click to copy link title, Shift-click to copy link title and URL.
  6. // @author mmmturkeybacon
  7. // @namespace http://userscripts.org/users/523367
  8. // @include http*://www.google.*/search?*
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  10. // @grant GM_setClipboard
  11. // ==/UserScript==
  12.  
  13. // If you have Google set to return 10 results per page (default), the first
  14. // page usually has 10 results but not sometimes it will have fewer.
  15.  
  16. // If you change Results per page under Search Settings, Google will return
  17. // more results per page. The number of links on the page might not always be
  18. // the same as the number of results per page you chose. That's because Google
  19. // doesn't count every link it shows you as a result.
  20. // Ads aren't counted
  21. // "More results from ..." are grouped with the link they are under. Google
  22. // counts this as one result.
  23. // "Images for ..." aren't counted. (imagebox_bigimages)
  24. // "News for ..." and all the the links grouped with it are counted as one
  25. // result?? (newsbox)
  26.  
  27. // scroll to first result if the following is true or the google URL contains &mtb_scroll
  28. var SCROLL_TO_FIRST = false;
  29.  
  30. $(document).ready(function()
  31. {
  32. // If instant search has been enabled
  33. //if(document.getElementById('misspell')) return;
  34.  
  35. var $results_div = $('div[id="res"]');
  36. if ($results_div.length == 0)
  37. {
  38. throw new Error("No results.");
  39. }
  40.  
  41. var result_num = 0;
  42. var page_num = Number($('td[class="cur"]').text());
  43. page_num = (page_num == 0) ? 1 : page_num;
  44. var page_str = page_num + '.';
  45. var is_first_page = (page_num == 1);
  46.  
  47. var $results = $('li[class="g"],li[class="g w0"]').not('[id="imagebox_bigimages"]').not('[id="newsbox"]').find('h3');
  48. $results.each(function(i)
  49. {
  50. result_num++;
  51. if (result_num > 10 && is_first_page)
  52. {
  53. page_num++;
  54. page_str = page_num + '.'
  55. result_num = result_num - 10;
  56. }
  57.  
  58. $(this).html('<button title="Click to copy URL.\nCtrl-click to copy title.\nShift-click to copy title and URL." id=mtb_btn'+page_str+result_num+'>'+page_str + result_num+'</button>' + '&nbsp;' + $(this).html());
  59. var $button = $(this).find('button[id^="mtb_btn"]');
  60. var $link = $(this).find('a');
  61.  
  62. var button_handler = (function(title, URL){return function(event)
  63. {
  64. if (event.ctrlKey)
  65. {
  66. GM_setClipboard(title)
  67. }
  68. else if (event.shiftKey)
  69. {
  70. GM_setClipboard(title +' '+ URL)
  71. }
  72. else
  73. {
  74. GM_setClipboard(URL)
  75. }
  76. }})($link.html(), $link.attr('href'));
  77.  
  78. $button.bind('click', button_handler);
  79.  
  80. });
  81.  
  82. // scroll to first button unless info box is present
  83. if ($('li.g.tpo.knavi.obcontainer').length == 0 && (SCROLL_TO_FIRST == true || document.location.href.indexOf('&mtb_scroll') > -1))
  84. {
  85. document.querySelector('button[id^="mtb_btn"]').scrollIntoView();
  86. }
  87. });