// ==UserScript==
// @name MTG better forum view
// @namespace https://greasyfork.org/en/users/13769
// @version 2.0
// @description Turns the forumn posts under Awesome HITS into a more managable list and adds a view for only hits posted.
// @author saqfish
// @include http://www.mturkgrind.com/threads/*
// @grant GM_log
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js
// @downloadURL none
// ==/UserScript==
var Page_nums = 0;
var Curr_page = 0;
var postcount = 0;
var runit = false;
var content2 = "";
var url = window.location.href;
var title =$('title').text();
var eee =$('#pageDescription > a:nth-child(1)').text();
if( eee === "Awesome HITS"){
runit = true;
}
var content = '
';
var content2 = '';
$(document).on('click', "[id^=view_hits]", function(e) {
$('body').empty();
$('body').append('');
console.log(title);
$('body').append(content2);
$(".post2").css('border','5px solid black');
$(".post2").css('list-style-position:','inside');
sort_list("main_list2");
});
$(document).on('click', "[id^=view_pages]", function(e) {
view_pages();
});
$(window).load(function(){
var Total_posts = 0;
if(runit)
{
$('link[rel="stylesheet"]').attr('disabled', 'disabled');
$('body').empty();
$('body').append("Loading...");
$.get(url, function(data)
{
var aBh = $(data);
Page_nums = aBh.find('div.PageNav').attr("data-last");
test(Page_nums);
});
}
});
function test(i){
var i2 = parseInt(i) + 1;
var i3 = parseInt(i) - 1;
console.log(i);
for(var a = 1; a < i2; a++){
var url2 = url + "page-" + a;
$.get(url2, function(data2){
var aCh = $(data2);
Curr_page = aCh.find('a.currentPage:first').text();
console.log(Curr_page);
content += '- Page '+ Curr_page + '
';
$('body').empty();
$('body').append("Loading Page "+ postcount +" out of " + i2 +" Page(s)...");
$(aCh).find("[id^=post] div.messageInfo.primaryContent > div.messageContent > article > blockquote").each(function(e) {
content += '- '+$(this).html()+'
';
});
content2 += '- Page '+ Curr_page + '
';
$(aCh).find('td.ctaBbcodeTableCellLeft').each(function(e) {
if ($(this).length !== 0){
content2 += '- '+$(this).html()+'
';
}
});
content += '
';
content2 += '
';
if(postcount === i3){
content += '
';
content2 += '
';
view_pages();
}
postcount++;
});
}
}
function view_pages(){
$('body').empty();
$('body').append('');
$('body').append("
Click on the page to view its content");
console.log(title);
$('body').append(content);
var toggle_flag = 0;
$('ul').toggleClass('no-js js');
$(".post").css('border','5px solid black');
$(".post").css('list-style-position:','inside');
var menuList = $(".js").find("li");
menuList.find("ul").hide();
menuList.on("click", function(){
menuList.find("ul").slideUp(0);
$(this).find("ul").slideToggle(0);
$(this).toggleClass("selected");
});
sort_list("main_list");
}
//Credit for sort - http://trentrichardson.com/2013/12/16/sort-dom-elements-jquery/
function sort_list(i){
var $people = $('ul.'+i),
$peopleli = $people.children('li');
$peopleli.sort(function(a,b){
var an = a.getAttribute('dn'),
bn = b.getAttribute('dn');
if(an > bn) {
return 1;
}
if(an < bn) {
return -1;
}
return 0;
});
$peopleli.detach().appendTo($people);
}
function addZeros(n) {
return (n < 10)? '00' + n : (n < 100)? '0' + n : '' + n;
}