这个问题针对的是所有狂热的绊脚石。
绊脚时,URL会被修改为如下所示。如您所见,所有原始内容都以
http://www.stumbleupon.com/su/...,然后是直接URL。

如果遇到有趣的事情,我喜欢通过复制URL并将其粘贴到需要的地方来共享它。问题是,当任何人单击它时,它都会拉起stumblebar,并将其带到内容中。我宁愿只拥有直接链接。

http://www.stumbleupon.com/su/1NKFju/:10yM7NnNO:GEYExz6R/toti.jjsoft.hu/public8/nyar1779/a28.jpg
http://www.stumbleupon.com/su/1uGF9s/:11Sd-1n0R:GEYExz6R/www.popularmechanics.com/technology/how-to/home-theater/4342672/
http://www.stumbleupon.com/su/237YPB/:GdOWpKe.:GEYExz6R/nerdsguidetoreading.com/Nerds_Guide_to_Reading/Science_Fiction.html/
http://www.stumbleupon.com/su/2pkYws/:1f+I-KON5:GEYExz6R/www.wizards.com/dnd/images/wd_maps/FRposterLarge_150.jpg/
http://www.stumbleupon.com/su/1ceVWt/:1fdJgD$uT:GEYExz6R/www.psych.upenn.edu/~andrewbg/images/Bluebell-carpet-480.jpg/
http://www.stumbleupon.com/su/2DdDRI/:GvgBVfdV:M-wRpADk/www.nature.com/news/higgs-triumph-opens-up-field-of-dreams-1.10970/


如您所见,前面的大多数术语都几乎相同。第三和最后一个短1个字符。

我想知道是否可以编写一个用户脚本,以将每次遇到的东西剥离掉而只留下直接链接,每次我绊到新页面时。

我想保留绊脚栏,但是当我到达新的绊脚页面时,请编辑URL并剥离它,而不实际重新加载页面。

最佳答案

由于Stumbleupon URL字段由固定数量的斜杠(/)分隔,因此您可以使用regex来获取URL,如下所示:

var targURL = location.href.replace (
    /^.+stumbleupon\.com\/su\/\w+\/[^\/]+\/(.+?)\/?$/i
    , "http://$1"
);




堆栈溢出(通常)不是脚本编写服务,但是我毫不费力地修改了我现有的脚本之一,而且似乎可以正常工作...

更新:以下是Greasemonkey脚本,因为这是最初指定的问题。要在Chrome中使用它,请安装Tampermonkey扩展程序。

// ==UserScript==
// @name     _Stumbleupon, add direct link to content page
// @include  http://www.stumbleupon.com/su/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==

$("#tb-like").before ( '                                                    \
    <li id      = "gmDirectLinkDisp"                                        \
        class   = "tb-btn tb-hide-visitor"                                  \
        title   = "Click for the direct link to the target page, below."    \
    >                                                                       \
        <button>Direct link</button>                                        \
    </li>                                                                   \
' );

$("#gmDirectLinkDisp button").click ( function () {
    var targURL = location.href.replace (
        /^.+stumbleupon\.com\/su\/\w+\/[^\/]+\/(.+?)\/?$/i
        , "http://$1"
    );
    window.prompt (
        "Press 'Ctrl+C' to copy to the clipboard; "
        + "then press `Enter` to close this dialog."
        , targURL
    );
} );

GM_addStyle ( "                             \
    #gmDirectLinkDisp {                     \
        float:              left;           \
    }                                       \
    #gmDirectLinkDisp button {              \
        padding:            0;              \
        margin-top:         10px;           \
    }                                       \
" );

10-05 20:53
查看更多