Last active
August 3, 2016 07:11
-
-
Save vjandrea/66afc69d871ef123d4e7 to your computer and use it in GitHub Desktop.
Ligthbox 4 All Greasemonkey Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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