Google Title Tooltips

Applies original Google search result titles to result links as title attributes

  1. // ==UserScript==
  2. // @name Google Title Tooltips
  3. // @namespace https://github.com/ohdeerdog/
  4. // @version 0.1
  5. // @description Applies original Google search result titles to result links as title attributes
  6. // @author ohdeerdog
  7. // @include *://*.google.tld/*
  8. // @run-at document-body
  9. // @grant none
  10. // @noframes
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. function apply_titles() {
  15. let links = document.querySelectorAll('#rso .g h3.r a');
  16. for (let link of links) {
  17. let request = new Request('https://urltitle.herokuapp.com/', {
  18. method: 'POST',
  19. headers: new Headers({
  20. 'Content-Type': 'application/json',
  21. }),
  22. body: JSON.stringify({ url: link.href }),
  23. });
  24.  
  25. fetch(request).then(response => {
  26. if (response.status === 200) {
  27. response.json().then(data => {
  28. if (data.title.length > 0) {
  29. link.setAttribute('title', data.title);
  30. }
  31. });
  32. }
  33. });
  34. }
  35. }
  36.  
  37. const observer = new MutationObserver(mutations => {
  38. for (let mutation of mutations) {
  39. if (mutation.target.id === 'search' && mutation.addedNodes.length === 2) {
  40. apply_titles();
  41. }
  42. }
  43. });
  44.  
  45. var config = { childList: true, subtree: true };
  46.  
  47. document.addEventListener('DOMContentLoaded', apply_titles);
  48. observer.observe(document.body, config);
  49. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址