°F+°C Weather - google

Shows both °F and °C weather temperatures at the same time on Google.

  1. // ==UserScript==
  2. // @name °F+°C Weather - google
  3. // @namespace https://gf.qytechs.cn/en/users/670188-hacker09?sort=daily_installs
  4. // @version 8
  5. // @description Shows both °F and °C weather temperatures at the same time on Google.
  6. // @author hacker09
  7. // @include *://www.google.*
  8. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://www.google.com&size=64
  9. // @run-at document-end
  10. // @grant none
  11. // @noframes
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. var CorF; //Create a global variable
  17.  
  18. if (document.querySelector("div.vk_bk.wob-unit > span,div.wob_uctr > span").innerText === '°F') //If the current temperature is in °F
  19. { //Starts the if condition
  20. CorF = '°F'; //Page was loaded in °F
  21. } //Finishes the if condition
  22.  
  23. async function ShowCF() {
  24. var c = document.getElementById('wob_tm').innerText; //Save the current temperature value
  25. var f = document.getElementById('wob_ttm').innerText; //Save the hidden temperature value
  26.  
  27. navigator.userAgentData.mobile === true ? document.querySelector("div.wob_tctr").style.display = 'none' : ''; //Hide the big text temperature
  28. navigator.userAgentData.mobile === true ? document.querySelector("div.wob_uctr").style.fontSize = '47px' : ''; //Increase the script custom text font size
  29. navigator.userAgentData.mobile === true ? document.querySelectorAll("div.wob_uctr > span").forEach(el => el.style.color = 'white') : ''; //Make the script temperature white
  30.  
  31. if (CorF === '°F') //If the current temperature is in °F
  32. { //Starts the if condition
  33. navigator.userAgentData.mobile === true ? '' : document.querySelector("div.vk_bk.TylWce.SGNhVe").innerText = c + '°F / ' + f + '°C'; //Show °F °C
  34. document.querySelectorAll("div.wob_uctr > .wob_t:nth-child(1),div.wob_uctr > .wob_t:nth-child(2)").forEach(el => el.innerText = c + '°F'); //Show °F
  35. document.querySelectorAll("div.wob_uctr > .wob_t:nth-child(4),div.wob_uctr > .wob_t:nth-child(5)").forEach(el => el.innerText = f + '°C'); //Show °C
  36. } //Finishes the if condition
  37. else //If the current temperature is in °C
  38. { //Starts the else condition
  39. navigator.userAgentData.mobile === true ? '' : document.querySelector("div.vk_bk.TylWce.SGNhVe").innerText = c + '°C / ' + f + '°F'; //Show °C °F
  40. document.querySelectorAll("div.wob_uctr > .wob_t:nth-child(1),div.wob_uctr > .wob_t:nth-child(2)").forEach(el => el.innerText = c + '°C'); //Show °C
  41. document.querySelectorAll("div.wob_uctr > .wob_t:nth-child(4),div.wob_uctr > .wob_t:nth-child(5)").forEach(el => el.innerText = f + '°F'); //Show °F
  42. } //Finishes the else condition
  43.  
  44. let elements1 = document.querySelectorAll("text.wob_t"), //For each graph number
  45. elements2 = document.querySelectorAll(".wNE31c > div > span"), //For each bottom number
  46. targetElements = [], //Creates a new array
  47. count = 0; //Create a new counter
  48. for (let i = 0; i < elements1.length; i++) { //For each graph number
  49. targetElements.push(elements1[i]), count++; //Add to the array and increase the counter
  50. if (44 === count) { //if counter is = 44
  51. let result = ""; ///Create a new blank variable
  52. for (let j = 0; j < targetElements.length; j++) "" !== targetElements[j].textContent.trim() && (result !== "" && (result += "⬩"), result += targetElements[j].textContent);
  53. for (let j = 1; j < targetElements.length; j++) "" !== targetElements[j].textContent.trim() && (targetElements[j - 1].textContent += "⬩" + targetElements[j].textContent);
  54. break; //Stop the loop
  55. } //Finishes the if condition
  56. } //Finishes the for loop
  57. targetElements = []; //Reset the array
  58. count = 0; //Reset the counter
  59. for (let i = 0; i < elements2.length; i++) { //For each bottom number
  60. targetElements.push(elements2[i]), count++; //Add to the array and increase the counter
  61. if (32 === count) { //if counter is = 32
  62. let result = ""; ///Create a new blank variable
  63. for (let j = 0; j < targetElements.length; j++) "" !== targetElements[j].textContent.trim() && (result !== "" && (result += "⬩"), result += targetElements[j].textContent);
  64. for (let j = 1; j < targetElements.length; j++) "" !== targetElements[j].textContent.trim() && (targetElements[j - 1].textContent += "⬩" + targetElements[j].textContent);
  65. break; //Stop the loop
  66. } //Finishes the if condition
  67. } //Finishes the for loop
  68.  
  69. document.querySelectorAll('.wNE31c').forEach(div => { div.innerHTML = div.innerHTML.replace(/°/g, '');}); //Remove the ° symbol
  70. }
  71.  
  72. setTimeout(() => { ShowCF(); }, 1200); //Calls the ShowCF function
  73.  
  74. if (navigator.userAgentData.mobile === true) //If it's a mobile device
  75. { //Starts the if condition
  76. new MutationObserver(async function() { //When the weather bar is scrolled
  77. await ShowCF(); //Calls the ShowCF function
  78. }).observe(document.querySelector("#wob_sh"), { //Defines the element and the characteristics to be observed
  79. attributes: true,
  80. attributeOldValue: true,
  81. characterData: true,
  82. characterDataOldValue: true,
  83.  
  84. childList: true,
  85. subtree: true
  86. }); //Finishes the definitions to be observed
  87. } //Finishes the if condition
  88. })();

QingJ © 2025

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