Greasy Fork is available in English.
美化Google搜索结果:宽屏居中显示、去除广告、背景色、悬停效果、整卡可点击
当前为
// ==UserScript==
// @license MIT
// @name Google搜索美化
// @namespace https://github.com/user-scripts
// @version 7.0
// @description 美化Google搜索结果:宽屏居中显示、去除广告、背景色、悬停效果、整卡可点击
// @author User
// @match https://www.google.com/search*
// @match https://www.google.com.hk/search*
// @grant none
// @run-at document-start
// ==/UserScript==
(function () {
'use strict';
if (window.__gsBeautified) return;
window.__gsBeautified = true;
const CARD_BG = '#f5e4ea';
const CARD_HOVER = '#e4f5f4';
const CSS = `
/* 隐藏广告 */
#tads, #tadsb, #bottomads,
.commercial_unit, .ads-ad,
[data-text-ad], .uEierd, .U3A9Ac {
display: none !important;
}
/* ✅ 让 rcnt 撑满并居中 */
#rcnt {
width: 100% !important;
max-width: 1100px !important;
margin: 0 auto !important;
box-sizing: border-box !important;
display: block !important;
}
/* ✅ center_col 独占整行,不给右侧栏留空间 */
#center_col {
width: 100% !important;
max-width: 100% !important;
margin: 0 auto !important;
box-sizing: border-box !important;
grid-column: 1 / -1 !important;
}
/* ✅ 隐藏右侧栏空容器(避免占位) */
#rhs {
display: none !important;
}
/* 中间层容器撑满 */
#rso, #search,
#rso .dURPMd,
#rso .eqAnXb,
#rso .s6JM6d {
width: 100% !important;
box-sizing: border-box !important;
}
/* 搜索结果卡片 */
#rso .MjjYud {
background: ${CARD_BG} !important;
border-radius: 10px !important;
margin: 10px 0 !important;
padding: 14px 18px !important;
box-sizing: border-box !important;
width: 100% !important;
position: relative !important;
overflow: hidden !important;
cursor: pointer !important;
transition: background 0.2s ease,
transform 0.2s ease,
box-shadow 0.2s ease !important;
}
/* 悬停 */
#rso .MjjYud:hover {
background: ${CARD_HOVER} !important;
transform: scale(1.012) !important;
box-shadow: 0 4px 18px rgba(0,0,0,0.10) !important;
z-index: 5 !important;
}
/* 扫光 */
#rso .MjjYud::before {
content: '' !important;
position: absolute !important;
top: 0 !important;
left: -100% !important;
width: 100% !important;
height: 100% !important;
background: linear-gradient(
120deg,
transparent 0%,
rgba(0,255,255,0.15) 30%,
rgba(138,43,226,0.12) 60%,
transparent 100%
) !important;
pointer-events: none !important;
z-index: 1 !important;
transition: left 1.2s ease !important;
}
#rso .MjjYud:hover::before {
left: 100% !important;
}
/* 内容层级高于扫光 */
#rso .MjjYud > * {
position: relative !important;
z-index: 2 !important;
}
/* 响应式 */
@media (max-width: 768px) {
#rcnt {
padding: 0 10px !important;
}
}
`;
function injectStyle() {
if (document.getElementById('__gs_beautify__')) return;
const el = document.createElement('style');
el.id = '__gs_beautify__';
el.textContent = CSS;
(document.head || document.documentElement).appendChild(el);
console.log('[Google美化 v7] 样式注入成功');
}
function bindClick() {
if (window.__gsClickBound) return;
window.__gsClickBound = true;
document.addEventListener('click', function (e) {
if (e.target.closest('a, button, input, select, textarea')) return;
const card = e.target.closest('#rso .MjjYud');
if (!card) return;
const link =
card.querySelector('.yuRUbf a') ||
card.querySelector('a[jsname] h3')?.closest('a') ||
card.querySelector('h3 a') ||
card.querySelector('a[href^="http"]');
if (!link) return;
const href = link.href;
if (!href || href.includes('google.com/search')) return;
e.preventDefault();
e.stopPropagation();
window.open(href, '_blank', 'noopener,noreferrer');
}, true);
}
function init() {
injectStyle();
bindClick();
}
if (document.head) {
injectStyle();
} else {
const watcher = new MutationObserver(function () {
if (document.head) {
watcher.disconnect();
injectStyle();
}
});
watcher.observe(document.documentElement, { childList: true });
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
let lastUrl = location.href;
new MutationObserver(function () {
if (location.href !== lastUrl) {
lastUrl = location.href;
setTimeout(init, 700);
}
}).observe(document.documentElement, { subtree: true, childList: true });
window.addEventListener('popstate', () => setTimeout(init, 700));
})();