GreaseMonkey, or How to Enhance Your Web Experience (2008)

작성자

카테고리:

← 피드로
DEV Community · Hamdi LAADHARI · 2026-08-22 개발(SW)
Cover image for GreaseMonkey, or How to Enhance Your Web Experience (2008)

Hamdi LAADHARI

Archival repost — originally published on my old blog on December 21, 2008. Lightly cleaned up for dev.to (translated from French, and I fixed a smart-quote encoding issue in the code block that would have made it fail). GreaseMonkey itself has since been discontinued for Firefox — Tampermonkey and Violentmonkey are the modern equivalents — and Google’s markup has changed completely since 2008, so the exact selectors below won’t match today’s page. The userscript technique itself still works exactly the same way.

GreaseMonkey is a Firefox extension that lets you take control of the web. You find a site interesting despite it being plastered with ads. Thanks to GreaseMonkey and a script that’s just a few lines long, you can change the visual rendering of your favorite site however you want.

To illustrate, here’s a small JS script I wrote — it removes the “Sponsored Links” that show up in Google search results. Knowing JavaScript is obviously a requirement, but so is knowing the DOM and/or XPath.

// ==UserScript==
// @name           Google Sponsored Links remover
// @namespace      http://www.laadhari.fr
// @description    remove google sponsored links from SERPS
// @include        http://www.google.com/*
// ==/UserScript==

(function() {
  var sidebarads = document.getElementById('mbEnd');
  var skyads = document.getElementById('tads');
  if (sidebarads) {
    sidebarads.parentNode.removeChild(sidebarads);
    }
  if (skyads) {
    skyads.parentNode.removeChild(skyads);
    }
  }
)();

Enter fullscreen mode Exit fullscreen mode

Hopefully this convinces you to write your own scripts — if you do, consider sharing them on UserScripts.org in case they’re useful to someone else. My Google Sponsored Links remover is up there, open to any criticism.

원문에서 계속 ↗