diff --git a/main.js b/main.js index 8c1d1da..4d9f065 100644 --- a/main.js +++ b/main.js @@ -14,57 +14,72 @@ function setLilikLogo(){ "background-repeat": "no-repeat", "background-size": "30px 30px" - }); + }); } + //roll out long post in home page: function setLongPostListener(){ jQuery("#list-view-2").on( "click", ".badge-evt.post-read-more", function( event ) { event.preventDefault(); + post = jQuery(event.target); - var sidebar = jQuery("#sidebar-longPost"); + + var sidebar = jQuery("#sidebar-content-mod"); sidebar.removeClass("closed"); sidebar.html(""); - 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")); - }) + }); }); jQuery(document).on('scroll', function(){ - var sidebar = jQuery("#sidebar-longPost"); + + var sidebar = jQuery("#sidebar-content-mod"); if( !sidebar.hasClass('closed') ){ sidebar.addClass('closed'); } }); } -function setupLongPostSidebar(){ - jQuery(".badge-page.page .main-wrap ").after(""); + +function setupSidebar(){ + if( !jQuery("#sidebar-content-mod").length ){ + + jQuery("#container").after(""); + var menuHeight = jQuery("#top-nav").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 function cleanWakeUp(){ -// jQuery('head').append(''); -// 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(''); + // 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 function setVideoListener(){ + jQuery(".main-wrap").on('contextmenu', "video", function(e) { - console.log(event.target); currentVideo.target = jQuery(event.target); currentVideo.gifUrl = currentVideo.target.parent().data("image").replace("a.gif", ".gif"); currentVideo.name = currentVideo.target.parents("article").find("h2").text().trim() + ".gif"; }); + jQuery(".main-wrap").on('contextmenu', "a", function(e) { currentVideo.target = jQuery(event.target); var previous = currentVideo.target.parents("article").prev(); @@ -79,29 +94,58 @@ function setVideoListener(){ 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 function downloadURI(uri, name){ + var link = document.createElement("a"); link.download = name; link.href = uri; link.click(); } +function enableSoftTransitions( element ){ + + jQuery(element).addClass("softTransitions"); + +} + //night mode function nightMode(){ + if( isNightTime() ){ 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 ){ + nightClass = "night"; 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(){ jQuery(".badge-nsfw-entry-cover").each(function() { jQuery(this).addClass("deobfuscated"); - jQuery(this).html(jQuery('', {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('', { src: imageSource } )); }); } +function NSFWListener(){ + if ( !jQuery("#jsid-upload-menu").not(".deobfuscated").is(":visible") && !updatingDom ){ + updatingDom = true; + showNSFW(); + updatingDom = false; + } +} //init everything jQuery(document).ready(function() { updatingDom = false; 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(); + cleanWakeUp(); + // TODO: this object is not in the right place: currentVideo = setupVideoObject(); setVideoListener(); + enableSoftTransitions(jQuery("#container")); - setupLongPostSidebar(); + + setupSidebar(); + + nightMode(); setLilikLogo(); + console.log("9gag Mod Successfully Loaded!"); }); diff --git a/style.css b/style.css index caedaf4..9352b75 100644 --- a/style.css +++ b/style.css @@ -13,7 +13,7 @@ header#top-nav a.logo{ #container.night img, #container.night video{ -webkit-filter: invert(100%); } -#sidebar-longPost{ +#sidebar-content-mod{ overflow-y: scroll; float: left; position: fixed; @@ -26,16 +26,16 @@ header#top-nav a.logo{ } -#sidebar-longPost *{ +#sidebar-content-mod *{ box-sizing: border-box; } -#sidebar-longPost img{ +#sidebar-content-mod img{ width: 100%; padding-bottom: 700px; } -#sidebar-longPost.closed, .closed{ +#sidebar-content-mod.closed, .closed{ width: 0px; - background: white; + background: none; } .hidden{