尝试使用 Chrome 扩展程序删除 Gmail 中的广告
我正在尝试使用 Chrome 扩展程序,该扩展程序将删除 Gmail 右侧窗格中显示的广告,并将我想要的信息放在那里。 (我还没有决定到底要放什么;在几个想法之间犹豫不决,包括外部内容和/或附件。)
广告(通常)包含在
< ;/div>
元素。但我似乎无法在我的扩展程序或控制台中选择它。我已经通过编写一个扩展来测试我的 manifest.json
设置,该扩展在页面顶部添加了一个多余的 div,并且效果很好 - 我刚刚创建了一个新元素,但是
document.body.parentElement.insertBefore(new_el, document.body);
,我'我现在想做的只是撕掉广告并放入一些虚拟文本,或者只是将文本放在广告上方。这是我的 content_script.js 文件中调用的主要函数。
function modifyPage(txt) {
var container = document.getElementsByClassName('oM')[0];
container.innerHTML = txt;
}
function modifyPage(txt) {
var insert = document.createElement('div');
insert.innerText = txt;
var container = document.getElementsByClassName('oM')[0];
document.body.parentElement.insertBefore(insert, container);
}
我什至尝试过 jQuery:
function modifyPage(txt) {
$('.oM').html(txt);
}
此外,尝试使用 Chrome 控制台检索
不会返回任何内容 - 尽管我可以在源代码中看到它。I'm experimenting with a Chrome extension that will remove the ads displayed in the right-hand pane in Gmail and instead put the information I want there. (I haven't decided exactly what to put there yet; vacillating between several ideas, including external content and/or attachments.)
The ads are (usually) contained in a <div class="oM"></div>
element. But I can't seem to select that either in my extension or in the console.
I've tested my manifest.json
settings by writing an extension that added a superfluous div to the top of the page, and that worked fine -- I just created a new element and
document.body.parentElement.insertBefore(new_el, document.body);
However, what I'm trying to do now is just rip out the ads and put in some dummy text, or just put the text above the ads. This is the main function called in my content_script.js file.
function modifyPage(txt) {
var container = document.getElementsByClassName('oM')[0];
container.innerHTML = txt;
}
function modifyPage(txt) {
var insert = document.createElement('div');
insert.innerText = txt;
var container = document.getElementsByClassName('oM')[0];
document.body.parentElement.insertBefore(insert, container);
}
I've even tried to jQuery:
function modifyPage(txt) {
$('.oM').html(txt);
}
Also, trying to retrieve the <div class="oM">
using the Chrome console returns nothing -- even though I can see it right there in the source.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
设置 jquery 选择器的执行延迟。 Google Tubes 比在页面加载时使用静态 div 类要复杂一些。
Set a delay on the execution of your jquery selector. The Google Tubes are a bit more complicated than using static div classes on page load.
与其用 JS 去除广告,不如用 CSS 隐藏它们:
Rather than remove the ads with JS, just hide them with CSS:
我正在使用
AdBlock
+Chrome 插件(或扩展程序)
。它工作得很好,它是一个捐赠软件,我猜作者使用 jquery
{display:none }
来隐藏
或删除
广告带有自定义过滤器列表。I'm using
AdBlock
+Chrome add-in(or extension)
.It works very well it's a donation-ware, I'm guessing the author use jquery
{display:none }
tohide
orremove
the ads with a custom filter lists.