javascript:if(!confirm('Add%20to%20Snipplr?'))window.open('http://snipplr.com').focus();else(function()%7Bvar%20x=document.getElementsByTagName('head').item(0);var%20o=document.createElement('script');if(typeof%20o!='object')o=document.standardCreateElement('script');o.setAttribute('src','http://snipplr.com/bookmarklets/'+(navigator.userAgent.indexOf('Firefox')+1?'firefox':'safari')+'.js');o.setAttribute('type','text/javascript');x.appendChild(o);%7D)();
Tag Archive for js
A Better Snipplr Bookmark
Custom Cocoa WebView JavaScript Confirm Window
- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
NSInteger result = NSRunInformationalAlertPanel(NSLocalizedString(@"JavaScript", @""), // title
message, // message
NSLocalizedString(@"OK", @""), // default button
NSLocalizedString(@"Cancel", @""), // alt button
nil);
return NSAlertDefaultReturn == result;
}
WebView Alert Panel
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
{
NSBeginInformationalAlertSheet(@"Alert", nil, nil, nil, [sender window], nil, NULL, NULL, NULL, message);
}
Optionally Serve Statically Compressed CSS & JS
# no weird non-ASCII quotes! Arg! They wasted an hour of time!
# info: <a href="http://www.bluehostforum.com/showthread.php?t=11402" >http://www.bluehostforum.com/showthread.php?t=11402</a>
Options +followsymlinks
<FilesMatch ".js.gz$">
ForceType text/javascript
Header set Content-Encoding: gzip
</FilesMatch>
<FilesMatch ".js$">
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*).js$ $1.js.gz [L]
ForceType text/javascript
</FilesMatch>
<FilesMatch ".css.gz$">
ForceType text/css
Header set Content-Encoding: gzip
</FilesMatch>
<FilesMatch ".css$">
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*).css$ $1.css.gz [L]
ForceType text/css
</FilesMatch>
Compression Script for CSS & JS
#!/bin/bash
development=0
localAddress=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{print $2; exit 1}'`
localAddress='your.localhost'
coreCSSOutputFile='css/core.css'
coreJSOutputFile='js/core.js'
if [ $development == 1 ]; then
cat > $coreJSOutputFile <<EOL
document.write('<script src="/includes/js/mootools.js" type="text/javascript" charset="utf-8"></script>');
document.write('<script src="/includes/js/validator.js" type="text/javascript" charset="utf-8"></script>');
document.write('<script src="/includes/js/datepicker.js" type="text/javascript" charset="utf-8"></script>');
EOL
cat > $coreCSSOutputFile <<EOL
@import "lib/reset.css";
@import "lib/typography.css";
@import "lib/forms.css";
@import "lib/plugins/tabs.css";
@import "components/datepicker_dashboard.css";
@import "admin.css";
EOL
# we dont want the server trying to serve the wrong data
if [[ -f "$coreCSSOutputFile.gz" ]]; then
rm "$coreCSSOutputFile.gz"
fi
if [[ -f "$coreJSOutputFile.gz" ]]; then
rm "$coreJSOutputFile.gz"
fi
exit 0
fi
tempFile=`mktemp -t webcompress.xxx`
# Compress CSS
coreCSSFiles=(
'css/lib/reset.css'
'css/lib/forms.css'
'css/lib/ie.css'
'css/lib/typography.css'
'css/screen.css'
'css/components/datepicker_dashboard.css'
)
for file in ${coreCSSFiles[@]}; do
# count /'s.. if we are father down in the directory replace ../../../ with ../
if [[ `echo "$file" | perl -ne 'while(///g){++$count}; print "$count
"'` > 2 ]]; then
cat $file | sed 's/../../..//../..//g' >> $tempFile
else
cat $file >> $tempFile
fi
done
cat $tempFile > /out.css
cssoptimizer -lo $tempFile > $coreCSSOutputFile
# Compress JS
javascriptFiles=(
js/mootools.js
js/validator.js
js/datepicker.js
)
# clear the tmp file
> $tempFile
for file in ${javascriptFiles[@]}; do
cat $file >> $tempFile
done
java -jar /usr/bin/yuicompressor.jar --type js "$tempFile" > "$coreJSOutputFile"
# gzip compress!
gzip -f "$coreJSOutputFile"
gzip -f "$coreCSSOutputFile"
exit 0
Waiting for events with the Selenium-Client Ruby driver
@selenium.wait_for_element "//div[@id='foo']"
# if the application under test uses jQuery, then you can do
@selenium.wait_for_condition "$('#foo').css('display') == 'block'", 2
# otoh if jQuery is not available, use native DOM methods:
@selenium.wait_for_condition "document.getElementById('foo').style.display == 'block'", 2
# Note that, within wait_for_condition, I did NOT need to use
# this.browserbot.getCurrentWindow().$() and instead I could
# simply refer to $()
Javascript Class with instance creation arguments
var NAMESPACE ={};
NAMESPACE.MyClassName = function () { this.initialize.apply(this, arguments); };
NAMESPACE.MyClassName.prototype = {
value1: null,
value2: null,
initialize: function(arg1, arg2) {
this.value1 = arg1;
this.value2 = arg2;
},
addItUp: function () {
var total = this.value1 + this.value2;
return total;
}
};
// new instance
var newInstance = new NAMESPACE.MyClassName('it ',' works!')
newInstance.addItUp();
Show input Text while tipping
$('input#ID').keyup(function(){
$('div-where-the-text-will-show').text($(this).val());
});
limitChars
$('#message').keyup(function(){
limitChars('message', 160, 'charlimitinfo');
});
// The Function
function limitChars(textid, limit, infodiv)
{
var text = $('#'+textid).val();
var textlength = text.length;
if(textlength > limit)
{
$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
$('#'+textid).val(text.substr(0,limit));
return false;
}
else
{
$('#' + infodiv).html(''+ (limit - textlength) +'');
return true;
}
}
XSS
" onmouseover="alert('hacker')" <!-- in email or url field -->
<image src=javascript:alert('ok')> <!-- in textarea -->
<script>alert('Hacking by hacker')</script>
<script>alert(document.cookie)</script>