Closed Spike-from-NH closed 6 months ago
https://wiki.greasespot.net/Metadata_Block
FREE Browser supports the following tags:
@match @run-at @name @run-at: If defined as "document-start" scripts run in onPageStarted() of Android WebView, otherwise scripts run in onPageFinished.
Other tags are NOT supported at the moment, e.g.
@include @exclude @grant @required
So basically you can run JavaScript on pages with an URL that matches an @match
rule.
Example:
// ==UserScript==
// @name Github Old Feed
// @description Replace the shit💩 new feed with the old one.
// @author 荣顶
// @version 1.6
// @license MIT
// @homepage https://github.com/wangrongding/github-old-feed.git
// @namespace http://tampermonkey.net/
// @match https://github.com/
// @match https://github.com/dashboard
// ==/UserScript==
(function () {
'use strict';
const feedContent = document.querySelector('.feed-content')
const feedMain = document.querySelector('.feed-main')
const sidebar = document.querySelector('.feed-right-sidebar')
if (feedContent) feedContent.style.maxWidth = "unset"
if (feedMain) feedMain.style.maxWidth = "100%"
if (sidebar) {
sidebar.style.maxWidth = "unset"
sidebar.style.width = "900px"
}
fetch('https://github.com/dashboard-feed')
.then(response => response.text())
.then(text => {
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'text/html');
// Preserving the SSO container
const dashboard = document.querySelector("#dashboard feed-container");
const main = doc.querySelector('main');
if (dashboard && main) dashboard.replaceWith(main);
})
.catch(error => {
console.error('Fetching the dashboard feed:', error);
});
})();
Thank you!
You note in #12 that you require @match
with wildcards for a rule intended to match all websites. It would be an improvement (at least to @kurasami) to drop that requirement and have match-all be the default.
In the example above, the payload is a function with no name and no parameters, whose body is the desired actions. All enclosed in parens, with additional parens afterward? But in your example in #12, you just jump in, with an unadorned call to alert();
.
The script above is from here: https://github.com/wangrongding/github-old-feed
The function is started by the parentheses at the end of the code block. This is known as an Immediately Invoked Function Expression (IIFE). It is a way to execute a function immediately after it is defined, without having to call it explicitly.
I don't like the idea of dropping the requirement for @match.
Running everywhere also means running on any http
only site.
Users of this feature should carefully think about where these scripts should run.
The Greasemonkey-style commands interest me as a possible alternative to Firefox+NoScript to restrict different web pages differently. But all I see by way of documentation is a pointer to another project. Could you point me to a better specification, or set out the Greasemonkey syntax you support?