使用Greasemonkey删除表格 [英] Use Greasemonkey to remove table

查看:63
本文介绍了使用Greasemonkey删除表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用油脂猴子用自己的桌子替换桌子.具有该表的页面包含2个具有相同类且没有ID的表.

I am trying to replace a table with my own table using grease monkey. The page that has the table has 2 tables with the same class and no IDs.

我只需要替换第二个表(用我自己的表),而对第一个表什么也不做.没有什么可以真正使第二张表与第一张表区分开,因此,我唯一想到的就是尝试在第二张表周围添加DIV,但无法弄清楚.

I need to replace only the second table (with my own table) and do nothing to the first table. There is nothing that really makes the second table unique from the first table, so the only thing I can think of is trying to add a DIV around the second table, but cant figure it out.

有什么想法吗?这是页面代码:

Any ideas? Heres the page code:

<h3>Table 1</h3>
<table class="details" border="1" cellpadding="0" cellspacing="0">
<tbody><tr>
<th>1</th>
<td>2</td>
</tr> 
</tbody></table>

<h3>Table 2</h3>
<table class="details" border="1">
<tbody><tr>
<th>1</th>
<td>2</td>
</tr><tr>
<th>3</th>
<td>4</td>
</tr> 
</tbody></table>

推荐答案

您可以使用xpath查找第二个表,并对其进行处理. xpath表达式为(//table[@class="details"])[2].下面我添加了一个使用(//pre)[1]的示例,它将在此页面上找到第一个代码块,我将其隐藏为示例.因此,这隐藏了您问题中的页面代码. (//pre)[2]将隐藏我的脚本.

You can use xpath to find the second tables, and do something with it. The xpath expression would be (//table[@class="details"])[2]. Below I added an example which uses (//pre)[1] instead, this will find the first code block on this page, I will hide it as an example. So this hides the page code from your question. (//pre)[2] will hide my script.

另请参见此处以获取有关如何使用的教程xpath.

See Also here for a tutorial how to use xpath.

// ==UserScript==
// @name           so-test
// @namespace      test
// @include        http://stackoverflow.com/questions/4635696/use-greasemonkey-to-remove-table
// ==/UserScript==

// find first <pre> on this page 
var xpathResult = document.evaluate('(//pre)[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
var node=xpathResult.singleNodeValue;

// now hide it :)
node.style.display='none';

这篇关于使用Greasemonkey删除表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆