// ==UserScript== // @name Duplicate Question Suggestion Boxes // @description This will add the possibility to show duplicate question suggestions and related questions in a neat place for any question on any SE site. // @namespace Something. // @include http://*stackoverflow.com/questions/* // @include http://*serverfault.com/questions/* // @include http://*superuser.com/questions/* // @include http://*.stackexchange.com/questions/* // @include http://meta.*.com/questions/* // ==/UserScript== function with_jquery(f) { var script = document.createElement("script"); script.type = "text/javascript"; script.textContent = "(" + f.toString() + ")(jQuery);"; document.body.appendChild(script); }; with_jquery(function($) { $(function () { var waitForClose, waitForDuplicate, waitForNoPopup, waitForOpenPopup; var canOpenPopup = true; var closeLink = $("a[id^='close-question']"); function fireClose(id) { clearInterval(waitForClose); clearInterval(waitForDuplicate); clearInterval(waitForNoPopup); clearInterval(waitForOpenPopup); if ($('#duplicate-question').size() > 0) { $('#duplicate-question').val(id).focus().keypress().keydown().keyup(); setTimeout(function() { $('.popup-actions-cancel').focus(); setTimeout(function() { $('.popup-submit').focus(); }, 69); }, 69); } else { setTimeout(function () { canOpenPopup = true; }, 3500); $('.popup-close').click(); $('.error-notification').click(); waitForNoPopup = setInterval(function () { if (($('.popup').size() == 0) && ($('.error-notification').size() == 0) ) { clearInterval(waitForNoPopup); waitForOpenPopup = setInterval(function () { if (canOpenPopup) { canOpenPopup = false; clearInterval(waitForOpenPopup); var link = document.getElementById(closeLink.attr('id')); if (document.createEvent) { var event = document.createEvent("MouseEvents"); event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); link.dispatchEvent(event); } else if (link.fireEvent) { link.fireEvent("onclick"); } waitForClose = setInterval(function() { if ($('#close-question-form').size() > 0 && $('#close-1').size() > 0) { clearInterval(waitForClose); var link = document.getElementById("close-1"); if (document.createEvent) { var event = document.createEvent("MouseEvents"); event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); link.dispatchEvent(event); } else if (link.fireEvent) { link.fireEvent("onclick"); } waitForDuplicate = setInterval(function() { if ($('#duplicate-question').size() > 0) { clearInterval(waitForDuplicate); $('#duplicate-question').val(id).focus().keypress().keydown().keyup(); $('#duplicate-question').parent().find('.edit-field-overlay').remove(); $('#duplicate-question').parent().find('.actual-edit-overlay').remove(); $('#duplicate-question').hide(); setTimeout(function() { $('.popup-actions-cancel').css('outline', 'none').focus(); setTimeout(function() { $('.popup-submit').focus(); }, 2 * 69); }, 69); } }, 69); } }, 69); } }, 69); } }, 69); } return false; } // Remove extra margin, add the possible duplicate question suggestions and related questions. $('div#question-header').css('margin-bottom', '0px').css('clear', 'both').after('
'); // Easy-peasy-lemon-squeezy. var both = $('div#question-suggest, div#question-related') var qs = $('div#question-suggest'); var qr = $('div#question-related div'); // Set the width, height, border, margin, padding and overflow of the two boxes. both.width('50%').height(91).css('margin-bottom', 10).css('padding', 0).css('overflow-y', 'scroll').css('width', '480px'); // Load the possible duplicate question suggestions. var s = $("#question-header").find("a:first").html(); qs.load("/search/titles?like=" + escape(s), function (){ // Remove nag message that was meant for the OP. qs.find("div.system-alert:first").remove(); // Remove the header. qs.find("label:first").remove(); // Don't mark the question we are viewing as a possible duplicate. qs.find("a.question-hyperlink").each(function(){ if ($(this).html() == s) { $(this).parent().parent().remove(); } }); // Override any site-specific cosmetics. qs.find('a').removeClass('question-hyperlink').css('color', 'black').parent().css('line-height', '15px'); // Magic allows us to do this FX elsewhere... qs.find("div:first").css('overflow-y', 'visible'); // Cosmetics allows us to mimic the related questions. qs.find('div.answer-summary').css('padding', 3); qs.find('div.answer-summary > a').remove(); qs.find('div.answer-summary > div').css('margin-top', 0).css('padding-left', 0).css('width', '100%'); qs.find('div.answer-link > span').remove(); $('#question-suggest .answer-link a').each(function (){ var link = $(this); if (link.html().length > 70) { link.html(link.html().substr(0, 60) + "...?"); } link.click(function(event) { event.preventDefault(); fireClose(link.attr('href').replace('/questions/', '').split("/")[0]); return false; }); }); }); // Let's copy the related questions from the sidebar into our new box system. $('h4#h-related').parent().find('div.spacer').each(function (i) { qr.append('
'); }); $('#question-related .answer-link a').each(function (){ var link = $(this); if (link.html().length > 70) { link.html(link.html().substr(0, 60) + "...?"); } link.click(function(event) { event.preventDefault(); fireClose(link.attr('href').replace('/questions/', '').split("/")[0]); return false; }); }); // Override any site-specific cosmetics. qr.find('a').removeClass('question-hyperlink').css('color', 'black').parent().css('line-height', '15px'); // There's no point in having the same information listed twice on a page... $('h4#h-related').parent().remove(); // Well; question titles are important, too... $('div#mainbar').before($('div#question-header').css('border-bottom', 'solid 0px #FFFFFF').css('margin-left', '58px')); }); });