26

So if you try to onebox a onebox from a different chat server, this weirdness happens. Basically, it generates this URL:

https://chat.stackexchange.com//stackoverflow.com/questions/25609915/php-sql-match-against

Now, obviously that isn't right. I've also tested this here, and I'm assuming it's broken on chat.SO too. Can this be fixed?

3 Answers 3

3

Should be fixed up now. We were a wee bit overzealous and didn't check for the links that started with /, but were already protocol-relative rather than site-relative.

1
  • Lovely. Indeed, it is fixed. :)
    – hichris123
    Commented Dec 30, 2015 at 23:12
8
+100

Damnit, Shog knows my weak spot. I wrote a quick 'n dirty userscript (source) to patch this until it's fixed properly.

Tested in Chrome on the example in the question and the one that prompted the bounty, but it should work in Firefox too.

1
  • Well, you're being paid well for this! :-) Commented Apr 7, 2015 at 21:50
7
+50

Downside of the script from Tim is that when hovering over the link the broken link is shown. My script fixes the DOM.

// ==UserScript==
// @name         Fix broken double links
// @namespace    http://stackoverflow.com/users/578411/rene
// @version      0.1
// @description  fix one-one-boxes
// @author       rene
// @match        *://chat.meta.stackexchange.com/*
// @match        *://chat.stackexchange.com/*
// @match        *://chat.stackoverflow.com/*
// @grant        none
// ==/UserScript==

(function() {

    // fix the link in the one box
    function fixup(item) {
        var a = $(item),
            hrefs = a.prop('href').split('//');
        if (hrefs.length > 2) {
            hrefs.shift();
            hrefs.shift();
            a.prop('href', '//' + hrefs.join('//'));
        }
    }

    // create an observer instance
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            var i,
                box;
            for(i=0; i< mutation.addedNodes.length; i = i + 1) {
                box = $(mutation.addedNodes[i]);
                console.log(box);
                box.find('div.ob-post-title a').each(function () {
                    fixup(this);
                });
            }
        });    
    });

    // chat window
    if ($('div#chat').length >0) {
        console.log('obs');
        observer.observe($('div#chat')[0], {childList:true, subtree: true});
    }

    //transcript
    $('div.ob-post-title a').each(function () {
        fixup(this);
    });
}())
2
  • 2
    I like both of these scripts, but I like Tim's more because it's simpler and doesn't bother replacing the URL until I click. OTOH, this uses jQuery... Decisions, decisions...
    – Shog9
    Commented Apr 8, 2015 at 2:23
  • Thanks @Shog9 much appreciated.
    – rene Mod
    Commented Apr 9, 2015 at 19:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .