Skip to content

Instantly share code, notes, and snippets.

@tomslominski
Forked from ozh/gist:5495656
Last active December 29, 2015 06:59
Show Gist options
  • Save tomslominski/7632637 to your computer and use it in GitHub Desktop.
Save tomslominski/7632637 to your computer and use it in GitHub Desktop.
Bookmarklet JavaScript from YOURLS: Infinity Squared edition
javascript: (function () {
var d = document,
w = window,
enc = encodeURIComponent,
e = w.getSelection,
k = d.getSelection,
x = d.selection,
s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
s2 = ((s.toString() == '') ? s : enc(s)),
f = '<?php echo YOURLS_SITE . ' / result.php '; ?>',
l = d.location,
k = prompt("Custom URL"),
k2 = (k ? '&keyword=' + k : ""),
p = '?url=' + enc(l.href) + '&title=' + enc(d.title) + '&text=' + s2 + k2,
u = f + p;
if (k != null) {
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!w.open(u)) l.href = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0)
}
})();
javascript: (function () {
var d = document,
k = prompt('Custom URL'),
s = d.createElement('script');
if (k != null) {
window.yourls_callback = function (r) {
if (r.short_url) {
prompt(r.message, r.short_url);
} else {
alert('An error occured: ' + r.message);
}
};
s.src = '<?php echo YOURLS_SITE . ' / result.php '; ?>?url=' + encodeURIComponent(d.location.href) + '&keyword=' + k + '&jsonp=yourls';
void(d.body.appendChild(s));
}
})();
javascript: (function () {
var d = document,
s = d.createElement('script');
window.yourls_callback = function (r) {
if (r.short_url) {
prompt(r.message, r.short_url);
} else {
alert('An error occured: ' + r.message);
}
};
s.src = '<?php echo YOURLS_SITE . ' / result.php '; ?>?url=' + encodeURIComponent(d.location.href) + '&jsonp=yourls';
void(d.body.appendChild(s));
})();
javascript: (function () {
var d = document,
w = window,
enc = encodeURIComponent,
e = w.getSelection,
k = d.getSelection,
x = d.selection,
s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
s2 = ((s.toString() == '') ? s : enc(s)),
f = '<?php echo YOURLS_SITE . ' / result.php '; ?>',
l = d.location,
p = '?url=' + enc(l.href) + '&title=' + enc(d.title) + '&text=' + s2,
u = f + p;
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!w.open(u)) l.href = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment