Browse Source

fix #3 , moved sidebar outside the night mode and abstarcted sidebar usage. Clened a bit the code. Added listener to window resize.

master
edoardoo 10 years ago
parent
commit
6ef1b97a51
2 changed files with 92 additions and 44 deletions
  1. +87
    -39
      main.js
  2. +5
    -5
      style.css

+ 87
- 39
main.js View File

@ -14,57 +14,72 @@ function setLilikLogo(){
"background-repeat": "no-repeat", "background-repeat": "no-repeat",
"background-size": "30px 30px" "background-size": "30px 30px"
});
});
} }
//roll out long post in home page: //roll out long post in home page:
function setLongPostListener(){ function setLongPostListener(){
jQuery("#list-view-2").on( "click", ".badge-evt.post-read-more", function( event ) { jQuery("#list-view-2").on( "click", ".badge-evt.post-read-more", function( event ) {
event.preventDefault(); event.preventDefault();
post = jQuery(event.target); post = jQuery(event.target);
var sidebar = jQuery("#sidebar-longPost");
var sidebar = jQuery("#sidebar-content-mod");
sidebar.removeClass("closed"); sidebar.removeClass("closed");
sidebar.html("<img>"); sidebar.html("<img>");
var image = jQuery("#sidebar-longPost img");
var image = jQuery("#sidebar-content-mod img");
jQuery.get(post.attr('href'), function(content) {
jQuery.get( post.attr('href'), function(content) {
image.attr("src", jQuery(content).find('.badge-item-img').attr("src")); image.attr("src", jQuery(content).find('.badge-item-img').attr("src"));
})
});
}); });
jQuery(document).on('scroll', function(){ jQuery(document).on('scroll', function(){
var sidebar = jQuery("#sidebar-longPost");
var sidebar = jQuery("#sidebar-content-mod");
if( !sidebar.hasClass('closed') ){ if( !sidebar.hasClass('closed') ){
sidebar.addClass('closed'); sidebar.addClass('closed');
} }
}); });
} }
function setupLongPostSidebar(){
jQuery(".badge-page.page .main-wrap ").after("<div id='sidebar-longPost' class='closed'></div>");
function setupSidebar(){
if( !jQuery("#sidebar-content-mod").length ){
jQuery("#container").after("<div id='sidebar-content-mod' class='closed'></div>");
var menuHeight = jQuery("#top-nav").height();
}
var pageHeight = jQuery(window).height(); var pageHeight = jQuery(window).height();
jQuery("#sidebar-longPost").css({"height": pageHeight});
jQuery("#sidebar-content-mod").css({"height": pageHeight, top: menuHeight});
} }
//clean wake up overlay //clean wake up overlay
function cleanWakeUp(){ function cleanWakeUp(){
// jQuery('head').append('<script type="text/javascript">GAG.Configs._configs.configs.idlePopupIdleTime = 9007199254740991; clearTimeout(GAG.PageController._idlePopupTimer); </script>');
// 31556926000 = 1 year in ms.
var code = ['GAG.Configs._configs.configs.idlePopupIdleTime = 31556926000; clearTimeout(GAG.PageController._idlePopupTimer);'].join('\n');
var script = document.createElement('script');
script.textContent = code;
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);
// jQuery('head').append('<script type="text/javascript">GAG.Configs._configs.configs.idlePopupIdleTime = 9007199254740991; clearTimeout(GAG.PageController._idlePopupTimer); </script>');
// 31556926000 = 1 year in ms.
var code = ['GAG.Configs._configs.configs.idlePopupIdleTime = 31556926000; clearTimeout(GAG.PageController._idlePopupTimer);'].join('\n');
var script = document.createElement('script');
script.textContent = code;
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);
} }
//set a listener to videos right click //set a listener to videos right click
function setVideoListener(){ function setVideoListener(){
jQuery(".main-wrap").on('contextmenu', "video", function(e) { jQuery(".main-wrap").on('contextmenu', "video", function(e) {
console.log(event.target);
currentVideo.target = jQuery(event.target); currentVideo.target = jQuery(event.target);
currentVideo.gifUrl = currentVideo.target.parent().data("image").replace("a.gif", ".gif"); currentVideo.gifUrl = currentVideo.target.parent().data("image").replace("a.gif", ".gif");
currentVideo.name = currentVideo.target.parents("article").find("h2").text().trim() + ".gif"; currentVideo.name = currentVideo.target.parents("article").find("h2").text().trim() + ".gif";
}); });
jQuery(".main-wrap").on('contextmenu', "a", function(e) { jQuery(".main-wrap").on('contextmenu', "a", function(e) {
currentVideo.target = jQuery(event.target); currentVideo.target = jQuery(event.target);
var previous = currentVideo.target.parents("article").prev(); var previous = currentVideo.target.parents("article").prev();
@ -79,29 +94,58 @@ function setVideoListener(){
console.log("Warning: unable to find the permalink for this post") console.log("Warning: unable to find the permalink for this post")
} }
}); });
}
function setOnNewNodeListener(){
jQuery(".main-wrap").on("DOMNodeInserted", function() {
NSFWListener();
});
}
function setOnWindowResizeListener(){
jQuery(window).on('resize', function(){
setupSidebar();
});
} }
//download url //download url
function downloadURI(uri, name){ function downloadURI(uri, name){
var link = document.createElement("a"); var link = document.createElement("a");
link.download = name; link.download = name;
link.href = uri; link.href = uri;
link.click(); link.click();
} }
function enableSoftTransitions( element ){
jQuery(element).addClass("softTransitions");
}
//night mode //night mode
function nightMode(){ function nightMode(){
if( isNightTime() ){ if( isNightTime() ){
toggleNight("on"); toggleNight("on");
} }
} }
function enableSoftTransitions( element ){
jQuery(element).addClass("softTransitions");
}
function isNightTime(){
var nightHour = 19;
var morningHour = 7;
var date = new Date();
var hours = date.getHours();
if( hours >= nightHour || hours <= morningHour)
return true;
else
return false;
}
function toggleNight( command ){ function toggleNight( command ){
nightClass = "night"; nightClass = "night";
var container = jQuery('#container'); var container = jQuery('#container');
@ -123,43 +167,47 @@ function toggleNight( command ){
} }
} }
} }
function isNightTime(){
var nightHour = 19;
var morningHour = 7;
var date = new Date();
var hours = date.getHours();
if( hours >= nightHour || hours <= morningHour)
return true;
else
return false;
}
function showNSFW(){ function showNSFW(){
jQuery(".badge-nsfw-entry-cover").each(function() { jQuery(".badge-nsfw-entry-cover").each(function() {
jQuery(this).addClass("deobfuscated"); jQuery(this).addClass("deobfuscated");
jQuery(this).html(jQuery('<img/>', {src: "http://img-9gag-fun.9cache.com/photo/" + jQuery(this).parents("article").data("entry-id") + "_460s.jpg",}));
var imageSource = "http://img-9gag-fun.9cache.com/photo/" + jQuery(this).parents("article").data("entry-id") + "_460s.jpg";
// TODO: isn't enough a string instead of a jquery object?
jQuery(this).html( jQuery('<img/>', { src: imageSource } ));
}); });
} }
function NSFWListener(){
if ( !jQuery("#jsid-upload-menu").not(".deobfuscated").is(":visible") && !updatingDom ){
updatingDom = true;
showNSFW();
updatingDom = false;
}
}
//init everything //init everything
jQuery(document).ready(function() { jQuery(document).ready(function() {
updatingDom = false; updatingDom = false;
showNSFW(); showNSFW();
jQuery(".main-wrap").on("DOMNodeInserted", function() {
if (!jQuery("#jsid-upload-menu").not(".deobfuscated").is(":visible") && !updatingDom){
updatingDom = true;
showNSFW();
updatingDom = false;
}
});
setOnNewNodeListener();
setOnWindowResizeListener();
setLongPostListener(); setLongPostListener();
cleanWakeUp(); cleanWakeUp();
// TODO: this object is not in the right place:
currentVideo = setupVideoObject(); currentVideo = setupVideoObject();
setVideoListener(); setVideoListener();
enableSoftTransitions(jQuery("#container")); enableSoftTransitions(jQuery("#container"));
setupLongPostSidebar();
setupSidebar();
nightMode(); nightMode();
setLilikLogo(); setLilikLogo();
console.log("9gag Mod Successfully Loaded!"); console.log("9gag Mod Successfully Loaded!");
}); });


+ 5
- 5
style.css View File

@ -13,7 +13,7 @@ header#top-nav a.logo{
#container.night img, #container.night video{ #container.night img, #container.night video{
-webkit-filter: invert(100%); -webkit-filter: invert(100%);
} }
#sidebar-longPost{
#sidebar-content-mod{
overflow-y: scroll; overflow-y: scroll;
float: left; float: left;
position: fixed; position: fixed;
@ -26,16 +26,16 @@ header#top-nav a.logo{
} }
#sidebar-longPost *{
#sidebar-content-mod *{
box-sizing: border-box; box-sizing: border-box;
} }
#sidebar-longPost img{
#sidebar-content-mod img{
width: 100%; width: 100%;
padding-bottom: 700px; padding-bottom: 700px;
} }
#sidebar-longPost.closed, .closed{
#sidebar-content-mod.closed, .closed{
width: 0px; width: 0px;
background: white;
background: none;
} }
.hidden{ .hidden{


Loading…
Cancel
Save