Skip to content

Instantly share code, notes, and snippets.

Created August 27, 2015 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/34f9069d2f10b0836e4f to your computer and use it in GitHub Desktop.
Save anonymous/34f9069d2f10b0836e4f to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name DLP - Expanded Search Results
// @namespace Makaze
// @description Shows expanded posts in search results instead of snippets.
// @include *://forums.darklordpotter.net*
// @grant none
// @version 1.0.0
// ==/UserScript==
var MakazeScriptStyles,
styleElem;
function createElement(type, callback) {
var element = document.createElement(type);
callback(element);
return element;
}
function runInJQuery(code) {
document.body.appendChild(createElement('script', function(jQ) {
jQ.type = 'text/javascript';
jQ.src = 'https://code.jquery.com/jquery-2.1.3.min.js';
jQ.onload = function() {
document.body.appendChild(createElement('script', function(content) {
content.appendChild(document.createTextNode('jQuery.noConflict();' + code));
}));
};
}));
}
function expandResults() {
jQuery('table[id*=post]').each(function() {
var id = this.id.match(/\d+/)[0],
context = this.getElementsByTagName('em')[0].parentNode,
children = context.getElementsByTagName('em')[0].childNodes;
jQuery(context).append(createElement('div', function(cont) {
cont.className = 'fullPost';
cont.id = 'fullPost' + id;
}));
while (children.length > 1) {
if (children[0].nodeType !== 1 || children[0].tagName !== 'A') {
children[0].remove();
} else {
children[1].remove();
}
}
context.getElementsByTagName('em')[0].style.display = 'block';
context.getElementsByTagName('em')[0].style.marginBottom = '1em';
jQuery(context).find('.fullPost').load('https://forums.darklordpotter.net/showpost.php?p=' + id + ' #post_message_' + id, function() {
jQuery('#fullPost' + id).fadeIn('slow');
});
});
}
if (document.getElementsByClassName('navbar')[0] != null && document.getElementsByClassName('navbar')[document.getElementsByClassName('navbar').length - 1].textContent.trim() === 'Search Results') {
//Styling
if (document.getElementById('MakazeScriptStyles') == null) {
MakazeScriptStyles = createElement('style', function(style) {
style.id = 'MakazeScriptStyles';
style.type = 'text/css';
});
document.head.appendChild(MakazeScriptStyles);
}
styleElem = document.getElementById('MakazeScriptStyles');
if (styleElem.hasChildNodes()) {
styleElem.childNodes[0].nodeValue += '\n\n';
} else {
styleElem.appendChild(document.createTextNode(''));
}
styleElem.childNodes[0].nodeValue +=
'.fullPost {\n' +
'display: none;\n' +
'}\n\n' +
'.fullPost, .fullPost * {\n' +
'font-size: 11px;\n' +
'}';
runInJQuery(
createElement.toString() +
expandResults.toString() +
'expandResults();'
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment