gpt4 book ai didi

image - Greasemonkey 脚本,用于查找具有特定条件的行

转载 作者:行者123 更新时间:2023-12-02 02:21:08 24 4
gpt4 key购买 nike

我尝试了一些不同的方法来查找表中列包含特定链接的行。

我的目标:当指向 xyz 的链接与图像位于同一行时替换图标。

到目前为止,这是我的代码片段:

var rows = document.getElementsByTagName("tr");
for(var i = rows.length - 1; i >= 0; i--) {
var links = rows[i].getElementsByTagName("a");
for(var k = links.length - k; k >= 0; k--) {
if (links[k].href =="http://www.XXXX.net/forum/index.php?showforum=121"){
var images = rows[i].getElementsByTagName("img");
for (var j=0;j<images.length;j++) {
images[j].src = "http://www.XXXX.net/forum/folder_post_icons/icon7.gif";
}
}
}
}

我很确定这不是最好的概念。但正如您可能看到的那样,我尝试在所有行中搜索链接,一旦找到论坛“121”的链接,我就尝试替换该特定行中的所有图像。

我得到的是网站上的每张图片都被替换了。

最佳答案

因为它很简单,所以这里有一个完整的脚本。
它使用 jQuery这是a handy jQuery reference .请特别注意选择器部分(与 CSS 选择器几乎相同)。

回复:“我得到的是网站上的每张图片都被替换了。” ...

这可能是因为搜索条件太宽泛了。如果它是一个设计不佳(使用表格布局)的页面,则每个图像都可能位于带有目标链接的表格行中!

发布 Greasemonkey 问题时,链接到目标页面,或者至少发布足够多的页面 HTML,以便我们可以调整 GM 脚本以匹配。


无论如何,这会起作用,可能需要等待有关目标页面的更多信息:

// ==UserScript==
// @name _Replace image on custom-targeted row
// @include http://www.XXXX.net/forum/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// ==/UserScript==

//--- This may need tuning based on information not provided!
var targetLinks = $("tr a[href*='showforum=121']");

//--- Loop through the links and rewrite images that are in the same row.
targetLinks.each ( function () {
//--- This next assumes that the link is a direct child of tr > td.
var thisRow = $(this).parent ().parent ();

//--- This may need tuning based on information not provided!
var images = thisRow.find ("td img");

//--- Replace all target images in the current row.
images.each ( function () {
$(this).attr (
'src',
'http://www.XXXX.net/forum/folder_post_icons/icon7.gif'
);
} );
} );

关于image - Greasemonkey 脚本,用于查找具有特定条件的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8098115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com