Skip to content

Instantly share code, notes, and snippets.

@tomslominski
Forked from ozh/gist:5495656
Last active December 29, 2015 06:58
Show Gist options
  • Save tomslominski/7632263 to your computer and use it in GitHub Desktop.
Save tomslominski/7632263 to your computer and use it in GitHub Desktop.
Bookmarklet JavaScript from YOURLS
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 $page; ?>?url=' + encodeURIComponent(d.location.href) + '&keyword=' + k + '&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 $page; ?>',
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,
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 $page; ?>',
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);
})()
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 $page; ?>?url=' + encodeURIComponent(d.location.href) + '&jsonp=yourls';
void(d.body.appendChild(s));
})();
// Share on Facebook
var d = document,
enc = encodeURIComponent,
share = 'facebook',
f = '<?php echo yourls_admin_url("index.php"); ?>',
l = d.location,
p = '?u=' + enc(l.href) + '&t=' + enc(d.title) + '&share=' + share,
u = f + p;
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!window.open(u,'Share','width=500,height=340,left=100','_blank')) l.href = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0);
// Share on Twitter
var d = document,
w = window,
enc = encodeURIComponent,
share = 'twitter',
e = w.getSelection,
k = d.getSelection,
x = d.selection,
s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
s2 = ((s.toString() == '') ? s : '%20%22' + enc(s) + '%22'),
f = '<?php echo yourls_admin_url("index.php"); ?>',
l = d.location,
p = '?u=' + enc(l.href) + '&t=' + enc(d.title) + s2 + '&share=' + share,
u = f + p;
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!w.open(u,'Share','width=780,height=265,left=100','_blank')) 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