|
// ==UserScript== |
|
// @name Glitch Forum Remixer |
|
// @namespace yijiang |
|
// @include http://www.glitch.com/forum/general/ |
|
// @version 1.01 |
|
// ==/UserScript== |
|
|
|
function init () { |
|
var forumUrl = 'http://www.glitch.com/forum/'; |
|
|
|
var remixSetting = $.extend(JSON.parse(localStorage['remixSetting'] || '{}'), { |
|
enabledForum: ['announcements', 'bugs', 'ideas', 'api', 'marketplace'], |
|
otherForumCount: 6, |
|
generalForumCount: 10, |
|
cacheTime: 10 // in minutes |
|
}); |
|
|
|
// Do stuff to the general |
|
|
|
var hiddenGeneral = $('div.sub-contents-inner table tr') |
|
.slice(remixSetting.generalForumCount + 1) |
|
.add('div.pages') |
|
.hide(); |
|
|
|
$('<a>', { |
|
'class': 'button-tiny', |
|
text: 'Show more +', |
|
click: function() { |
|
hiddenGeneral.toggle(); |
|
return false; |
|
} |
|
}).insertBefore('div.sub-contents-inner p:last-child'); |
|
|
|
// Bring in the family! |
|
function insertForum (data, forumName) { |
|
var newForum = $(data).find('div.sub-contents-inner') |
|
.appendTo('div.sub-contents'); |
|
|
|
newForum.children('div').hide(); |
|
newForum.find('table tr') |
|
.slice(remixSetting.otherForumCount + 1).hide(); |
|
|
|
newForum.children('h1').wrap($("<a>", { |
|
href: forumUrl + forumName.toLowerCase() |
|
})); |
|
} |
|
|
|
remixSetting.enabledForum.forEach(function(forum){ |
|
var forumCache = forum + 'RemixCache', |
|
isCacheOld = (Date.now() - localStorage.lastRemixCacheTime) > |
|
(remixSetting.cacheTime * 60 * 1000); |
|
|
|
if (!localStorage.lastRemixCacheTime || |
|
!localStorage[forumCache] || |
|
isCacheOld) { |
|
|
|
$.get(forumUrl + forum + '/', function(data){ |
|
insertForum(data, forum); |
|
localStorage.lastRemixCacheTime = Date.now(); |
|
localStorage[forumCache] = data; |
|
}); |
|
} else { |
|
insertForum(localStorage[forumCache], forum); |
|
} |
|
}); |
|
} |
|
|
|
|
|
function inject () { |
|
var script = document.createElement('script'); |
|
script.innerHTML = '(' + init.toString() + ')();'; |
|
document.body.appendChild(script); |
|
|
|
var style = 'div.sub-contents-inner p:last-child, table.forum thead, a.description_toggle { display: none; } div.sub-contents-inner h1 {font-size: 24px; margin-bottom: 0 !important; } div.sub-contents-inner p:first-child { margin-top: -24px !important; } div.sub-contents-inner {padding-bottom: 1em; } table { margin: 0.4em 0 8px !important; }'; |
|
var styleEle = document.createElement('style'); |
|
styleEle.innerHTML = style; |
|
document.getElementsByTagName('head')[0].appendChild(styleEle); |
|
|
|
} |
|
|
|
inject(); |