Forked from WillSullivan/TaggedQuestionList.userscript
Last active
February 27, 2018 21:06
-
-
Save mogsdad/dc32bc9543e0576bf703 to your computer and use it in GitHub Desktop.
This userscript will add a list (initially hidden in an expandable div) containing links to every question listed on a tag page (i.e., questions/tagged/something). When a link in this list is clicked, it goes away. This allows you to easily open up many questions with this tag at the same time. Simply ctrl-click on the first link, then keep clic…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Tag list | |
// @namespace http://statestreetgang.net/ | |
// @version 1.2.0 | |
// @description Adds an expandable list containing a link to every question on the current tag page. Useful when you want to open many questions with the same tag at the same time. | |
// @match *://*.stackoverflow.com/questions/* | |
// @match http://stackoverflow.com/*tag*/* | |
// @match http://stackoverflow.com/questions/* | |
// @match http://stackoverflow.com/questions/new | |
// @match http://stackoverflow.com/search* | |
// @match http://meta.stackoverflow.com/*tag*/* | |
// @require http://code.jquery.com/jquery-latest.js | |
// ==/UserScript== | |
function exec(fn) { | |
var script = document.createElement('script'); | |
script.setAttribute("type", "application/javascript"); | |
script.textContent = '(' + fn + ')();'; | |
document.body.appendChild(script); // run the script | |
document.body.removeChild(script); // clean up | |
} | |
window.addEventListener("load", function () { | |
// script injection | |
exec(function () { | |
userscriptCSS(); | |
// Some question lists have a question-mini-list div, searches don't. To simplify, we'll insert our own if needed. | |
if ( !($('#question-mini-list').length) ) $('<div id=question-mini-list></div>').insertAfter('.welovestackoverflow'); | |
//$('<p class="linkyhead">Click here to open a list of all links on this page</p>').insertBefore('#question-mini-list'); // Temp - OK location | |
// re-sort list; move all the already handled shit to the top | |
$.each(["closed", "on hold", "migrated", "duplicate"], function (index) | |
{ | |
var items = $('.question-summary .summary:contains(' + this + ')'); | |
//items.closest('.question-summary').detach().insertAfter('.search-results'); | |
items.closest('.question-summary').detach().appendTo('#question-mini-list'); | |
}); | |
//return; | |
// get all the hrefs | |
var root = $('#mainbar'); | |
var hrefs = root.find('.question-hyperlink'); | |
console.log(hrefs); | |
if (hrefs.length === 0) | |
return; | |
console.log('here4'); | |
// I totally copypasted this. | |
//$('head').append($('<style type="text/css">.linkylist {margin: 0px;padding: 0px;}.linkyhead {padding: 5px 10px;cursor: pointer;position: relative;background-color:#FFCCCC;margin:1px;} .linkybody {padding: 5px 10px 15px;background-color:#F4F4F8;}</style>')); | |
var listroot = $('<div class="linkylist"/>'); | |
var listhead = $('<p class="linkyhead">Click here to open a list of all links on this page</p>'); | |
var listbody = $('<div class="linkybody"/>'); | |
$('.question').before(listroot); | |
listroot.prepend(listbody); | |
listroot.prepend(listhead); | |
listbody.hide(); | |
listhead.click(function (){ listbody.slideToggle(600); }); | |
// note that when you click a link it gets removed from the list. | |
hrefs.each(function () | |
{ | |
var parent = $('<span class="linkeyspan"/>'); | |
var linkey = $(this).clone().attr('target','_blank'); | |
linkey.click(function () { $(this).closest('.linkeyspan').remove(); }); | |
parent.prepend(linkey); | |
parent.prepend($('<br/>')); | |
listbody.prepend(parent); | |
}); | |
function addCss(cssString) { | |
var head = document.getElementsByTagName('head')[0]; | |
if (!head) return; | |
var newCss = document.createElement('style'); | |
newCss.type = "text/css"; | |
newCss.innerHTML = cssString; | |
head.appendChild(newCss); | |
} | |
function userscriptCSS() { | |
addCss ( | |
'.linkylist {margin: 0px;padding: 0px;}.linkyhead {text-align: right;padding: 5px 10px;cursor: pointer;position: relative;background-color:#FFCCCC;margin:1px;} .linkybody {padding: 5px 10px 15px;background-color:#F4F4F8;}' | |
); | |
} | |
}); | |
}, false); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment