Skip to content

Instantly share code, notes, and snippets.

@vjandrea
Last active August 3, 2016 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vjandrea/66afc69d871ef123d4e7 to your computer and use it in GitHub Desktop.
Save vjandrea/66afc69d871ef123d4e7 to your computer and use it in GitHub Desktop.
Ligthbox 4 All Greasemonkey Script
// ==UserScript==
// @name Lightbox 4 all
// @namespace http://vjandrea.net
// @description Open all images in lightbox
// @require http://lokeshdhakar.com/projects/lightbox2/js/jquery-1.11.0.min.js
// @require http://lokeshdhakar.com/projects/lightbox2/js/lightbox.js
// @version 1.3.1
// @grant none
// ==/UserScript==
/* ----------------------------------------*\
| HISTORY
|-------------------------------------------
| 0.1 first attempt in plain JS
| 0.2 switched to jQuery, added LightBox
| 1.0 first public release, working
| 1.1 added title attribute
| 1.1.1 removed @include and @exclude
| 1.1.2 added more extensions
| 1.2 fixed grouped selectors
| 1.3 added support for GIF, PNG, BMP
| 1.3.1 added filter to exclude linked images
\*-------------------------------------------*/
function basename(path) {
return path.split('/').reverse()[0];
}
var $ = unsafeWindow.jQuery;
$(document).ready(function()
{
// include lightbox CSS
$("head").append('<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/css/lightbox.css" />')
// scan all jpgs and add the lightbox attribute
$("[href$='.jpg'],[href$='.JPG'],[href$='.jpeg'],[href$='.JPEG'],[href$='.gif'],[href$='.GIF'],[href$='.bmp'],[href$='.BMP'],[href$='.png'],[href$='.PNG']").not(':has(div,img)').attr('data-lightbox', 'lightbox4all').attr('data-title', function(){
return basename(this.href);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment