Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Forked from JoelBesada/README.md
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AstraLuma/2d3531c66c3215d2b777 to your computer and use it in GitHub Desktop.
Save AstraLuma/2d3531c66c3215d2b777 to your computer and use it in GitHub Desktop.
Backtick: Diigo Read Later

This is a port of Diigo's read later bookmark let. It just saves the current page as unread and gets out of the way.

/* NOTE: Comments need to be in multiline format like this, instead of "// Comment" */
/*
Diigo Read Later bookmartlet
version 1.0
(ripped from https://www.diigo.com/javascripts/readlater.js )
*/
DIIGO_R_TEST = false;
if (DIIGO_R && DIIGO_R.inited) {
DIIGO_R.save();
}else{
function DIIGO_R() {
setTimeout(function(){
DIIGO_R.save();
}, 1);
};
DIIGO_R.prototype = {
save: function(){
if(DIIGO_R_TEST){
DIIGO_R.message('Test successful, you are good to go!', true);
DIIGO_R.int = setTimeout(function(){
DIIGO_R.hide();
}, 5000);
}
else{
DIIGO_R.u = encodeURIComponent(document.location.href);
DIIGO_R.t = encodeURIComponent(document.title.replace(/^\s\s*/, '').replace(/\s\s*$/, ''));
if(DIIGO_R.t.length<1) DIIGO_R.t = DIIGO_R.u;
DIIGO_R.message('Saving Page to Read Later...', true);
DIIGO_R.img = new Image();
DIIGO_R.img.src = 'https://www.diigo.com/readlater/rlt.gif?url='+DIIGO_R.u+'&title='+DIIGO_R.t+'&rand='+Math.random();
document.body.appendChild(DIIGO_R.img);
DIIGO_R.int = setInterval(function(){
DIIGO_R.checkImage();
}, 250);
}
DIIGO_R.inited = true;
},
checkImage:function(){
if(DIIGO_R.img && DIIGO_R.img.complete){
clearInterval( DIIGO_R.int );
DIIGO_R.complete = true;
var w = DIIGO_R.img.width;
if (w == 0) {return;}
console.log(w == 1);
var msg = '';
if(w==2 || w==3){
if (w == 2) {
msg += '<p>You are not logged in. Please log in before saving links to Diigo</p><p><a target="_blank" href="https://www.diigo.com/sign-in">Login Here</a></p>';
} else if (w == 3) {
msg += '<p>Could not save.</p>Please bother the backtick command author or <a target="_blank" href="https://www.diigo.com/sign-in">relogin</a>.</p> ';
}
msg += '<p>&nbsp;</p><p><a class="" style="text-decoration:underline" onclick="DIIGO_R.hide()">[Close]</a>';
DIIGO_R.message(msg);
}else if(w==1){
DIIGO_R.message('Page Saved!', true);
DIIGO_R.int = setTimeout(function(){
DIIGO_R.hide();
}, 1500);
}else{
msg += '<p>Could not save.</p>Please reinstall the bookmarklet or <a target="_blank" href="https://www.diigo.com/sign-in">relogin</a>.</p> ';
msg += '<p>&nbsp;</p><p><a class="" style="text-decoration:underline" onclick="DIIGO_R.hide()">[Close]</a>';
DIIGO_R.message(msg);
}
DIIGO_R.img.style.display = 'none';
}
},
message:function(m,scale){
if (!this.msg) {
this.msg = document.createElement( 'div' );
}
var h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
this.msg.style.cssText = 'display:block;position:absolute;margin:0px;padding:0px;font-size:18px;font-family:Arial;text-align:center;font-size:14px;font-weight:bold;color:#000000;background: #FFFFFF;border:1px solid #333333;z-index:100000;padding:25px';
document.body.appendChild(this.msg);
this.msg.style.fontSize = scale ? (h * 0.06) + 'px' : '18px';
this.msg.innerHTML = m;
var y = window.pageYOffset ? window.pageYOffset : document.body.scrollTop;
var x = window.pageXOffset ? window.pageXOffset : document.body.scrollLeft;
var w = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
this.msg.style.top = ( y + ( h * 0.40 - this.msg.clientHeight / 2 ) ) + 'px';
this.msg.style.left = ( x + ( w / 2 - this.msg.clientWidth / 2 ) ) + 'px';
},
hide : function() {
this.msg.style.display = 'none';
this.msg = false;
}
};
var DIIGO_R = window.DIIGO_R = new DIIGO_R();
}
{
"name": "Diigo: Read Later",
"description": "Saves a page in Diigo to be read later",
"icon": "https://www.diigo.com/images/v6/logo-small.png",
"link": "https://gist.github.com/astronouth7303/2d3531c66c3215d2b777"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment