This question is directed at all of the avid stumblers, out there... When stumbling the URL is modified to look like the ones listed below. As you can see all the original content is preceded by http://www.stumbleupon.com/su/... and then the direct URL is after.

If I come across something interesting I like to share it by copying the URL and pasting it wherever need be. The problem is that, when anyone clicks on it, it pulls up the stumblebar for them and takes them to the content. I would much rather just have only the direct link.

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/

As you can see, most of the preceding stumble jargon is almost the same length. The 3rd and last however are 1 char shorter.

I would like to know if a userscript can be written to strip the stumble stuff out and just leave the direct link, every time I stumble to a new page.

I would like to keep the stumble bar but when I arrive at my newly stumbled page, edit the URL and strip it and not actually reload the page.

有帮助吗?

解决方案

Since the Stumbleupon URL-fields are delimited by a fixed number of slashes (/), you can use regex to get the URL, like so:

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

Stack Overflow is not (normally) a script writing service, but I modified one of my existing scripts with no difficulty, and it seems to work...

Update: The following is a Greasemonkey script, because that is what the question originally specified. To use it in Chrome, install the Tampermonkey extension.

// ==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;           \
    }                                       \
" );

其他提示

Use the StumbleUpon Firefox extension and you will be stumbled straight to the URL rather than the a framed version of it. The URL shown in your address bar will not have stumbleupon.com/su/xxxx in front of it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top