如果页面在代码中具有此元素,则TAMPERMONKEY脚本将关闭选项卡

发布于 2025-02-10 17:20:16 字数 355 浏览 1 评论 0原文

我有一个带有列的页面,如果第一列具有此src =“ imgs/newmail.gif”,则需要关闭选项卡

< tr> < td align =“中心” bgcolor =“#ffffff”> 1</td> < td bgcolor =“#ffffff” align =“ center”> < img src =“ imgs/newmail.gif” border =“ 0”> </td>

I have a page with columns and I need to close the tab if the first column has this src="imgs/newmail.gif"

I will send you a screenshot of part of the code.
<tr> <td align="center" bgcolor="#FFFFFF">1</td> <td bgcolor="#FFFFFF" align="center"> <img src="imgs/newmail.gif" border="0"> </td>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守不住的情 2025-02-17 17:20:16

@vlad您没有给我们太多使用的工作,并且以下脚本未经测试,但请尝试以此作为起点:

// ==UserScript==
// @name         Close Tab if Img Found
// @namespace    http://tampermonkey.net/
// @match        https://example.com/*
// @grant        window.close
// ==/UserScript==

(function() {
    'use strict';
    const $ = document.querySelector.bind(document);
    const $ = document.querySelectorAll.bind(document);

    setTimeout(() => {
        //allow a few ms for page to fully load
        if ( $('img[src=imgs/newmail.gif"]') !== undefined && $('img[src=imgs/newmail.gif"]') !== null){
            window.close();
        }
    });
})();

您将需要更改// match line,并且您可能有调整观察正确图像标签的行。

给我们更多信息,我们可以尝试为您进行更多调整。

PS-上面的代码不是jQuery-仔细查看。

参考:

https://www.tampermonkey.net/documentation.php#_grant

@Vlad you haven't given us much to work with, and the below script is untested, but try this as a starting point:

// ==UserScript==
// @name         Close Tab if Img Found
// @namespace    http://tampermonkey.net/
// @match        https://example.com/*
// @grant        window.close
// ==/UserScript==

(function() {
    'use strict';
    const $ = document.querySelector.bind(document);
    const $ = document.querySelectorAll.bind(document);

    setTimeout(() => {
        //allow a few ms for page to fully load
        if ( $('img[src=imgs/newmail.gif"]') !== undefined && $('img[src=imgs/newmail.gif"]') !== null){
            window.close();
        }
    });
})();

You will need to change the //match line, and you might have to tweak the line that watches for the correct image tag.

Give us more information and we can try to tweak it a little more for you.

PS - The above code is not jQuery - look carefully.

Reference:

https://www.tampermonkey.net/documentation.php#_grant

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文