Skip to content

Instantly share code, notes, and snippets.

Brian Keith Smith thisisbrians

View GitHub Profile
View trump-blocker.js
$(":contains(Trump),:contains(TRUMP),:contains(trump)").filter(function(){return $(this).clone().children().remove().end().text().toLowerCase().indexOf("trump")!=-1;}).remove();
@thisisbrians
thisisbrians / jquery-time-zone-select.js
Created Feb 3, 2013
Dynamically select a timezone in a Rails time_zone_select based on the browser's timezone using jQuery/JavaScript.
View jquery-time-zone-select.js
jQuery.fn.selectTimeZone = function() {
var $el = $(this[0]); // our element
var offsetFromGMT = String(- new Date('1/1/2009').getTimezoneOffset() / 60); // using 1/1/2009 so we know DST isn't tripping us up
if (offsetFromGMT[0] != '-') {
offsetFromGMT = '+' + offsetFromGMT; // if it's not negative, prepend a +
}
if (offsetFromGMT.length < 3) {
offsetFromGMT = offsetFromGMT.substr(0, 1) + '0' + offsetFromGMT.substr(1); // add a leading zero if we need it
}
var regEx = new RegExp(offsetFromGMT); // create a RegExp object with our pattern
You can’t perform that action at this time.