What is greasemonkey used for




















Hide Private Photos on iPhone. Take Screenshot by Tapping Back of iPhone. Should You Upgrade to Windows 11? Browse All Windows Articles. Copy and Paste Between Android and Windows. Protect Windows 10 From Internet Explorer. Mozilla Fights Double Standard. Connect to a Hidden Wi-Fi Network.

Change the Size of the Touch Keyboard. Check Bluetooth Device Battery Life. Reader Favorites Take Screenshot on Windows. Mount an ISO image in Windows. Boot Into Safe Mode. Disable Startup Programs in Windows. Where to Download Windows Legally. Find Your Lost Product Keys. The Best Tech Newsletter Anywhere Join , subscribers and get a daily digest of news, geek trivia, and our feature articles. Getting Started with User Scripts Once you have Greasemonkey installed, managing the extension is really easy.

How-To Geek is where you turn when you want experts to explain technology. Since we launched in , our articles have been read more than 1 billion times. Some downloads include harmless additions such as a branded browser toolbar or a change to your home page. However, some free downloads may install adware and other less-than-reputable software. This script does a good job of removing these unwanted items on some of the most popular websites. This configurable script automatically closes YouTube video ads after a time delay that you choose.

It also offers an option to mute these advertisements as soon as the ad launches. Many websites display a warning and require user interaction when you click a link that redirects to another site.

This script disables that functionality on many popular domains, including Google, YouTube, Facebook, and Twitter. The Feedly Filtering and Sorting script adds some useful features such as advanced keyword matching, auto-load, filtering, and restricting to the popular news-aggregation site. Block certain websites or entire domains from appearing in search engine results with this script.

The title is a bit misleading, as it supports Bing, DuckDuckGo, Yahoo, and other search engines in addition to Google. It works best with Chrome or Firefox.

This script adds useful buttons to Google's engine. These buttons include tools to search for PDF documents and search for results from user-specified time intervals, including days, weeks, months, years, and hours.

View and download full-size images and videos from Instagram by pressing a keyboard shortcut with this script. This script works with all browsers, but the direct-download feature only works with Chrome. It makes almost any text link a clickable link. If you're a fan of the Japanese comic genre, this script displays complete chapters on one page in an easy-to-read long-strip format on many of the web's most popular Manga sites. This script lets you browse image collections on Pinterest without creating an account on the site.

However, it doesn't work as expected on all pages. Use this script to translate selected text on a web page to the language of your choice with the Alt key and the cursor. Programmers find this script useful. It resizes all GitHub repository pages for a better look and feel. When you're ready to search for scripts, the following sites are the best starting points. Not every script works across all browsers, so verify the corresponding description and notes before installation. Actively scan device characteristics for identification.

You can also remove an attribute entirely with the removeAttribute method:. If the link has an id or name attribute, it will still be a page anchor, but you will no longer be able to click it to follow the link. There are several ways to accomplish this. Here is a simple function that I reuse in most cases in which I need to add arbitrary styles to a page. It takes a single parameter, a string containing any number of CSS rules:.

As you see in the previous example, Firefox maintains a list of the stylesheets in use on the page, in document. Each item in this collection is an object, representing a single stylesheet. Each stylesheet object has a collection of rules, and methods to add new rules or remove existing rules. The insertRule method takes two parameters.

The first is the CSS rule to insert, and the second is the positional index of the rule before which to insert the new rule:. You can also delete individual rules by using the deleteRule method.

It takes a single parameter, the positional index of the rule to remove. The following code will remove the first rule, which we just inserted with insertRule :. The property names of individual styles are not always obvious.

But there are exceptions. The float property is set with elmModify. There is no easy way to set multiple properties at once. In regular JavaScript, you can set multiple styles by calling the setAttribute method to the style attribute to a string:. Firefox contains a little-known but powerful feature called XPath.

Many hacks work on a collection of elements. Without XPath, you would need to get a list of elements for example, with document. With XPath expressions, you can find exactly the elements you want, all in one shot, and then immediately start working with them. To execute an XPath query, use the document. If you want to search the entire web page, pass in document.

But you can also search just a part of the page. If you want a collection of elements, use XPathResult. If you want to find a single element, use XPathResult. More on this in a minute, too.

I rarely use this, but it can be useful if you want to conditionally concatenate the results of multiple XPath queries. The document.

You can iterate through the snapshot or access its items in any order. The snapshot is static, which means it will never change, no matter what you do to the page. You can even delete DOM nodes as you move through the snapshot. To get the number of items in the snapshot, use snapResults.

To access a particular item, you need to call snapshotResults. Here is the skeleton of a script that executes an XPath query and loops through the results:. You can use XPath to search for specific elements. You can also test for the presence of an attribute, regardless of its value. The following query finds all elements with an accesskey attribute.

Not impressed yet? You can also do combinations of attributes. This query finds all images with a width of 36 and a height of By using more advanced XPath syntax, you can actually find elements that are contained within other elements. This code finds all the links that are contained in a paragraph whose class is g. Finally, you can find a specific element by passing XPathResult. XPath is, quite literally, a language all its own. Like regular expressions, XPath can make your life easier, or it can make your life a living hell.

Remember, you can always get what you need eventually with standard DOM functions such as document. Edit a user script and see your changes immediately. Changes to these installed files take effect immediately, as soon as you refresh the page. This makes the testing cycle quick, because you can edit your partially written script, save changes, and refresh your test page to see the changes immediately.

Before you can take advantage of live editing, you need to set up file associations on your system, so that double-clicking a. Control-click a. In the Open With section, select your text editor from the drop-down menu, or select Other…to find the editor program manually. Click Change All to permanently associate your editor with. Right-click a. Select your favorite text editor from the list, or click Browse to find the editor application manually.

Select a script from the pane on the left and click Edit. If your file associations are set up correctly, this should open the user script in your text editor. The first time you do this on Windows, you will get a warning message, explaining that you need to set up your file associations, as shown in Figure The reason for the warning is that, by default, Windows is configured to execute. Once the user script opens in your text editor, you can make any changes you like to the code.

As soon as you make a change and save it, you can switch back to Firefox and refresh your test page to see the effect of your change. Switch to your editor, make another change, switch back to Firefox, and refresh. During live editing , you can change only the code of a user script, not the configuration parameters in the metadata section. If you want to change where the script runs, use the Manage User Scripts dialog. Save a backup somewhere else for safekeeping. Learn the subtle art of Greasemonkey debugging.

Since JavaScript is an interpreted language, errors that would otherwise cause a compilation error such as misspelled variables or function names can only be caught when they occur at runtime. In the JavaScript Console window, click Clear to remove the old errors from the list. If your user script is crashing or otherwise misbehaving, you will see the exception displayed in JavaScript Console.

If your user script is crashing, JavaScript Console will display an exception and a line number. Due to the way Greasemonkey injects user scripts into a page, this line number is not actually useful, and you should ignore it. It is not the line number within your user script where the exception occurred. What next? Such messages should be taken out before release, but they are enormously helpful in debugging.

Plus, watching the console pile up with log messages is much more satisfying than clicking OK over and over to dismiss multiple alerts.

After logging to JavaScript Console, the user script will continue executing normally. Messages logged in Javascript Console are not limited to characters. Plus, lines in JavaScript Console wrap properly, so you can always scroll down to see the rest of your log message. Go nuts with logging! In JavaScript Console, you can right-click Mac users Control-click on any line and select Copy to copy it to the clipboard. You can get details on each HTML element, attribute, and text node.

You can explore all the scriptable properties of an object. DOM Inspector is included with the Firefox installation program, but depending on your platform, it might not installed by default. It allows you to right-click on any element—a link, a paragraph, even the page itself—and open DOM Inspector with that element selected.

From there, you can inspect its properties, or see exactly where it fits within the hierarchy of other elements on the page. One last note: DOM Inspector does not follow you as you browse. JavaScript Shell is a bookmarklet that allows you to evaluate arbitrary JavaScript expressions in the context of the current page. You install it simply by dragging it to your links toolbar. Then you can visit a web page you want to work on, and click the JavaScript Shell bookmarklet in your toolbar.

The JavaScript Shell window will open in the background. Think of it as a command line for the DOM. You can enter any JavaScript expressions or commands, and you will see the output immediately. You can even make changes to the page, such as creating a new element document. Your changes are reflected in the original page. One feature of JavaScript Shell that is worth special mention is the props function. Methods and properties that are specific to link elements such as the blur and focus methods, and the href and hreflang properties are listed first, followed by methods and properties shared by all types of nodes such as the insertBefore method.

Again, this is the same information that is available in DOM Inspector—but with more typing and experimenting, and less pointing and clicking. If you open JavaScript Shell and then navigate somewhere else in the original window, JavaScript Shell will get confused.

Add images to web pages without hitting a remote server. A user script is a single file. Greasemonkey does not provide any mechanism for bundling other resource files, such as image files, along with the JavaScript code. While this might offend the sensibilities of some purists who would prefer to maintain separation between code, styles, markup, and media resources, in practice, it is rarely a problem for me. Instead of posting the image to a web server and having your user script fetch it, you can embed the image data in the script itself by using a data : URL.

A data : URL allows you to encode an image as printable text, so you can store it as a JavaScript string. Firefox will display the image without sending a separate request to any remote server.

This user script runs on all pages. It uses an XPath query to find web bugs : 1 x 1-pixel img elements that advertisers use to track your movement online. A user script can do anything you can do in Javascript. In fact, it can do even more than that, because Greasemonkey provides special functions that are only available to user scripts.

There is a Greasemonkey script repository that contains hundreds of user scripts that people have written to scratch their own personal itches.

Once you write your own user script, you can add it to the repository if you think others might find it useful. Or you can keep it to yourself, content in the knowledge that you've made your own browsing experience is a little better.

There is also a Greasemonkey mailing list , where you can ask questions, announce user scripts, and discuss ideas for new features.



0コメント

  • 1000 / 1000