Skip to content

Instantly share code, notes, and snippets.

@barbuza
Created August 20, 2009 16:40
Show Gist options
  • Save barbuza/171183 to your computer and use it in GitHub Desktop.
Save barbuza/171183 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name lepra.newcomments
// @namespace http://leprosorium.ru
// @include http://leprosorium.ru/comments/*
// @include http://*.leprosorium.ru/comments/*
// @include http://leprosorium.ru/my/inbox/*
// ==/UserScript==
(function() {
var
new_comments = $$('#js-commentsHolder .new'),
count = new_comments.length,
current = -1,
initialPosition = Cookie.read('newcomments-panel') || 'right',
scrollFx = new Fx.Scroll(document.body, {
duration: 200,
wait: false
}),
scroll = function() {
scrollFx.start(0, new_comments[current].getTop());
positionDisplay.firstChild.data = (current + 1) + ' / ' + count;
},
toolbar = new Element('div', {
styles: {
background: '#fffff0',
position: 'fixed',
top: 300,
left: (initialPosition === 'left') ? 0 : null,
right: (initialPosition === 'right') ? 0 : null,
padding: '5px 8px',
border: '1px solid #ddd',
'z-index': 5000
}
}).inject(document.body),
nextBtn = new Element('span', {
styles: {
padding: '0px 5px',
cursor: 'pointer',
color: '#333',
},
events: {
mousedown: function(e) {
e.stop();
if (count && (current < (count - 1))) {
current ++;
scroll();
}
}
},
html: '&darr;'
}).inject(toolbar),
prevBtn = new Element('span', {
styles: {
padding: '0px 5px',
cursor: 'pointer',
color: '#333'
},
events: {
mousedown: function(e) {
e.stop();
if (count && (current > 0)) {
current --;
scroll();
}
}
},
html: '&uarr;'
}).inject(toolbar),
positionDisplay = new Element('div', {
styles: {
color: '#666',
'font-size': 10,
'text-align': 'center'
},
html: count.toString()
}).inject(toolbar),
movePanel = function(to) {
Cookie.write('newcomments-panel', to, {
path: '/',
duration: 999
});
toolbar.setStyles({
left: (to === 'left') ? 0 : null,
right: (to === 'right') ? 0 : null
});
moveBtn.innerHTML = (to === 'left') ? '&rarr;' : '&larr;';
initialPosition = to;
},
moveBtn = new Element('div', {
styles: {
cursor: 'pointer',
'font-size': 12,
'text-align': 'center'
},
events: {
mousedown: function(e) {
e.stop();
movePanel((initialPosition === 'right') ? 'left' : 'right');
}
},
html: (initialPosition === 'left') ? '&rarr;' : '&larr;'
}).inject(toolbar);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment