【问题标题】:Tampermonkey - Match default start pageTampermonkey - 匹配默认起始页
【发布时间】:2017-01-24 08:42:53
【问题描述】:

我尝试删除 Chrome 起始页上最后看到的页面的 8 个图块。 你知道,如果你启动 Chrome 会出现的页面。

但由于根本没有 URL,我不知道我必须在 @match 输入什么。 我试过// @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
    );
})();

【问题讨论】:

  • 设置 // @match *://*/_/chrome/newtab* 似乎有效。

标签: javascript tampermonkey


【解决方案1】:

使用@include 代替@match。

此外,可以通过转到控制台并运行 window.location.href 来获取 URL

我试过了,效果很好:

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

也许不要在那里使用间隔,因为一旦元素不再存在,它会继续抛出错误。

我会使用这样的东西:

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

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

【讨论】:

  • 是的,你是对的,它也可以在没有间隔的情况下工作。
  • 我不得不接受这个答案作为解决方案,因为它不再起作用了。
猜你喜欢
  • 2015-04-13
  • 2019-01-28
  • 1970-01-01
  • 2012-07-22
  • 2013-02-16
  • 1970-01-01
  • 1970-01-01
  • 2018-05-07
  • 1970-01-01
相关资源
最近更新 更多