Skip to content

Instantly share code, notes, and snippets.

@ZhangYiJiang
Created August 28, 2012 03:59
Show Gist options
  • Save ZhangYiJiang/3494838 to your computer and use it in GitHub Desktop.
Save ZhangYiJiang/3494838 to your computer and use it in GitHub Desktop.
Glitch Forum Remix

To configure this script, open your browser's console (F12) and copy this in

localStorage.remixSetting = JSON.stringify({
	// Add or remove forums to load by editing these. 
	enabledForum: ['announcements', 'bugs', 'ideas', 'marketplace'], 
	otherForumCount: 6, // Number of posts to show from the other forum
	generalForumCount: 10, // Number of posts to show from General 
	cacheTime: 10 // Amount of time to cache the results from other forums in minutes
});

edit it to suit your taste and hit enter

// ==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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment