Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var e621SlideGetJSON = function(url, parameters, successHandler, errorHandler) {
- var xhr = new XMLHttpRequest();
- xhr.open('post', url, true);
- xhr.responseType = 'json';
- xhr.onload = function() {
- var status = xhr.status;
- if (status == 200) {
- successHandler && successHandler(xhr.response);
- } else {
- errorHandler && errorHandler(status);
- }
- };
- xhr.setRequestHeader('Accept', "text/javascript, text/html, application/xml, text/xml, */*");
- xhr.setRequestHeader('Content-type', "application/x-www-form-urlencoded; charset=UTF-8");
- xhr.setRequestHeader('X-Prototype-Version', "1.6.0.3");
- xhr.setRequestHeader('X-Requested-With', "XMLHttpRequest");
- xhr.send(parameters);
- };
- var e621SlideFailJSON = function(status) {
- alert(status);
- };
- var e621SlideImageBuffer = Array();
- var e621SlideCurrentPostId = -1;
- var e621SlideCurrentIndex = -1;
- var e621SlideLoadImageArray = function() {
- var thumbs = document.getElementsByClassName('thumb');
- for (var i = 0; i < thumbs.length; i++) {
- var currentThumb = thumbs[i];
- var postId = currentThumb.id.substring(1);
- if (currentThumb.className.indexOf("blacklisted") >= 0) {
- e621SlideDownVote(postId);
- continue;
- }
- e621SlideLoadImageData(postId);
- }
- };
- var e621SlideLoadImageData = function(postId) {
- var placeholder = {
- postId: postId,
- image: document.createElement('IMG'),
- link: document.createElement('A')
- };
- placeholder.link.appendChild(placeholder.image);
- placeholder.link.target = '_blank';
- placeholder.image.style.border = 'none';
- e621SlideImageBuffer.push(placeholder);
- var succ = function(response) {
- if (response.file_ext === 'swf') {
- placeholder.image.src = '/download-preview.png';
- } else {
- placeholder.image.src = response.sample_url;
- }
- placeholder.link.href = '/post/show/' + postId;
- };
- e621SlideGetJSON('/post/show.json', 'id=' + postId, succ, e621SlideFailJSON);
- };
- var e621SlideContent = document.createElement('DIV');
- var e621SlideBackground = document.createElement('DIV');
- var e621SlideCell = document.createElement('DIV');
- var e621SlideAdvance = function(count) {
- e621SlideCurrentIndex += count;
- if (e621SlideCurrentIndex < 0) e621SlideCurrentIndex = 0;
- if (e621SlideCurrentIndex < e621SlideImageBuffer.length) {
- while (e621SlideCell.children.length > 0) {
- e621SlideCell.removeChild(e621SlideCell.children[0]);
- }
- var slide = e621SlideImageBuffer[e621SlideCurrentIndex];
- e621SlideCurrentPostId = slide.postId;
- window.scrollTo(0, document.getElementById('i' + e621SlideCurrentPostId).offsetTop);
- e621SlideCell.appendChild(slide.link);
- } else {
- e621SlideCloseLightbox();
- }
- };
- var e621SlideDrawLightbox = function() {
- //TODO: Show a given image by post id in a lightbox with upvote, downvote and favorite buttons
- e621SlideBackground.style.position = 'fixed';
- e621SlideBackground.style.width = '100%';
- e621SlideBackground.style.height = '100%';
- e621SlideBackground.style.top = '0px';
- e621SlideBackground.style.left = '0px';
- e621SlideBackground.style.background = '#000000';
- e621SlideBackground.style.opacity = 0.5;
- e621SlideBackground.style.zIndex = 98;
- e621SlideContent.style.position = 'fixed';
- e621SlideContent.style.display = 'table';
- e621SlideContent.style.top = '0px';
- e621SlideContent.style.left = '0px';
- e621SlideContent.style.width = '100%';
- e621SlideContent.style.height = '100%';
- e621SlideContent.style.zIndex = 99;
- e621SlideCell.style.width = '100%';
- e621SlideCell.style.height = '100%';
- e621SlideCell.style.display = 'table-cell';
- e621SlideCell.style.textAlign = 'center';
- e621SlideCell.style.verticalAlign = 'middle';
- e621SlideContent.appendChild(e621SlideCell);
- document.body.appendChild(e621SlideBackground);
- document.body.appendChild(e621SlideContent);
- e621SlideAdvance(1);
- document.body.onkeydown = e621SlideKeyboardEvent;
- };
- var e621SlideGetVoteJSON = function(postId, vote, successHandler, errorHandler) {
- var url = '/post/vote.json';
- var parameters = 'id=' + postId + '&score=' + vote;
- e621SlideGetJSON(url, parameters, successHandler, errorHandler);
- };
- var e621ErrStrResponse = 'Unexpected response. Change: ';
- var e621SlideUpVote = function(postId) {
- var succ = function(response) {
- if (response.change > 0) {
- // fresh upvote (1) or changed from downvote (2)
- console.log('Upvoted https://e621.net/post/show/' + postId);
- } else if (response.change == -1) {
- // removed upvote. correct to upvote
- e621SlideGetVoteJSON(postId, 1, succ, e621SlideFailJSON);
- } else {
- console.err(e621ErrStrResponse + response.change);
- }
- };
- e621SlideGetVoteJSON(postId, 1, succ, e621SlideFailJSON);
- };
- var e621SlideDownVote = function(postId) {
- var succ = function(response) {
- if (response.change < 0) {
- // fresh downvote (-1) or changed from upvote (-2)
- console.log('Downvoted https://e621.net/post/show/' + postId);
- } else if (response.change == 1) {
- // removed downvote. correct to downvote
- e621SlideGetVoteJSON(postId, -1, succ, e621SlideFailJSON);
- } else {
- console.err(e621ErrStrResponse + response.change);
- }
- };
- e621SlideGetVoteJSON(postId, -1, succ, e621SlideFailJSON);
- };
- var e621SlideFavorite = function() {
- e621SlideUpVote();
- //TODO: Add post to favorites
- };
- var e621SlideCloseLightbox = function() {
- document.body.removeChild(e621SlideContent);
- document.body.removeChild(e621SlideBackground);
- document.body.onkeydown = function(){};
- };
- var e621SlideKeyboardEvent = function(e) {
- switch(e.keyCode) {
- case 38: // up
- case 73: // i
- case 87: // w
- case 187: // =
- e621SlideUpVote(e621SlideCurrentPostId);
- e621SlideAdvance(1);
- break;
- case 40: // down
- case 75: // k
- case 83: // s
- case 189: // -
- e621SlideDownVote(e621SlideCurrentPostId);
- e621SlideAdvance(1);
- break;
- case 39: // right
- case 76: // l
- case 68: // d
- e621SlideAdvance(1);
- break;
- case 37: // left
- case 65: // a
- case 74: // j
- e621SlideAdvance(-1);
- break;
- //TODO: open post in new window on enter or spacebar
- case 13: // enter
- case 32: // spacebar
- e621SlideImageBuffer[e621SlideCurrentIndex].link.click();
- e621SlideAdvance(1);
- break;
- default: // any other key closes the lightbox
- e621SlideCloseLightbox();
- }
- e.preventDefault();
- };
- e621SlideLoadImageArray();
- e621SlideDrawLightbox();
- //=====================================================================================
- // BOOKMARKLET VERSION
- //=====================================================================================
- javascript:var e621SlideGetJSON=function(a,b,c,e){var d=new XMLHttpRequest;d.open("post",a,!0);d.responseType="json";d.onload=function(){var a=d.status;200==a?c&&c(d.response):e&&e(a)};d.setRequestHeader("Accept","text/javascript, text/html, application/xml, text/xml, */*");d.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");d.setRequestHeader("X-Prototype-Version","1.6.0.3");d.setRequestHeader("X-Requested-With","XMLHttpRequest");d.send(b)},e621SlideFailJSON=function(a){alert(a)},e621SlideImageBuffer=[],e621SlideCurrentPostId=-1,e621SlideCurrentIndex=-1,e621SlideLoadImageArray=function(){for(var a=document.getElementsByClassName("thumb"),b=0;b<a.length;b++){var c=a[b],e=c.id.substring(1);0<=c.className.indexOf("blacklisted")?e621SlideDownVote(e):e621SlideLoadImageData(e)}},e621SlideLoadImageData=function(a){var b={postId:a,image:document.createElement("IMG"),link:document.createElement("A")};b.link.appendChild(b.image);b.link.target="_blank";b.image.style.border="none";e621SlideImageBuffer.push(b);e621SlideGetJSON("/post/show.json","id="+a,function(c){b.image.src="swf"===c.file_ext?"/download-preview.png":c.sample_url;b.link.href="/post/show/"+a},e621SlideFailJSON)},e621SlideContent=document.createElement("DIV"),e621SlideBackground=document.createElement("DIV"),e621SlideCell=document.createElement("DIV"),e621SlideAdvance=function(a){e621SlideCurrentIndex+=a;0>e621SlideCurrentIndex&&(e621SlideCurrentIndex=0);if(e621SlideCurrentIndex<e621SlideImageBuffer.length){for(;0<e621SlideCell.children.length;)e621SlideCell.removeChild(e621SlideCell.children[0]);a=e621SlideImageBuffer[e621SlideCurrentIndex];e621SlideCurrentPostId=a.postId;window.scrollTo(0,document.getElementById("i"+e621SlideCurrentPostId).offsetTop);e621SlideCell.appendChild(a.link)}else e621SlideCloseLightbox()},e621SlideDrawLightbox=function(){e621SlideBackground.style.position="fixed";e621SlideBackground.style.width="100%";e621SlideBackground.style.height="100%";e621SlideBackground.style.top="0px";e621SlideBackground.style.left="0px";e621SlideBackground.style.background="#000000";e621SlideBackground.style.opacity=0.5;e621SlideBackground.style.zIndex=98;e621SlideContent.style.position="fixed";e621SlideContent.style.display="table";e621SlideContent.style.top="0px";e621SlideContent.style.left="0px";e621SlideContent.style.width="100%";e621SlideContent.style.height="100%";e621SlideContent.style.zIndex=99;e621SlideCell.style.width="100%";e621SlideCell.style.height="100%";e621SlideCell.style.display="table-cell";e621SlideCell.style.textAlign="center";e621SlideCell.style.verticalAlign="middle";e621SlideContent.appendChild(e621SlideCell);document.body.appendChild(e621SlideBackground);document.body.appendChild(e621SlideContent);e621SlideAdvance(1);document.body.onkeydown=e621SlideKeyboardEvent},e621SlideGetVoteJSON=function(a,b,c,e){e621SlideGetJSON("/post/vote.json","id="+a+"&score="+b,c,e)},e621ErrStrResponse="Unexpected response. Change: ",e621SlideUpVote=function(a){var b=function(c){0<c.change?console.log("Upvoted https://e621.net/post/show/"+a):-1==c.change?e621SlideGetVoteJSON(a,1,b,e621SlideFailJSON):console.err(e621ErrStrResponse+c.change)};e621SlideGetVoteJSON(a,1,b,e621SlideFailJSON)},e621SlideDownVote=function(a){var b=function(c){0>c.change?console.log("Downvoted https://e621.net/post/show/"+a):1==c.change?e621SlideGetVoteJSON(a,-1,b,e621SlideFailJSON):console.err(e621ErrStrResponse+c.change)};e621SlideGetVoteJSON(a,-1,b,e621SlideFailJSON)},e621SlideFavorite=function(){e621SlideUpVote()},e621SlideCloseLightbox=function(){document.body.removeChild(e621SlideContent);document.body.removeChild(e621SlideBackground);document.body.onkeydown=function(){}},e621SlideKeyboardEvent=function(a){switch(a.keyCode){case 38:case 73:case 87:case 187:e621SlideUpVote(e621SlideCurrentPostId);e621SlideAdvance(1);break;case 40:case 75:case 83:case 189:e621SlideDownVote(e621SlideCurrentPostId);e621SlideAdvance(1);break;case 39:case 76:case 68:e621SlideAdvance(1);break;case 37:case 65:case 74:e621SlideAdvance(-1);break;case 13:case 32:e621SlideImageBuffer[e621SlideCurrentIndex].link.click();e621SlideAdvance(1);break;default:e621SlideCloseLightbox()}a.preventDefault()};e621SlideLoadImageArray();e621SlideDrawLightbox();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement