Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Enlarge images on iichan
- // @namespace http://iichan.hk/
- // @license WTFPL
- // @version 0.1
- // @description adds image enlargement on click to iichan
- // @author Cirno
- // @match http://iichan.hk/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- var MIN_DISPLAY_SIZE = 700; // ширина или высота, при которой картинки будут открываться как обычно
- var thumbs = document.querySelectorAll('.thumb');
- function removeClass(el, className) {
- var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
- el.className = el.className.replace(reg, ' ');
- }
- function hasClass(el, className) {
- if(!className) return false;
- return (' ' + el.className + ' ').indexOf(' ' + className + ' ') !== -1;
- }
- for (var i = thumbs.length - 1; i >= 0; i--) {
- var img = thumbs[i];
- var a = img.parentNode;
- a.addEventListener('click', function(e) {
- if (screen.width < MIN_DISPLAY_SIZE || screen.height < MIN_DISPLAY_SIZE) {
- return;
- }
- e.preventDefault();
- console.log(this);
- var thumb = this.querySelector('.thumb');
- if (hasClass(thumb, 'iichan-image-fullsize')) {
- thumb.src = thumb.originalSrc;
- thumb.width = thumb.originalWidth;
- thumb.height = thumb.originalHeight;
- removeClass(thumb, 'iichan-image-fullsize');
- return;
- }
- var imageSrc = this.href;
- var thumbSrc = thumb.src;
- thumb.originalSrc = thumb.src;
- thumb.originalWidth = thumb.width;
- thumb.originalHeight = thumb.height;
- thumb.removeAttribute('width');
- thumb.removeAttribute('height');
- thumb.className += ' iichan-image-fullsize';
- thumb.src = imageSrc;
- });
- }
- function appendCSS() {
- var css = document.createElement('style');
- css.type = 'text/css';
- css.innerHTML = '\
- .iichan-image-fullsize {\
- max-width: 97%;\
- max-height: 97%;\
- }\
- ';
- document.body.appendChild(css);
- }
- appendCSS();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement