snipt

Ctrl+h for KB shortcuts

JavaScript

hashbang stylesheet change

1
2
3
4
5
// Swaps out the screen stylesheet for a print stylesheet
if (window.location.hash == '#print=true') {
	var printcssuri = $('link[media=print]:first').attr('href');
	$('link[media=screen]:first').attr('href', printcssuri);
}
https://snipt.net/embed/8316e7f10fd7cefa41accd90fe1f4036/
/raw/8316e7f10fd7cefa41accd90fe1f4036/
8316e7f10fd7cefa41accd90fe1f4036
js
JavaScript
5
2019-08-21T14:18:20
True
False
False
Mar 18, 2014 at 03:12 AM
/api/public/snipt/122666/
hashbang-stylesheet-change
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">// Swaps out the screen stylesheet for a print stylesheet</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">hash</span> <span class="o">==</span> <span class="s1">&#39;#print=true&#39;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="kd">var</span> <span class="nx">printcssuri</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;link[media=print]:first&#39;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;href&#39;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;link[media=screen]:first&#39;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;href&#39;</span><span class="p">,</span> <span class="nx">printcssuri</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
CSS, jQuery, link, meta, theme

JavaScript

CS Cart - ZBA Z-3010 Scanner Aus Post Express Post tracking code input favlet

1
2
3
4
5
/* CS CART 2.x */
javascript:(function(){/*Scanner Postage Tracking7 Aug 2013Quick fix as the scanner adds 5 numerals at the start of the Australia Post Express Post tracking codes and does a carriage returnRMW Web Publishing*/if($('#content_add_shipment:visible').length>0){var scanned=$('#shipment_comments').val();if(scanned.length>0){scanned=scanned.trim();scanned=scanned.slice(4);/* example '997960402908127094' return 60402908127094 */if(scanned.length===14){$('#tracking_number').val(scanned).focus();$('#shipment_comments').val('');}else{alert('Something sus happened - the code is not correct. Please fix manually');return;}}else{alert('Please scan code into the "Comments" field');}/* Set Carrier to Australia Post */$('#carrier_key option[value="AUP"]').attr('selected','selected');/* Set Order Status to Posted */$('#order_status option[value="C"]').attr('selected','selected');/* Set Notification to True */$('#shipment_notify_user').attr('checked','checked');}else{alert('CS Cart "New Shipment" dialogue not active');}})()

/* CS CART 4.x */
javascript:!function(){!function(){if($('form[name=%22shipments_form%22]:visible').length%3E0){var%20e=$(%22%23shipmentcomments%22).val();if(e.length%3E0){if(e=e.trim(),e=e.slice(4),14!==e.length)return%20void%20alert(%22Somethings%20wrong%20-%20the%20code%20is%20not%20correct.%20Please%20fix%20manually%22);$(%22%23tracking_number%22).val(e).focus(),$(%22%23shipmentcomments%22).val(%22%22)}else%20alert('Please%20scan%20code%20into%20the%20%22Comments%22%20field');$('%23carrier_key%20option[value=%22aup%22]').prop(%22selected%22,!0),$('%23order_status%20option[value=%22C%22]').prop(%22selected%22,!0),$(%22%23shipment_notify_user%22).prop(%22checked%22,!0)}else%20alert('Unable%20to%20find%20CS%20Cart%20%22New%20Shipment%22%20modal')}()}();
https://snipt.net/embed/2693ff9953ca2d4d080614b35ea6a710/
/raw/2693ff9953ca2d4d080614b35ea6a710/
2693ff9953ca2d4d080614b35ea6a710
js
JavaScript
5
2019-08-20T08:41:37
True
False
False
/api/public/snipt/72417/
cs-cart-zba-z-3010-scanner-aus-post-express-post-tracking-code-input-favlet
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cm">/* CS CART 2.x */</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">javascript</span><span class="o">:</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span><span class="cm">/*Scanner Postage Tracking7 Aug 2013Quick fix as the scanner adds 5 numerals at the start of the Australia Post Express Post tracking codes and does a carriage returnRMW Web Publishing*/</span><span class="k">if</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#content_add_shipment:visible&#39;</span><span class="p">).</span><span class="nx">length</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">){</span><span class="kd">var</span> <span class="nx">scanned</span><span class="o">=</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#shipment_comments&#39;</span><span class="p">).</span><span class="nx">val</span><span class="p">();</span><span class="k">if</span><span class="p">(</span><span class="nx">scanned</span><span class="p">.</span><span class="nx">length</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">){</span><span class="nx">scanned</span><span class="o">=</span><span class="nx">scanned</span><span class="p">.</span><span class="nx">trim</span><span class="p">();</span><span class="nx">scanned</span><span class="o">=</span><span class="nx">scanned</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">4</span><span class="p">);</span><span class="cm">/* example &#39;997960402908127094&#39; return 60402908127094 */</span><span class="k">if</span><span class="p">(</span><span class="nx">scanned</span><span class="p">.</span><span class="nx">length</span><span class="o">===</span><span class="mi">14</span><span class="p">){</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#tracking_number&#39;</span><span class="p">).</span><span class="nx">val</span><span class="p">(</span><span class="nx">scanned</span><span class="p">).</span><span class="nx">focus</span><span class="p">();</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#shipment_comments&#39;</span><span class="p">).</span><span class="nx">val</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">);}</span><span class="k">else</span><span class="p">{</span><span class="nx">alert</span><span class="p">(</span><span class="s1">&#39;Something sus happened - the code is not correct. Please fix manually&#39;</span><span class="p">);</span><span class="k">return</span><span class="p">;}}</span><span class="k">else</span><span class="p">{</span><span class="nx">alert</span><span class="p">(</span><span class="s1">&#39;Please scan code into the &quot;Comments&quot; field&#39;</span><span class="p">);}</span><span class="cm">/* Set Carrier to Australia Post */</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#carrier_key option[value=&quot;AUP&quot;]&#39;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;selected&#39;</span><span class="p">,</span><span class="s1">&#39;selected&#39;</span><span class="p">);</span><span class="cm">/* Set Order Status to Posted */</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#order_status option[value=&quot;C&quot;]&#39;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;selected&#39;</span><span class="p">,</span><span class="s1">&#39;selected&#39;</span><span class="p">);</span><span class="cm">/* Set Notification to True */</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#shipment_notify_user&#39;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;checked&#39;</span><span class="p">,</span><span class="s1">&#39;checked&#39;</span><span class="p">);}</span><span class="k">else</span><span class="p">{</span><span class="nx">alert</span><span class="p">(</span><span class="s1">&#39;CS Cart &quot;New Shipment&quot; dialogue not active&#39;</span><span class="p">);}})()</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="cm">/* CS CART 4.x */</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">javascript</span><span class="o">:!</span><span class="kd">function</span><span class="p">(){</span><span class="o">!</span><span class="kd">function</span><span class="p">(){</span><span class="k">if</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;form[name=%22shipments_form%22]:visible&#39;</span><span class="p">).</span><span class="nx">length</span><span class="o">%</span><span class="mi">3</span><span class="nx">E0</span><span class="p">){</span><span class="kd">var</span><span class="o">%</span><span class="mi">20</span><span class="nx">e</span><span class="o">=</span><span class="nx">$</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="o">%</span><span class="mi">23</span><span class="nx">shipmentcomments</span><span class="o">%</span><span class="mi">22</span><span class="p">).</span><span class="nx">val</span><span class="p">();</span><span class="k">if</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">length</span><span class="o">%</span><span class="mi">3</span><span class="nx">E0</span><span class="p">){</span><span class="k">if</span><span class="p">(</span><span class="nx">e</span><span class="o">=</span><span class="nx">e</span><span class="p">.</span><span class="nx">trim</span><span class="p">(),</span><span class="nx">e</span><span class="o">=</span><span class="nx">e</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span><span class="mi">14</span><span class="o">!==</span><span class="nx">e</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span><span class="k">return</span><span class="o">%</span><span class="mi">20</span><span class="k">void</span><span class="o">%</span><span class="mi">20</span><span class="nx">alert</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="nx">Somethings</span><span class="o">%</span><span class="mi">20</span><span class="nx">wrong</span><span class="o">%</span><span class="mi">20</span><span class="o">-%</span><span class="mi">20</span><span class="nx">the</span><span class="o">%</span><span class="mi">20</span><span class="nx">code</span><span class="o">%</span><span class="mi">20</span><span class="nx">is</span><span class="o">%</span><span class="mi">20</span><span class="nx">not</span><span class="o">%</span><span class="mi">20</span><span class="nx">correct</span><span class="p">.</span><span class="o">%</span><span class="mi">20</span><span class="nx">Please</span><span class="o">%</span><span class="mi">20</span><span class="nx">fix</span><span class="o">%</span><span class="mi">20</span><span class="nx">manually</span><span class="o">%</span><span class="mi">22</span><span class="p">);</span><span class="nx">$</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="o">%</span><span class="mi">23</span><span class="nx">tracking_number</span><span class="o">%</span><span class="mi">22</span><span class="p">).</span><span class="nx">val</span><span class="p">(</span><span class="nx">e</span><span class="p">).</span><span class="nx">focus</span><span class="p">(),</span><span class="nx">$</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="o">%</span><span class="mi">23</span><span class="nx">shipmentcomments</span><span class="o">%</span><span class="mi">22</span><span class="p">).</span><span class="nx">val</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="o">%</span><span class="mi">22</span><span class="p">)}</span><span class="k">else</span><span class="o">%</span><span class="mi">20</span><span class="nx">alert</span><span class="p">(</span><span class="s1">&#39;Please%20scan%20code%20into%20the%20%22Comments%22%20field&#39;</span><span class="p">);</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;%23carrier_key%20option[value=%22aup%22]&#39;</span><span class="p">).</span><span class="nx">prop</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="nx">selected</span><span class="o">%</span><span class="mi">22</span><span class="p">,</span><span class="o">!</span><span class="mi">0</span><span class="p">),</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;%23order_status%20option[value=%22C%22]&#39;</span><span class="p">).</span><span class="nx">prop</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="nx">selected</span><span class="o">%</span><span class="mi">22</span><span class="p">,</span><span class="o">!</span><span class="mi">0</span><span class="p">),</span><span class="nx">$</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="o">%</span><span class="mi">23</span><span class="nx">shipment_notify_user</span><span class="o">%</span><span class="mi">22</span><span class="p">).</span><span class="nx">prop</span><span class="p">(</span><span class="o">%</span><span class="mi">22</span><span class="nx">checked</span><span class="o">%</span><span class="mi">22</span><span class="p">,</span><span class="o">!</span><span class="mi">0</span><span class="p">)}</span><span class="k">else</span><span class="o">%</span><span class="mi">20</span><span class="nx">alert</span><span class="p">(</span><span class="s1">&#39;Unable%20to%20find%20CS%20Cart%20%22New%20Shipment%22%20modal&#39;</span><span class="p">)}()}();</span> </span></pre></div> </td></tr></table>
auspost, barcode, bookmarklet, cscart, cscart4, ecommerce, favlet, scanned, shipping, shopping, store, tracking, z-3010

JavaScript

SlimTimmer - Open Timer to the top right

javascript:newwindow=window.open('http://slimtimer.com/client/','slimtimer','resizable=1,toolbar=0,location=0,status=1,menubar=0,scrollbars=1,width=175,height=700,left=2400,top=20');newwindow.focus();
https://snipt.net/embed/4424f42ed6e1f81508f5693959d37003/
/raw/4424f42ed6e1f81508f5693959d37003/
4424f42ed6e1f81508f5693959d37003
js
JavaScript
1
2019-08-19T20:06:54
True
False
False
May 14, 2013 at 10:23 AM
/api/public/snipt/61299/
slimtimmer-open-timer-to-the-top-right
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">javascript</span><span class="o">:</span><span class="nx">newwindow</span><span class="o">=</span><span class="nb">window</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="s1">&#39;http://slimtimer.com/client/&#39;</span><span class="p">,</span><span class="s1">&#39;slimtimer&#39;</span><span class="p">,</span><span class="s1">&#39;resizable=1,toolbar=0,location=0,status=1,menubar=0,scrollbars=1,width=175,height=700,left=2400,top=20&#39;</span><span class="p">);</span><span class="nx">newwindow</span><span class="p">.</span><span class="nx">focus</span><span class="p">();</span> </span></pre></div> </td></tr></table>
"time tracking", "work tool", bunny, open, position, slimtimer, timer, window

Text only

Google Analytics External Link Tracking

1
2
3
4
5
6
7
function gaExternalLink(link, category, action, label) {
	try {
		var myTracker = _gat._getTrackerByName();
		_gaq.push(['myTracker._trackEvent', category , action, label]);
		setTimeout('document.location = "' + link.href + '"', 100)
	} catch(err) {}
}
https://snipt.net/embed/49ac53887b6751ddc7f1b2d93760439e/
/raw/49ac53887b6751ddc7f1b2d93760439e/
49ac53887b6751ddc7f1b2d93760439e
text
Text only
7
2019-08-17T22:07:44
True
False
False
Sep 04, 2012 at 10:49 PM
/api/public/snipt/46700/
google-analytics-external-link-tracking
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>function gaExternalLink(link, category, action, label) { </span><span id="L-2"><a name="L-2"></a> try { </span><span id="L-3"><a name="L-3"></a> var myTracker = _gat._getTrackerByName(); </span><span id="L-4"><a name="L-4"></a> _gaq.push([&#39;myTracker._trackEvent&#39;, category , action, label]); </span><span id="L-5"><a name="L-5"></a> setTimeout(&#39;document.location = &quot;&#39; + link.href + &#39;&quot;&#39;, 100) </span><span id="L-6"><a name="L-6"></a> } catch(err) {} </span><span id="L-7"><a name="L-7"></a>} </span></pre></div> </td></tr></table>
GoogleAnalytics, ga, link, stats, tracking

MySQL

MySQL: Change Domain Name on email address (leave username)

update [TABLE] set [EMAIL] = replace([EMAIL], SUBSTRING_INDEX([EMAIL], '@', -1), '@XYZ.COM');
https://snipt.net/embed/a7f51ca2395c042c07e351e3e15ef1e2/
/raw/a7f51ca2395c042c07e351e3e15ef1e2/
a7f51ca2395c042c07e351e3e15ef1e2
mysql
MySQL
1
2019-08-21T11:59:58
True
False
False
/api/public/snipt/41505/
mysql-change-domain-name-on-email-address-leave-username
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">update</span> <span class="p">[</span><span class="k">TABLE</span><span class="p">]</span> <span class="kt">set</span> <span class="p">[</span><span class="n">EMAIL</span><span class="p">]</span> <span class="o">=</span> <span class="k">replace</span><span class="p">([</span><span class="n">EMAIL</span><span class="p">],</span> <span class="nf">SUBSTRING_INDEX</span><span class="p">([</span><span class="n">EMAIL</span><span class="p">],</span> <span class="s1">&#39;@&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="s1">&#39;@XYZ.COM&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
"find & replace", email, mysql, regex

JavaScript

Trim string to length

1
2
3
4
5
function trimLength(str, length) {
	str = $.trim(str); // jQuery required
	str = str.slice(0, length);
	return str;
}
https://snipt.net/embed/b282ce90eccedb80413e42bfea8f0572/
/raw/b282ce90eccedb80413e42bfea8f0572/
b282ce90eccedb80413e42bfea8f0572
js
JavaScript
5
2019-08-21T17:37:21
True
False
False
/api/public/snipt/23868/
trim-string-to-length
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">trimLength</span><span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="nx">length</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">str</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">trim</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span> <span class="c1">// jQuery required</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">length</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">return</span> <span class="nx">str</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
cut, function, helper, javascript, length, shorten, snippet, string, trim

JavaScript

Styles the first letter of each word. Needed for webkit when using a custom font-face

1
2
3
4
5
6
$.fn.SmallCaps = function() {
	return this.each(function() {
		// single out the first letter of each word and wrap in span for styling
		$(this).html( $(this).text().replace(/(^| )(\w)/g, "<span class='caps'>$1$2</span>" ) );
	});
};
https://snipt.net/embed/4de7cd72661c9f558af98324abd86461/
/raw/4de7cd72661c9f558af98324abd86461/
4de7cd72661c9f558af98324abd86461
js
JavaScript
6
2019-08-17T08:53:24
True
False
False
/api/public/snipt/22064/
styles-the-first-letter-of-each-word-needed-for-webkit-when-using-a-custom-font-face
<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="nx">$</span><span class="p">.</span><span class="nx">fn</span><span class="p">.</span><span class="nx">SmallCaps</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="c1">// single out the first letter of each word and wrap in span for styling</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">text</span><span class="p">().</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/(^| )(\w)/g</span><span class="p">,</span> <span class="s2">&quot;&lt;span class=&#39;caps&#39;&gt;$1$2&lt;/span&gt;&quot;</span> <span class="p">)</span> <span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">});</span> </span><span id="L-6"><a name="L-6"></a><span class="p">};</span> </span></pre></div> </td></tr></table>
jquery, plugin, regex, string, text, webkit