[英]Chrome extension to modify the contents of a page
I am interested in creating a Chrome extension which can manipulate some of the content of specific webpages..我有兴趣创建一个 Chrome 扩展程序,它可以操作特定网页的某些内容。
I want to replace something like this:我想替换这样的东西:
<td class="Data">Phone:</td>
with something like this:像这样:
<span title="Telephone number including area code."><td class="Data">Phone:</td></span>
The reason for this is to add hover-over or tool-tip text to certain parts of an existing website.这样做的原因是将悬停或工具提示文本添加到现有网站的某些部分。
Is this possible with a Chrome extension?这可以通过 Chrome 扩展程序实现吗? If so, how could this be done?
如果是这样,这怎么可能? Thank you.
谢谢你。
You can do this with a Chrome extension, but even easier would be a bookmarklet.您可以使用 Chrome 扩展程序执行此操作,但使用书签更简单。
Basically, the browser allows you to run javascript in the address bar in the form javascript://your valid javascript.基本上,浏览器允许您以 javascript://your valid javascript 的形式在地址栏中运行 javascript。
So write the script to achieve your desired results, minify it to a single line, then bookmark the results.因此,编写脚本以实现您想要的结果,将其缩小为一行,然后为结果添加书签。 It can then also be used in any browser.
然后它也可以在任何浏览器中使用。
I don't understand the exact use case, and your html is not valid, but you could do something similar pretty easily, this example assumes jquery is available:我不明白确切的用例,你的 html 无效,但你可以很容易地做类似的事情,这个例子假设 jquery 可用:
javascript:$(function(){ $('td:contains("Phone")').attr('title', 'Telephone number including area code'); });
Note: the :contains() selector is case-sensitive注意::contains() 选择器区分大小写
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.