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-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("<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"));
})
});
});
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("<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();
jQuery("#sidebar-longPost").css({"height": pageHeight});
jQuery("#sidebar-content-mod").css({"height": pageHeight, top: menuHeight});
}
//clean wake up overlay
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
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('<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
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!");
});


+ 5
- 5
style.css View File

@ -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{


Loading…
Cancel
Save