Auto-Espande Google Search Tools

Mostra il menu Strumenti di ricerca nei risultati di ricerca di Google +link colorati

当前为 2020-11-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Auto-Espande Google Search Tools
  3. // @description Mostra il menu Strumenti di ricerca nei risultati di ricerca di Google +link colorati
  4. // @namespace https://greasyfork.org/users/237458
  5. // @author figuccio
  6. // @include /https:\/\/www\.google\.(com?(\.[a-z]{2})?|[a-z]{2})\/.*/
  7. // @version 13.1
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
  9. // @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=19641
  10. // @grant GM_addStyle
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @run-at document-start
  14. // @noframes
  15. // ==/UserScript==
  16. (function() {
  17. 'use strict';
  18. /* globals $, waitForKeyElements */
  19. //pulsante Strumenti di ricerca rosso
  20. GM_addStyle("#hdtb-tls { color:red !important;background:green !important; border-radius:12px;border:2px solid red!important}");
  21.  
  22. //link altro,immagini.ecc colore rosso spondo arancione
  23. GM_addStyle('#hdtb .hdtb-mitem a {color:red!important;background:orange!important;border-radius:8px;padding:4px 4px;border:2px solid green!important}');
  24.  
  25. //prova altro
  26. GM_addStyle('.hdtb-mitem .sqXXR{color:red!important;background:orange!important;border-radius:8px;padding:4px 4px;border:2px solid green!important}');
  27.  
  28.  
  29. //link altro,immagini.maps ecc colore rosso che cambia colore al passaggio mouse diventa verde
  30. GM_addStyle('#hdtb .hdtb-mitem a:hover{color:green!important}');
  31.  
  32. GM_addStyle('#hdtb-msb {min-width:0px!important}');//pulsanti impostazioni e strumenti avvicinati al pulsante altro
  33.  
  34. //link espansione strumenti colore verde
  35. GM_addStyle('.hdtb-mn-hd {color:green!important;background:gold!important;border-radius:9px;border:2px solid blue!important}');
  36.  
  37. //link espansione strumenti colore verde che diventa rosso al passaggio mouse
  38. GM_addStyle('.hdtb-mn-hd:hover {color:red!important}');
  39.  
  40. //topbar espansioni strumenti colorata arancione
  41. GM_addStyle('body.vasq .WE0UJf {background:green!important;width:700px;border-radius:12px;border:2px dotted red!important}');//funziona
  42.  
  43. //link ricerca google colorati di rosso
  44. GM_addStyle('a:visited {color:black !important}');
  45. //GM_addStyle('a:link {color:red !important}');
  46.  
  47. //pulsante tutti
  48. GM_addStyle('#hdtb-msb .hdtb-mitem.hdtb-msel{color:red!important;background:orange!important;border-radius:8px;border:2px solid green!important;padding:4px 4px;border-bottom:6px solid blue!important}');
  49.  
  50. GM_addStyle('.mn-dwn-arw {border-color:red transparent!important}');//triangolini rossi
  51. //menu colorato
  52. GM_addStyle('.hdtbItm.hdtbSel, .hdtbItm a,#hdtb-more-mn a,#cdrlnk, .hdtb-mn-o {color:lime!important;background:red !important;}');
  53. GM_addStyle('.hdtb-mn-o {border:2px solid blue!important}');//bordo blu
  54.  
  55. //Accelera la visibilità del menu Strumenti di ricerca rimuovendo l'animazione.
  56. GM_addStyle("#hdtbMenus { transition: none !important; }");
  57. // Mostra il menu Strumenti di ricerca.
  58. waitForKeyElements ("#hdtbMenus", expandSearchTools);
  59. function expandSearchTools (jNode) {
  60. jNode.removeClass("hdtb-td-c hdtb-td-h").addClass("hdtb-td-o");
  61. }
  62. })();
  63. //no publicita correlate
  64. GM_addStyle('#rcnt .col:nth-of-type(3) {display:none !important;}');
  65.  
  66. //funzione endless google
  67. const centerElement = "#center_col";
  68. const loadWindowSize = 1.6;
  69. const filtersAll = ["#foot", "#bottomads"];
  70. const filtersCol = filtersAll.concat(["#extrares", "#imagebox_bigimages"]);
  71.  
  72. const css = `
  73. .page-number {
  74. position: relative;
  75. display: flex;
  76. flex-direction: row-reverse;
  77. align-items: center;
  78. margin-bottom: 2em;
  79. color:red;
  80. }
  81. .page-number::before {
  82. content: "";
  83. background-color:green;
  84. height: 1px;
  85. width: 90%;
  86. margin: 1em 3em;
  87. }
  88. `;
  89.  
  90. let pageNumber = 1;
  91. let prevScrollY = 0;
  92. let nextPageLoading = false;
  93.  
  94. function requestNextPage() {
  95. nextPageLoading = true;
  96. let nextPage = new URL(location.href);
  97. if (!nextPage.searchParams.has("q")) return;
  98.  
  99. nextPage.searchParams.set("start", String(pageNumber * 10));
  100.  
  101. fetch(nextPage.href)
  102. .then(response => response.text())
  103. .then(text => {
  104. let parser = new DOMParser();
  105. let htmlDocument = parser.parseFromString(text, "text/html");
  106. let content = htmlDocument.documentElement.querySelector(centerElement);
  107.  
  108. content.id = "col_" + pageNumber;
  109. filter(content, filtersCol);
  110.  
  111. let pageMarker = document.createElement("div");
  112. pageMarker.textContent = String(pageNumber + 1);
  113. pageMarker.className = "page-number";
  114.  
  115. let col = document.createElement("div");
  116. col.className = "next-col";
  117. col.appendChild(pageMarker);
  118. col.appendChild(content);
  119. document.querySelector(centerElement).appendChild(col);
  120.  
  121. if (!content.querySelector("#rso")) {
  122. // end of results
  123. window.removeEventListener("scroll", onScrollDocumentEnd);
  124. nextPageLoading = false;
  125. return;
  126. }
  127.  
  128. pageNumber++;
  129. nextPageLoading = false;
  130.  
  131. });
  132. }
  133.  
  134. function onScrollDocumentEnd() {
  135. let y = window.scrollY;
  136. let delta = y - prevScrollY;
  137. if (!nextPageLoading && delta > 0 && isDocumentEnd(y)) {
  138. requestNextPage();
  139. }
  140. prevScrollY = y;
  141. }
  142.  
  143. function isDocumentEnd(y) {
  144. return y + window.innerHeight * loadWindowSize >= document.body.clientHeight;
  145. }
  146.  
  147. function filter(node, filters) {
  148. for (let filter of filters) {
  149. let child = node.querySelector(filter);
  150. if (child) {
  151. child.parentNode.removeChild(child);
  152. }
  153. }
  154. }
  155. function init() {
  156. prevScrollY = window.scrollY;
  157. window.addEventListener("scroll", onScrollDocumentEnd);
  158. filter(document, filtersAll);
  159. let style = document.createElement("style");
  160. style.type = "text/css";
  161. style.appendChild(document.createTextNode(css));
  162. document.head.appendChild(style);
  163. }
  164. document.addEventListener("DOMContentLoaded", init);
  165.  
  166. //le persone anno chiesto anche
  167. GM_addStyle('.OJXvsb.Wnoohf.cUnQKe.kp-blk {display:none !important;}');
  168.  
  169. //Promemoria sulla privacy di Google
  170. GM_addStyle('#cnsh,#cnso,#cnsi{display:none!important}');
  171. //////////////////////////////////////////////////aggiunto youtube
  172. process();
  173. new MutationObserver(process).observe(document.body || document.documentElement, { childList: true, subtree: true });
  174.  
  175. function process(mutations) {
  176. let q,
  177. queryElement = document.querySelector('input[name="q"]'); // selector for the Google search input textbox
  178.  
  179. if (queryElement?.value) q = encodeURIComponent(queryElement.value);
  180. else if (q = location.href.match(/^.+?(?:[#/&?](?:q|query))=(.+?)(?:|&.+|\|.+)$/)) q = q[1];
  181.  
  182. let link = document.querySelector(`a[href*='tbm=vid']`);
  183.  
  184. if (q && link?.href) {
  185. link.href = 'https://www.youtube.com/results?search_query=' + q;
  186. //link.textContent = link.textContent.replace(/\S+/, 'YouTube');;
  187. link.textContent = 'YouTube';
  188. console.log('create', link.textContent);
  189. }
  190. }
  191. ///ricerche correlate
  192. GM_addStyle('#brs {display:none !important;}');
  193.  
  194. GM_addStyle('.commercial-unit-desktop-top {display:none !important;}');
  195. ///////////////////////////////////////////////////////////////////////cookie consent//////////////
  196. (function() {
  197. window.addEventListener("yt-navigate-finish", function(event) {
  198. window.dispatchEvent(new Event('locationchange'))
  199. });
  200.  
  201. //old layout < 2017
  202. window.addEventListener("spfdone", function(e) {
  203. window.dispatchEvent(new Event('locationchange'))
  204. });
  205.  
  206. window.addEventListener("load",function(){
  207. dismissLogin();
  208. },{once:true});
  209.  
  210. function cookieIsSet(){
  211. return document.cookie.match(/CONSENT\=YES\+EN\.en\+V13\+BX/) !== null;
  212. }
  213.  
  214. function siteIsRefreshable(){
  215. return document.URL.match(/^https\:\/\/(accounts\.(google|youtube)\.com|www\.google\.com\/recaptcha)/i) === null;
  216. }
  217.  
  218. function isYoutube(){
  219. return document.URL.match(/^https\:\/\/www\.youtube\.com/i) !== null;
  220. }
  221.  
  222. window.addEventListener('locationchange', function(){
  223. if(!cookieIsSet()){
  224. cookieInjection();
  225. }
  226. dismissLogin();
  227. });
  228.  
  229. //if cookie is unset then inject it
  230. if(!cookieIsSet()){
  231. cookieInjection();
  232. }
  233. dismissLogin();
  234.  
  235. function cookieInjection(){
  236. //cookie injection
  237. document.cookie = "CONSENT=YES+EN.en+V13+BX; expires=Fri, 01 Jan 2038 00:00:00 GMT; domain="+document.URL.match(/^https\:\/\/[a-z]*\.((google|youtube)\.[\.a-z]*)/)[1]+"; path =/; Secure";
  238.  
  239. //reload on accounts.google.com pages causes infinite loop
  240. if(siteIsRefreshable()){
  241. //refresh page to avoid cookie's popup
  242. //console.log("Google Shut Up: cookie refresh");
  243. location.reload();
  244. }
  245. }
  246.  
  247. function dismissLogin(){
  248. try {
  249. window.ytInitialPlayerResponse.auxiliaryUi.messageRenderers.upsellDialogRenderer.isVisible = false;
  250. //console.log("Google Shut Up: dismissed login popup");
  251. } catch (e){
  252. }
  253. }
  254.  
  255. })();
  256.  
  257. /////////
  258. GM_addStyle('.gLSAk {background-color:red !important;color:blue!important;border:2px solid black!important}');