Browse Source

resolve #9 : added inversion for comments images

master
edoardoo 10 years ago
parent
commit
f6421717ab
3 changed files with 50 additions and 2 deletions
  1. +43
    -1
      main.js
  2. +1
    -1
      manifest.json
  3. +6
    -0
      style.css

+ 43
- 1
main.js View File

@ -126,6 +126,9 @@ function enableSoftTransitions( element ){
//night mode //night mode
function nightMode(){ function nightMode(){
if( hasComments())
setInvertCommentImages();
if( isNightTime() ){ if( isNightTime() ){
toggleNight("on"); toggleNight("on");
} }
@ -143,19 +146,31 @@ function isNightTime(){
else else
return false; return false;
} }
function hasComments(){
return jQuery("#gcomment-widget-jsid-comment-sys").length;
}
function toggleNight( command ){ function toggleNight( command ){
nightClass = "night"; nightClass = "night";
var container = jQuery('#container'); var container = jQuery('#container');
if( hasComments())
var commentPosts = frames['gcomment-widget-jsid-comment-sys'].document.getElementsByClassName("post-comment")[0];
if( command ){ if( command ){
switch( command ){ switch( command ){
case 'on': case 'on':
container.addClass( nightClass ); container.addClass( nightClass );
if( hasComments())
addClass( commentPosts, nightClass );
break; break;
case 'off': case 'off':
container.removeClass( nightClass ); container.removeClass( nightClass );
if( hasComments())
removeClass( commentPosts, nightClass );
break; break;
} }
}else{ }else{
@ -168,6 +183,17 @@ function toggleNight( command ){
} }
} }
function setInvertCommentImages(){
// jQuery( "img", frames['gcomment-widget-jsid-comment-sys'].document ).css({"-webkit-filter" : "invert(100%)"});
var cssLink = document.createElement("link")
cssLink.href = chrome.extension.getURL("style.css");
cssLink.rel = "stylesheet";
cssLink.type = "text/css";
frames['gcomment-widget-jsid-comment-sys'].document.body.appendChild(cssLink);
}
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");
@ -187,6 +213,7 @@ function NSFWListener(){
} }
} }
//init everything //init everything
jQuery(document).ready(function() { jQuery(document).ready(function() {
updatingDom = false; updatingDom = false;
showNSFW(); showNSFW();
@ -204,7 +231,6 @@ jQuery(document).ready(function() {
setupSidebar(); setupSidebar();
nightMode(); nightMode();
setLilikLogo(); setLilikLogo();
@ -226,3 +252,19 @@ chrome.extension.onMessage.addListener(
} }
} }
); );
// javascript utils to manipulate classes:
// necessary to hack the comments css
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
}

+ 1
- 1
manifest.json View File

@ -18,7 +18,7 @@
"persistent": false, "persistent": false,
"scripts": ["background.js"] "scripts": ["background.js"]
}, },
"web_accessible_resources": ["assets/logo100.png"],
"web_accessible_resources": ["assets/logo100.png", "style.css"],
"icons": { "16": "assets/logoDark16.png", "icons": { "16": "assets/logoDark16.png",
"48": "assets/logoDark48.png", "48": "assets/logoDark48.png",
"128": "assets/logoDark128.png" }, "128": "assets/logoDark128.png" },


+ 6
- 0
style.css View File

@ -38,6 +38,12 @@ header#top-nav a.logo{
background: none; background: none;
} }
/*comments*/
.post-comment.night img{
-webkit-filter: invert(100%);
}
.hidden{ .hidden{
display: none; display: none;
} }


Loading…
Cancel
Save