Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add option to disable display of image captions. #128

Merged
merged 3 commits into from

2 participants

@gamefreak
Collaborator

Switch toggles titles, captions, and credits on images.

If captions are disabled, skip the API for single image imgur links
because we can guess those.

gamefreak added some commits
@gamefreak gamefreak Add option to disable display of image captions.
Switch toggles titles, captions, and credits on images.

If captions are disabled, skip the API for single image imgur links
because we can guess those.
3537195
@gamefreak gamefreak Merge branch 'master' of https://github.com/honestbleeps/Reddit-Enhan… f13011f
@gamefreak gamefreak Fix new option description. f784b94
@honestbleeps honestbleeps merged commit e49ea74 into honestbleeps:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 1, 2012
  1. @gamefreak

    Add option to disable display of image captions.

    gamefreak authored
    Switch toggles titles, captions, and credits on images.
    
    If captions are disabled, skip the API for single image imgur links
    because we can guess those.
  2. @gamefreak
  3. @gamefreak

    Fix new option description.

    gamefreak authored
This page is out of date. Refresh to see the latest.
Showing with 36 additions and 19 deletions.
  1. +36 −19 lib/reddit_enhancement_suite.user.js
View
55 lib/reddit_enhancement_suite.user.js
@@ -8373,6 +8373,11 @@ modules['showImages'] = {
type: 'boolean',
value: true,
description: 'Do not create expandos for images that appear multiple times in a page.'
+ },
+ displayImageCaptions: {
+ type: 'boolean',
+ value: true,
+ description: 'Retrieve image captions/attribution information.'
}
},
description: 'Opens images inline in your browser with the click of a button. Also has configuration options, check it out!',
@@ -8415,6 +8420,9 @@ modules['showImages'] = {
RESUtils.addCSS('.RESGalleryControls .previous:hover { background-position: 0px -320px; }');
RESUtils.addCSS('.RESGalleryControls .next:hover { background-position: 16px -320px; }');
RESUtils.addCSS('.RESGalleryControls .end:hover { background-position-y: -304px; }');
+ if (!this.options.displayImageCaptions.value) {
+ RESUtils.addCSS('.imgTitle, .imgCaptions, .imgCredits { display: none; }');
+ }
}
},
go: function() {
@@ -8791,6 +8799,7 @@ modules['showImages'] = {
if ('imageTitle' in imageLink) {
var header = document.createElement('h3');
+ header.className = 'imgTitle';
header.innerHTML = imageLink.imageTitle;
imgDiv.appendChild(header);
}
@@ -8818,8 +8827,7 @@ modules['showImages'] = {
if ('caption' in imageLink) {
var captions = document.createElement('div');
- //TODO: style captions
-// captions.className = 'imgCaptions';
+ captions.className = 'imgCaptions';
captions.innerHTML = imageLink.caption;
imgDiv.appendChild(captions);
}
@@ -9111,24 +9119,33 @@ modules['showImages'] = {
var groups = this.hashRe.exec(href);
if (!groups) var albumGroups = this.albumHashRe.exec(href);
if (groups && !groups[2]) {
- var apiURL = this.apiPrefix + 'image/' + groups[1] + '.json';
- if (apiURL in this.calls) {
- this.handleInfo(elem, this.calls[apiURL]);
- } else {
- GM_xmlhttpRequest({
- method: 'GET',
- url: apiURL,
-// aggressiveCache: true,
- onload: function(response) {
- try {
- var json = JSON.parse(response.responseText);
- } catch (error) {
- var json = {};
+ if (modules['showImages'].options.displayImageCaptions.value) {
+ var apiURL = this.apiPrefix + 'image/' + groups[1] + '.json';
+ if (apiURL in this.calls) {
+ this.handleInfo(elem, this.calls[apiURL]);
+ } else {
+ GM_xmlhttpRequest({
+ method: 'GET',
+ url: apiURL,
+// aggressiveCache: true,
+ onload: function(response) {
+ try {
+ var json = JSON.parse(response.responseText);
+ } catch (error) {
+ var json = {};
+ }
+ modules['showImages'].siteModules['imgur'].calls[apiURL] = json;
+ modules['showImages'].siteModules['imgur'].handleInfo(elem, json);
}
- modules['showImages'].siteModules['imgur'].calls[apiURL] = json;
- modules['showImages'].siteModules['imgur'].handleInfo(elem, json);
- }
- });
+ });
+ }
+ } else {
+ //If we don't show captions, then we can skip the API call.
+ modules['showImages'].siteModules['imgur'].handleInfo(elem, {image: {
+ links: {
+ //Imgur doesn't really care about the extension and the browsers don't seem to either.
+ original: 'http://i.imgur.com/'+groups[1]+'.jpg'
+ }, image: {}}});
}
} else if (albumGroups && !albumGroups[2]) {
//TODO: handle multi captions
Something went wrong with that request. Please try again.