1

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.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295

2 Answers2

1

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;           \
    }                                       \
" );
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Thanks for the response. I was thinking the same thing about the / characters but I have no background in javascript so I was struggling with the rest. From the looks of it, it looks more difficult that I had originally imagined. I installed the script and for me it does not work on Windows or Ubuntu. Chrome v. 21.0.1180.60 –  Aug 05 '12 at 01:02
  • This question was tagged "Greasemonkey" which means Firefox, no mention of Chrome was made. The script was tuned for Firefox, and would need a bit of a rewrite for Chrome. – Brock Adams Aug 05 '12 at 01:20
  • Good point. That was my bad. Tested and works in Firefox. I appreciate your help. Ill look into modifying it for chrome. Should be a good little project –  Aug 05 '12 at 05:06
  • To work on Chrome, First change the `(<><![CDATA[ ...` constructs. You can't do multi-line strings that way in Chrome. Then the script will probably work if you install it with Chrome's Tampermonkey extension. ... Otherwise, just include jQuery the Chrome userscript way (see the highest voted "userscripts" question on this site) -- if you don't want to use Tampermonkey. If I feel frisky, I might translate the script in a bit (no promises). – Brock Adams Aug 05 '12 at 05:32
0

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.

Ben
  • 1
  • He's not using Firefox, he's using Chrome. – Brock Adams Aug 09 '12 at 03:51
  • Would ya look at that, the chrome extension works the same way =] I stopped using the bar long ago as it was clunky and slowed pages down. Seems to have improved a lot since then –  Aug 09 '12 at 04:58