// ==UserScript== // @name PopupX - Flickr Tweak (Only Tiny Design Tweak for Flickr + Autopager support) // @namespace http://userscripts.org/users/45256 // @description browse image(embeded a link) by a Popup Image Viewer ( Original version by NIO, Tweaked Design version by decembre) // @include http://*.pixnet.net/album/* // @include http://photo.pchome.com.tw/* // @include http://www.wretch.cc/album/* // @include http://www.wretch.cc/album/ // @include http://www.wretch.cc/blog/* // @include http://picasaweb.google.com* // @include http://album.blog.yam.com/* // @include http://gnn.gamer.com.tw/* // @include http://*nownews.com*/* // @include http://2cat.twbbs.org/* // @include http://komica*.dreamhosters.com/* // @include http://blog.roodo.com/* // @include http://iphonecake.com/* // @include http://*.flickr.com/* // @include http://*.engadget.com/* // @include http://www.facebook.com/album.php* // @include http://class.ruten.com.tw/* // @version 0.0.1.20140630035010 // @downloadURL https://update.greasyfork.icu/scripts/52/PopupX%20-%20Flickr%20Tweak%20%28Only%20Tiny%20Design%20Tweak%20for%20Flickr%20%2B%20Autopager%20support%29.user.js // @updateURL https://update.greasyfork.icu/scripts/52/PopupX%20-%20Flickr%20Tweak%20%28Only%20Tiny%20Design%20Tweak%20for%20Flickr%20%2B%20Autopager%20support%29.meta.js // ==/UserScript== /* ________________________________________________ ________________________________________________ >>> Original Author : nio // @name PopupX // @namespace http://userscripts.org/users/45256 // @description browse image(embeded a link) by a Popup Image Viewer Go here for more information.... >>> Thanks to Alesa Dam for her help! ________________________________________________ ________________________________________________ is Tweaked version for Flickr: ________________________________________________ >> 2010-/08/18 : (Thanks to Alesa Dam ) : Press the shift (MAJ) while hovering a thumbnail, if I you want shows the preview . This way you can decide yourself when to see a bigger picture or not. >> 2010-/08/16 - Added support to Autopager ...by inserting at the end of the script : window.addEventListener('AutoPagerAfterInsert', function(){PopupImage.load(); }, false); Now no needs to click on the blue button (must find a way to convert it in a On/Off button...) >> 2010/08/13 - Idea of Alesa Dam : changed line 314 from this:"//img[@class='pc_img' or @class='setThumb' or @class='nextprev_thumb' ]" into this:"//img[(@class='pc_img' or @class='setThumb' or @class='nextprev_thumb') and not(contains(@src,'/cols/') or contains(@src,'_z.jpg'))]" to make it ignore collection mozaics (which contain '/cols/' in the src attribute) and 640px wide medium images (which contain '_z.jpg' int the src) >> 2010/08/12 - just tweak Design by decembre (no new functions) */ //CHANGE LOG in the Original Version // 2010/02/25 - // * support website: class.ruten.com.tw // * modify toolbox style // 2009/07/23 - // * support website: www.facebook.com/ profile.php & album.php // * fixed toolbox style: set width // 2009/06/14 - // * fixed website pattern: Gamer GNN // * some style changed. // 2009/06/03 - // * support website: *.engadget.com // 2009/05/28 - // * append a toolbox at top-left // * add a option: shrink image // 2009/05/27 - // * fixed pattern for yam // 2009/05/24 - // * support website: iphonecake.com, *.flickr.com // * add reload button. // * compatible with google chrome (bookmarklet). (function(){ var __fit = false; var PopupImage = { //樣式集 data : [ //Pixnet相簿 [ /.*\.pixnet\.net\/album\//, /\/thumb_/, '/', '//*[@id="contentBody"]//img[@class="thumb"]' ], //PCHome Photo [ /photo\.pchome\.com\.tw/, /s\./, '.', '//span[@class="PostponeImg Cover"]' // '//span/img[1]' ], //無名個人相簿 [ /www\.wretch\.cc\/album\/.+/, /thumbs\/t/, '', '//*[@class="side"]/a/img[1]' ], //無名相簿首頁 [ /www\.wretch\.cc\/album\/$/, /thumbs\/t/, '', '//*[@class="image_link"]/a/img[1]' //'.image_link >a>img:first-child' ], //無名blog頁面 [ /www\.wretch\.cc\/blog\/.+/, /http:\/\/([\w\W]+cover\/)([\w\W]+)_\w+([\w\W]*)$/, 'http://cover.wretch.cc/$2$3', "//*[@class='boxMySpaceImg' or @class='bighead' or @id='whowrapper']//img[1]" //'a.bighead>img:first-child, #whowrapper a img, #boxMySpace .boxMySpaceImg a img' ], //Picasaweb [ /picasaweb\.google\.com(\.tw)?\/\w+/, /\/(s\d{2,4})(\-\w+)?\//, '/s640/', "//a/img[1]" //'a>img:first-child' ], //Yam [ /album\.blog\.yam\.com\/\w+/, /\/album\/[\w]_/, '/album/', "//*[@class='photoimg' or @class='albumShow' or @id='sideBlock' or @id='albumList']//a/img" //'.photoimg a>img, .albumShow a>img, #sideBlock a>img, #albumList a>img'; ], //Gamer GNN [ /gnn\.gamer\.com\.tw\//, /\/(M|S)\//, '/B/', "//img[@class='gnnPIC']" //"//a[starts-with(@href,'javascript:showpic(')]/img" //'a[href^="javascript:showpic("]>img' ], //NowNews [ /www\.nownews\.com\//, /s(\d+\.(jpg|JPG))/, 'i$1', "//a/img" //'a>img:first-child' ], //2cat (no frameset) [ /2cat\.twbbs\.org\//, /thumb\/(\d+)s/, 'src/$1', "//div[@class='threadpost' or @class='reply']/a/img" ], //komica*.dreamhosters (no frameset) [ /komica\d+\.dreamhosters\.com\//, /thumb\/(\d+)s/, 'src/$1', "//*[contains(name(),'FORM') or contains(name(),'form') or contains(name(),'TABLE')]//a/img" ], //Roodo Blog //sample: http://blog.roodo.com/ace_kaha/ [ /blog\.roodo\.com\//, /(\w+)_s/, '$1', "//div[@class='pict']//img" ], //iphonecake.com [ /iphonecake\.com/, /(?:\-\w+)(\.jpg)/, '$1', "//img[@class='attachment-thumbnail']" ], //www.flickr.com [ /flickr\.com/, /_[a-z](\.jpg)$/, '$1', "//img[(@class='pc_img' or @class='setThumb' or @class='nextprev_thumb') and not(contains(@src,'/cols/') or contains(@src,'_z.jpg'))]" ], //mining.tw // [ // /mining\.tw/, // /http:\/\/([\w\W]+cover\/)([\w\W]+)_\w+([\w\W]*)$/, // 'http://cover.wretch.cc/$2$3', // "//div[@class='mPic']/a/img" // ], //http://chinese.engadget.com [ /\w+\.engadget\.com/, /_thumbnail/, '', "//*[@class='thumb' or @class='postgallery']//a/img" ], //facebook album //facebook profile [ /www\.facebook\.com\/(album|profile)\.php/, /s([\d_]+)?\.jpg/, 'n$1.jpg', "//div[@id='photos_of_wrapper' or @id='album_container' or @id='tab_content']//a/img" ], //ruten.com [ /\.ruten\.com\.tw/, /_\w\.jpg$/, "_m.jpg", "//div[@id='bestgoods_div']/parent::td//a/img | //*[@class='featured-first' or @class='all-products']//a/img" ] ], //樣式組 //針對不同網站有個別的設定 PatternSet: function() { this.urlExpression = //; this.patternBefore = //; this.patternAfter = ''; this.imgSelector = ''; // self 指物件本身 var self = this; //插入真實圖片元素 this.appendTrueImage = function(srcImgNode, patternSet) { patternSet = self; var imgSrc = srcImgNode.getAttribute('src'); //if (imgSrc == null) //imgSrc = srcImgNode.src; if (imgSrc == null || imgSrc == "") { if (location.href.match(/photo\.pchome/)) { imgSrc = srcImgNode.getAttribute('id'); imgSrc = imgSrc.replace(/Img\[([\w\/\.\-]+)\]/, '$1'); } else if (location.href.match(/www\.wretch\.cc\/blog\/.+/)) { var re = /\/blog\/(\w+)/; var after = 'http://cover.wretch.cc/$1.jpg'; var href = srcImgNode.parentNode.getAttribute('href'); imgSrc = href.replace(re, after).toLowerCase(); } } imgSrc = imgSrc.replace(patternSet.patternBefore, patternSet.patternAfter); var imgNode = document.createElement('img'); imgNode.setAttribute('class', 'trueImg'); imgNode.setAttribute('src', imgSrc); imgNode.style.display = 'none'; srcImgNode.parentNode.appendChild(imgNode); srcImgNode.addEventListener('mouseover', function(ev) // Alesa Dam change : only shows the preview if I press shift (MAJ) while hovering a thumbnail. This way y can decide yourself when to see a bigger picture or not. { if (!ev.shiftKey) { return; } PopupImage.show(); var true_nodes = PopupImage.getElementsByClassName(ev.target.parentNode, 'trueImg'); if (true_nodes.length == 0) true_nodes = PopupImage.getElementsByClassName(ev.target.parentNode.parentNode, 'trueImg'); if (true_nodes.length > 0) { var srcNode = true_nodes[0]; var get_src = srcNode.getAttribute('src'); //顯示圖片 PopupImage.setViewerSrc(get_src); //自動縮放 //if (PopupImage.isFitWindow) if (__fit) { var sW = srcNode.width; var sH = srcNode.height; var iW = window.innerWidth; var iH = window.innerHeight; var dx = sW/iW; var dy = sH/iH; console.log('dx: '+dx+', dy:' + dy); // alert('dx: '+dx+', dy:' + dy); if (dx > 1 || dy > 1) { var fixed_ratio = 0.95; var ratio = dx > dy ? dx : dy; console.log('ratio: ' + ratio + ' after w,h: '+ (sW/ratio)*fixed_ratio + ',' + (sH/ratio)*fixed_ratio ); PopupImage.setWidth((sW/ratio)*fixed_ratio); PopupImage.setHeight((sH/ratio)*fixed_ratio); } else { PopupImage.setWidth(""); PopupImage.setHeight(""); } } else { PopupImage.setWidth(""); PopupImage.setHeight(""); } } }, false); srcImgNode.addEventListener('mouseout', function(ev) { PopupImage.hide(); }, false); srcImgNode.addEventListener('mousemove', function(ev) { var viewportWidth = window.innerWidth; var viewportHeight = window.innerHeight; var x,y; var paddingX= 100; var paddingY = 100; var imgWidth = PopupImage.getWidth(); var imgHeight = PopupImage.getHeight(); if(ev.pageX >= viewportWidth/2) { x = ev.pageX - imgWidth - paddingX; offsetX = (typeof(window.pageXOffset)=='undefined') ? ev.pageX - ev.clientX : window.pageXOffset; x = (x >= offsetX) ? x: offsetX; } else { x = eval(ev.pageX + paddingX); var dx = (ev.pageX + imgWidth + paddingX) - viewportWidth; x = (dx > 0) ? x-dx : x; } if (ev.clientY >= viewportHeight/2) { y = ev.pageY - imgHeight - paddingY; offsetY = (typeof(window.pageYOffset)=='undefined') ? ev.pageY - ev.clientY : window.pageYOffset; y = (y >= offsetY) ? y : offsetY; } else { y = eval(ev.pageY + paddingY); dy = (viewportHeight -( ev.clientY + imgHeight) - paddingY); y = (dy >= 0) ? y : y+dy-50; } PopupImage.setViewerPos(x, y); }, false); }, //列舉元素 this.selectNodes = function(xpathExpr) { var nodes = new Array(); var iters = document.evaluate(xpathExpr, document, null, XPathResult.ANY_TYPE, null); var node; while (node = iters.iterateNext()) { nodes.push(node); }; return nodes; }, //檢查網址 this.check = function() { if (location.href.match(self.urlExpression)) self.set(); }, //建立所有物件及連結 this.set = function() { PopupImage.isGetProfile = true; var nodes = this.selectNodes(this.imgSelector); for(var i=0;i