Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name nh_load_all
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://nhentai.net/g/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- let buttonElement, imageQueue, continueOnError;
- let imageSources = [];
- let imageHeight = '100vh';
- let imageWidth = '50%';
- let title = document.title;
- let container = document.getElementById('thumbnail-container');
- let gallerythumbs = document.getElementsByClassName('gallerythumb');
- let pattern = /.*galleries\/([\d\/]+).*\.(.*)$/;
- let replacement = "https://i.nhentai.net/galleries/$1.$2";
- let numProcesses = 1;
- window.reloadImage = function(imageElement) {
- let reloadCount = imageElement.getAttribute('data-reload-count');
- let dataSource = imageElement.getAttribute('data-source');
- let currentTime = (new Date()).getTime();
- if (reloadCount < 3) {
- imageElement.src = `${dataSource}?t=${currentTime}`;
- imageElement.setAttribute('data-reload-count', reloadCount + 1);
- console.log(`${reloadCount}: reloading img ${dataSource}`);
- } else {
- console.log(`max retry of ${reloadCount} reached - ${dataSource}`);
- if (typeof continueOnError === 'undefined') {
- continueOnError = confirm('Unable to load image. Proceed with next images?');
- }
- if (continueOnError) {
- processQueue();
- }
- }
- };
- for (let gallerythumb of gallerythumbs) {
- let imageElement = gallerythumb.getElementsByTagName('img')[0];
- let dataSource = imageElement.getAttribute('data-src');
- let imageSource = dataSource.replace(pattern, replacement);
- imageSources.push(imageSource);
- }
- document.title = `[INC - ${imageSources.length}] ${title}`;
- container.innerHTML = '';
- // insert one image a time
- imageQueue = [...imageSources];
- window.processQueue = function() {
- let numRemainingImages = imageQueue.length;
- if (numRemainingImages === 0) {
- console.log('no more images left');
- document.title = `[COMPLETE] ${title}`;
- return;
- }
- let imageSource = imageQueue.shift();
- let imageElement = document.createElement("img");
- imageElement.src = imageSource;
- imageElement.setAttribute('data-reload-count', 0);
- imageElement.setAttribute('data-source', imageElement.src);
- imageElement.setAttribute('onerror', 'reloadImage(this)');
- imageElement.setAttribute('onload', 'processQueue()');
- imageElement.style.background = `transparent url('https://thinkfuture.com/wp-content/uploads/2013/10/loadingSpinner.gif') center no-repeat;`;
- imageElement.style['max-width'] = imageWidth;
- imageElement.style['max-height'] = imageHeight;
- container.appendChild(imageElement);
- // notify progress
- console.log(`image added: ${imageElement.src}`);
- document.title = `[INC - ${numRemainingImages}] ${title}`;
- };
- // start queue
- for (var i = 0; i < numProcesses; i++) {
- processQueue();
- }
- // add button to update height
- buttonElement = document.createElement('button');
- buttonElement.className = 'btn btn-primary btn-custom';
- buttonElement.innerText = '200vh';
- buttonElement.style = `position: fixed; top: 2em; right: 2em;`;
- buttonElement.addEventListener('click', function() {
- if (imageHeight === '200vh') {
- imageHeight = '100vh';
- imageWidth = '50%';
- this.innerText = '200vh';
- } else {
- imageHeight = '200vh';
- imageWidth = '100%';
- this.innerText = '100vh';
- }
- let imgs = document.querySelectorAll('#thumbnail-container img');
- for (let img of imgs) {
- if (img) {
- img.style['max-width'] = imageWidth;
- img.style['max-height'] = imageHeight;
- }
- }
- console.log(`settings cssText to ${imgs[0].style.cssText}`);
- });
- document.body.append(buttonElement);
- // pagedown on right
- document.addEventListener('keydown', function(e) {
- let height = window.innerHeight;
- switch(e.keyCode) {
- case 37: // left
- window.scrollBy(0, -height);
- break;
- case 39: // right
- window.scrollBy(0, height);
- break;
- default: return; // exit this handler for other keys
- }
- e.preventDefault(); // prevent the default action (scroll / move caret)
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement