Skip to content

Instantly share code, notes, and snippets.

@izhaomin
Created December 20, 2013 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izhaomin/8057057 to your computer and use it in GitHub Desktop.
Save izhaomin/8057057 to your computer and use it in GitHub Desktop.
Blackground on white content with brightness control, by pressing q or w.
javascriptfunction(){var styleElem=null,doc=document,ie=doc.all,fontColor=50,sel='body,body *';styleElem=createCSS(sel,setStyle(fontColor),styleElem);showTip(doc);if(ie){doc.attachEvent('onkeydown',onKeyDown)}else{doc.addEventListener('keydown',onKeyDown)};functwqqqqwwwwwwwwqweElem)};function setStyle(fontColor){var colorArr=[fontColor,fontColor,fontColor];return'background-color:#000 !important;color:RGB('+colorArr.join('%,')+'%) !important;'};function createCSS(sel,decl,styleElem){var doc=document,h=doc.getElementsByTagName('head')[0],styleElem=styleElem;if(!styleElem){s=doc.createElement('style');s.setAttribute('type','text/css');styleElem=ie?doc.styleSheets[doc.styleSheets.length-1]:h.appendChild(s)};if(ie){styleElem.addRule(sel,decl)}else{styleElem.innerHTML='';styleElem.appendChild(doc.createTextNode(sel+' {'+decl+'}'))};return styleElem};function showTip(){var tipElem=doc.createElement('div'),body=doc.getElementsByTagName('body')[0];tipElem.innerHTML='=== 夜间模式开启。提示: q 或 w 可减少增加字体亮度 ===';tipElem.style.cssText='background-color:#3FA9FB !important;color:#fff !important;font-size:14px;height:20px;line-height:20px;position:fixed;left:0;top:0;text-align:center;width:100%;z-index:99999;';body.appendChild(tipElem);setTimeout(function(){body.removeChild(tipElem)},3000)}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment