简体   繁体   English

Tampermonkey - 匹配默认开始页面

[英]Tampermonkey - Match default start page

I try to remove the 8 tiles with the last seen pages on the start page of Chrome. 我尝试删除Chrome开头页面上最后看到的8个图块。 You know, the page which appears if you start Chrome. 您知道,如果您启动Chrome,则会显示该页面。

But since there is no URL at all, I don't know what I have to enter at @match. 但由于根本没有URL,我不知道我必须在@match上输入什么。 I've tried // @match * but the script is not executed. 我试过// @match *但脚本没有执行。

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        *
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    setInterval(function(){
        var box = document.getElementById("mv-tiles");
        box.remove();
    },10
    );
})();

Use @include instead of @match . 使用@include而不是@match

Also, it's possible to get the URL by going to the console and running window.location.href 此外,可以通过转到控制台并运行window.location.href来获取URL

I tried this and it worked: 我试过这个并且它有效:

// @include      http*://*chrome/newtab*

Maybe don't use an interval there, since it'll keep throwing errors once the element is not there anymore. 也许不要在那里使用一个区间,因为一旦元素不再存在,它将继续抛出错误。

I'd use something like this: 我会用这样的东西:

injectStyles('#mv-single {display: none;}');

function injectStyles (styles) {
    var style       = document.createElement('style');
    style.type      = 'text/css';
    style.innerHTML = styles;
    document.head.appendChild(style);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM