nyafnyaf
Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: // ==UserScript== // @name Image auto resize // @namespace rb_image_resize // @include * // @exclude *.png* // @exclude *.jpg* // @exclude *.jpeg* // @exclude *.bmp* // @version 1.0.1 // @grant GM_addStyle // ==/UserScript== var maxWidth = 800; var maxHeight = 600; GM_addStyle("img.gm_image_resize {border: 2px solid silver; margin:0px;} img.gm_image_resize:hover {border-color: gray;}"); GM_addStyle(".cursor_zoom_in {cursor:pointer;cursor:-moz-zoom-in;} .cursor_zoom_out {cursor:pointer;cursor:-moz-zoom-out;}"); var image = document.getElementsByTagName('img'); for(var i=0; i<image.length;i++) { if(image[i].width > maxWidth || image[i].height > maxHeight) { image[i].setAttribute("class", "gm_image_resize cursor_zoom_in"); image[i].origWidth = image[i].width; image[i].origHeight = image[i].height; imageResize(image[i]); image[i].addEventListener("click", imageClick, false); } } function imageClick(event) { event.preventDefault() if(event.target.getAttribute("class").indexOf("cursor_zoom_in") != -1) { event.target.setAttribute("class", "gm_image_resize cursor_zoom_out"); event.target.width = event.target.origWidth; event.target.height = event.target.origHeight; } else { event.target.setAttribute("class", "gm_image_resize cursor_zoom_in"); imageResize(event.target); } } function imageResize(img) { if(img.width > maxWidth) { img.height = img.height * (maxWidth / img.width); img.width = maxWidth; if (img.height > maxHeight) { img.width = img.width * (maxWidth / img.height); img.height = maxHeight; } } else if (img.height > maxHeight) { img.width = img.width * (maxWidth / img.height); img.height = maxHeight; if (img.width > maxWidth) { img.height = img.height * (maxWidth / img.width); img.width = maxWidth; } } } | | Всего записей: 300 | Зарегистр. 12-12-2011 | Отправлено: 19:32 27-07-2014 | Исправлено: nyafnyaf, 19:37 27-07-2014 |
|