我被侧栏中的相关问题和热门网络问题分心,所以我写了一个Greasemonkey脚本来隐藏它们。该脚本适用于Stack Exchange站点,但不适用于Stack Overflow本身。
// ==UserScript==
// @name minimal-stack-exchange
// @include http://www.stackoverflow.com/*
// @include http://www.stackexchange.com/*
// @include http://*.stackexchange.com/*
// @include http://*.stackoverflow.com/*
// @description Hide distracting links from StackExchange pages
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
$("#sidebar").hide();
$("#herobox").hide();
$("#footer").hide();
我清除了我的Firefox缓存,使用Inspect Element确定我使用了正确的div ID,但没有成功。
答案 0 :(得分:3)
解决方案是通配符http://stackoverflow.com
未捕获http://*.stackoverflow.com/*
,因此添加另一个包含行修复了问题。
// ==UserScript==
// @name minimal-stack-exchange
// @include http://www.stackoverflow.com/*
// @include http://www.stackexchange.com/*
// @include http://*.stackexchange.com/*
// @include http://*.stackoverflow.com/*
// @include http://stackexchange.com/*
// @include http://stackoverflow.com/*
// @description Hide distracting links from StackExchange pages
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
$("#sidebar").hide();
$("#herobox").hide();
$("#footer").hide();
答案 1 :(得分:3)
在这种情况下,更好的解决方案是使用@match
Doc代替@include
。 @match
智能处理领先的*.
并提供更好的性能和安全性,尤其是在Chrome上。
以下@match
指令完成:
http://
和https://
,因为所有Stack Exchange站点都支持SSL。// @match *://*.askubuntu.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
注意:对于实际脚本,我建议您也排除某些堆栈交换页面,除非您明确编写它们。
请参阅 Stack Apps 上的"Complete list of sites to @include / @match into my script?"。