snipt

Ctrl+h for KB shortcuts

JavaScript

show content based on date

1
2
3
4
5
6
<script type="text/javascript">
	var myDate=new Date();
	myDate.setFullYear(2009,5,7);
	var today = new Date();
	if (today>myDate){document.getElementById('hidden').style.display = 'none';}
</script>
https://snipt.net/embed/782b5aa9783653194215d470f5078eee/
/raw/782b5aa9783653194215d470f5078eee/
782b5aa9783653194215d470f5078eee
js
JavaScript
6
2019-07-19T03:48:58
True
False
False
/api/public/snipt/6296/
show-content-based-on-date
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">&lt;</span><span class="nx">script</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;text/javascript&quot;</span><span class="o">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">myDate</span><span class="o">=</span><span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">myDate</span><span class="p">.</span><span class="nx">setFullYear</span><span class="p">(</span><span class="mi">2009</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">var</span> <span class="nx">today</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">if</span> <span class="p">(</span><span class="nx">today</span><span class="o">&gt;</span><span class="nx">myDate</span><span class="p">){</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">&#39;hidden&#39;</span><span class="p">).</span><span class="nx">style</span><span class="p">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s1">&#39;none&#39;</span><span class="p">;}</span> </span><span id="L-6"><a name="L-6"></a><span class="o">&lt;</span><span class="err">/script&gt;</span> </span></pre></div> </td></tr></table>
date, display, javascript

JavaScript

Javascript to set CSS selector for browser

1
2
3
4
5
6
7
8
/*
CSS Browser Selector v0.3.1
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
https://snipt.net/embed/faff121815802a2af83041183587d58f/
/raw/faff121815802a2af83041183587d58f/
faff121815802a2af83041183587d58f
js
JavaScript
8
2019-07-08T01:57:35
True
False
False
/api/public/snipt/2653/
javascript-to-set-css-selector-for-browser
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cm">/*</span> </span><span id="L-2"><a name="L-2"></a><span class="cm">CSS Browser Selector v0.3.1</span> </span><span id="L-3"><a name="L-3"></a><span class="cm">Rafael Lima (http://rafael.adm.br)</span> </span><span id="L-4"><a name="L-4"></a><span class="cm">http://rafael.adm.br/css_browser_selector</span> </span><span id="L-5"><a name="L-5"></a><span class="cm">License: http://creativecommons.org/licenses/by/2.5/</span> </span><span id="L-6"><a name="L-6"></a><span class="cm">Contributors: http://rafael.adm.br/css_browser_selector#contributors</span> </span><span id="L-7"><a name="L-7"></a><span class="cm">*/</span> </span><span id="L-8"><a name="L-8"></a><span class="kd">function</span> <span class="nx">css_browser_selector</span><span class="p">(</span><span class="nx">u</span><span class="p">){</span><span class="kd">var</span> <span class="nx">ua</span> <span class="o">=</span> <span class="nx">u</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">(),</span><span class="nx">is</span><span class="o">=</span><span class="kd">function</span><span class="p">(</span><span class="nx">t</span><span class="p">){</span><span class="k">return</span> <span class="nx">ua</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">t</span><span class="p">)</span><span class="o">&gt;-</span><span class="mi">1</span><span class="p">;},</span><span class="nx">g</span><span class="o">=</span><span class="s1">&#39;gecko&#39;</span><span class="p">,</span><span class="nx">w</span><span class="o">=</span><span class="s1">&#39;webkit&#39;</span><span class="p">,</span><span class="nx">s</span><span class="o">=</span><span class="s1">&#39;safari&#39;</span><span class="p">,</span><span class="nx">h</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s1">&#39;html&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span><span class="nx">b</span><span class="o">=</span><span class="p">[(</span><span class="o">!</span><span class="p">(</span><span class="sr">/opera|webtv/i</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">ua</span><span class="p">))</span><span class="o">&amp;&amp;</span><span class="sr">/msie\s(\d)/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">ua</span><span class="p">))</span><span class="o">?</span><span class="p">(</span><span class="s1">&#39;ie ie&#39;</span><span class="o">+</span><span class="nb">RegExp</span><span class="p">.</span><span class="nx">$1</span><span class="p">)</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;firefox/2&#39;</span><span class="p">)</span><span class="o">?</span><span class="nx">g</span><span class="o">+</span><span class="s1">&#39; ff2&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;firefox/3&#39;</span><span class="p">)</span><span class="o">?</span><span class="nx">g</span><span class="o">+</span><span class="s1">&#39; ff3&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;gecko/&#39;</span><span class="p">)</span><span class="o">?</span><span class="nx">g</span><span class="o">:</span><span class="sr">/opera(\s|\/)(\d+)/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">ua</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;opera opera&#39;</span><span class="o">+</span><span class="nb">RegExp</span><span class="p">.</span><span class="nx">$2</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;konqueror&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;konqueror&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;chrome&#39;</span><span class="p">)</span><span class="o">?</span><span class="nx">w</span><span class="o">+</span><span class="s1">&#39; &#39;</span><span class="o">+</span><span class="nx">s</span><span class="o">+</span><span class="s1">&#39; chrome&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;applewebkit/&#39;</span><span class="p">)</span><span class="o">?</span><span class="nx">w</span><span class="o">+</span><span class="s1">&#39; &#39;</span><span class="o">+</span><span class="nx">s</span><span class="o">+</span><span class="p">(</span><span class="sr">/version\/(\d+)/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">ua</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39; &#39;</span><span class="o">+</span><span class="nx">s</span><span class="o">+</span><span class="nb">RegExp</span><span class="p">.</span><span class="nx">$1</span><span class="o">:</span><span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;mozilla/&#39;</span><span class="p">)</span><span class="o">?</span><span class="nx">g</span><span class="o">:</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;j2me&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;mobile&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;iphone&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;iphone&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;ipod&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;ipod&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;mac&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;mac&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;darwin&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;mac&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;webtv&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;webtv&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;win&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;win&#39;</span><span class="o">:</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;freebsd&#39;</span><span class="p">)</span><span class="o">?</span><span class="s1">&#39;freebsd&#39;</span><span class="o">:</span><span class="p">(</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;x11&#39;</span><span class="p">)</span><span class="o">||</span><span class="nx">is</span><span class="p">(</span><span class="s1">&#39;linux&#39;</span><span class="p">))</span><span class="o">?</span><span class="s1">&#39;linux&#39;</span><span class="o">:</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="s1">&#39;js&#39;</span><span class="p">];</span> <span class="nx">c</span> <span class="o">=</span> <span class="nx">b</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">);</span> <span class="nx">h</span><span class="p">.</span><span class="nx">className</span> <span class="o">+=</span> <span class="s1">&#39; &#39;</span><span class="o">+</span><span class="nx">c</span><span class="p">;</span> <span class="k">return</span> <span class="nx">c</span><span class="p">;};</span> <span class="nx">css_browser_selector</span><span class="p">(</span><span class="nx">navigator</span><span class="p">.</span><span class="nx">userAgent</span><span class="p">);</span> </span></pre></div> </td></tr></table>
browser, css, javascript, selector