Greasemonkey - 如何在以特定字符串开头的页面上找到并打开 v URL?
Greasemonkey - How do you find and open aν URL on a page that starts with a specific string?
已更新
我想为 URL 以特定字符串开头的页面上的每个 link 打开一个新的 window。例如:
https://whosebug.com/users/3763853/tonakis2108
我希望它在包含以下内容的页面上每隔 link 打开:
在新的 window 或标签上。
https://whosebug.com/users/"string" 之后的 url 在刷新后发生变化,我需要捕捉它。
我试过 window.open("")
在里面输入 https://whosebug.com/users*
但没有效果。
这在 Google 主页上运行并打开所有包含 mail.google.com.
的链接
// ==UserScript==
// @name Open Some Links
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @namespace http://www.yourDomainName.com/GreaseMonkey/
// @description Opens the links to [something] when the page loads.
// @include http*://www.google.com/
// @grant none
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true); //make a safe instance of jQuery
var baseUrl = "mail.google.com";
//The $ function is an alias to the jQuery function. It's shorter, and most commonly used.
//You pass a selector string into the $ function to select some elements on the page.
//We want to find all "a" tags (anchors) whose href attribute contains the baseUrl. *= is the "atribute contains" selector.
//See: http://api.jquery.com/category/selectors/ for other selectors.
//To make it clearer, after adding in the baseUrl, this will be $( "a[href*='mail.google.com']" )
var matchingLinks = $( "a[href*='" + baseUrl + "']" );
//Use jQuery to loop over each link and run a function for each one.
//$(this) returns a jQuery wrapper for the current node.
//This is nice because we can use jQuery functions on it, like attr, which returns the value of the specified attribute.
//If the page contains more than one link to the same href, it will be opened multiple times.
$(matchingLinks).each(
function(index)
{
window.open( $(this).attr( "href" ) );
}
);
已更新
我想为 URL 以特定字符串开头的页面上的每个 link 打开一个新的 window。例如:
https://whosebug.com/users/3763853/tonakis2108
我希望它在包含以下内容的页面上每隔 link 打开:
在新的 window 或标签上。 https://whosebug.com/users/"string" 之后的 url 在刷新后发生变化,我需要捕捉它。
我试过 window.open("")
在里面输入 https://whosebug.com/users*
但没有效果。
这在 Google 主页上运行并打开所有包含 mail.google.com.
的链接// ==UserScript==
// @name Open Some Links
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @namespace http://www.yourDomainName.com/GreaseMonkey/
// @description Opens the links to [something] when the page loads.
// @include http*://www.google.com/
// @grant none
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true); //make a safe instance of jQuery
var baseUrl = "mail.google.com";
//The $ function is an alias to the jQuery function. It's shorter, and most commonly used.
//You pass a selector string into the $ function to select some elements on the page.
//We want to find all "a" tags (anchors) whose href attribute contains the baseUrl. *= is the "atribute contains" selector.
//See: http://api.jquery.com/category/selectors/ for other selectors.
//To make it clearer, after adding in the baseUrl, this will be $( "a[href*='mail.google.com']" )
var matchingLinks = $( "a[href*='" + baseUrl + "']" );
//Use jQuery to loop over each link and run a function for each one.
//$(this) returns a jQuery wrapper for the current node.
//This is nice because we can use jQuery functions on it, like attr, which returns the value of the specified attribute.
//If the page contains more than one link to the same href, it will be opened multiple times.
$(matchingLinks).each(
function(index)
{
window.open( $(this).attr( "href" ) );
}
);