Skip to content

Instantly share code, notes, and snippets.

@Dither
Last active July 12, 2016 18:09
Show Gist options
  • Save Dither/29e3326260a0f2c1106de2569eebae0c to your computer and use it in GitHub Desktop.
Save Dither/29e3326260a0f2c1106de2569eebae0c to your computer and use it in GitHub Desktop.
Imgur gallery custom pattern for AutoPatchWork mod (autoclick "load more" and pagerize galleries)
// ==UserScript==
// @name Imgur service script for AutoPatchWork Mod (UserJS version)
// @include http://imgur.com/*/*
// @include https://imgur.com/*/*
// @run-at document-end
// ==/UserScript==
AutoPatchWorked.on('ready', function() {
var current_index = parseInt(location.hash.slice(1), 10) || 0,
img_arr_len = 0;
AutoPatchWorked.on('request', function handleNewPageLink(event) {
if (current_index < img_arr_len - 1) {
var img = Imgur.Album.getInstance()._.images.images[++current_index];
AutoPatchWorked.trigger('load', {
htmlDoc: AutoPatchWorked.create_html('<!DOCTYPE html><html></head><body><div class=\"image post-image\"><a href=\"#' + current_index + '\" class=\"zoom\"><img src=\"http://i.imgur.com/' + img['hash'] + img['ext'] + '\"></img></a></div></body></html>')
});
} else AutoPatchWorked.trigger('terminated');
}, false);
if (AutoPatchWorked.get_node('a.post-loadall'))
AutoPatchWorked.trigger('siteinfo', {
siteinfo:
{
url: '^http://imgur\\.com/a/',
buttonElementSelector: 'a.post-loadall'
}
});
else {
if (Imgur.Album.getInstance()._.images) img_arr_len = Imgur.Album.getInstance()._.images.images.length;
AutoPatchWorked.trigger('siteinfo', {
siteinfo:
{
url: '^http://imgur\\.com/a/',
pageElementSelector: 'div.post-image',
removeElementSelector:'#prev,#next',
nextLinkSelector: '#next',
SERVICE: true
}
});
}
}, false);
{
"url":"^https?://imgur\\.com/\\w+/",
"SERVICE":true,
"jsPatch":"AutoPatchWorked.on('ready', function() { var current_index = parseInt(location.hash.slice(1),10)||0, img_arr_len = 0; AutoPatchWorked.on('request', function handleNewPageLink(event) { if (current_index < img_arr_len - 1) { var img = Imgur.Album.getInstance()._.images.images[++current_index]; AutoPatchWorked.trigger('load', { htmlDoc: AutoPatchWorked.create_html('<!DOCTYPE html><html></head><body><div class=\"image post-image\"><a href=\"#'+current_index+'\" class=\"zoom\"><img src=\"http://i.imgur.com/' + img['hash'] + img['ext'] + '\"></img></a></div></body></html>') }); } else AutoPatchWorked.trigger('terminated'); }, false); if (AutoPatchWorked.get_node('a.post-loadall')) AutoPatchWorked.trigger('siteinfo', { siteinfo : { url:'^http://imgur\\.com/a/', buttonElementSelector:'a.post-loadall' } }); else {if (Imgur.Album.getInstance()._.images)img_arr_len = Imgur.Album.getInstance()._.images.images.length; AutoPatchWorked.trigger('siteinfo', { siteinfo : { url: '^http://imgur\\.com/a/', removeElementSelector:'#prev,#next', pageElementSelector: 'div.post-image', nextLinkSelector: '#next', SERVICE: true } });}}, false);"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment