// Flickr - Widescreen // Copyright (c) 2010, Patrick Joseph. // Released under the GPL license // http://www.gnu.org/copyleft/gpl.html // // ==UserScript== // @name Flickr - Widescreen // @namespace http://userscripts.org/users/isamux // @description Adjusts the appearance of photostream pages depending on the browser's window size. // @version 1.2.2.1 // @date 2011-04-24 // @creator Patrick Joseph // @include http://*.flickr.com/photos/* // @include http://*.flickr.com/groups/*/pool*/ // @exclude http://*.flickr.com/photos/friends* // @downloadURL none // ==/UserScript== // ==Changelog== //2011-04-24 v1.2.2: // * Flickr changed id of photostream's content div from "Main" to "main". Changed it in the script to make it work again. // * Updated integrated Flickr - TopPager to version 1.0.5. // 2010-11-21 v1.2.1: // * experimatal adjustment on photo page: comments are displayed in a column left to the photo. // Can be disabled by setting CONF_DISPLAY_COMMENTS_AS_LEFT_COLUMN to false. // 2010-10-11 v1.2: // * fixed medium + sets view // * added logging functionality // * added widescreen display for sets overview page (Example: http://www.flickr.com/photos/barackobamadotcom/sets/) // * added @include for group pool // 2010-04-23 v1.1: // * added top pager functionality (http://userscripts.org/scripts/show/73290). // 2010-04-22 v1.0.2: // * added handling for photostream layout "Medium + sets" (big5). // * removed @require dependency from userscript metablock. // 2010-04-15 v1.0.1: // * some minor adjustments. // ==/Changelog== // --------------- // CONFIGURATION // --------------- const CONST_ENABLE_FIREBUG_LOGGING = false; // some "constants" for the script const CONST_MINIMUM_COLUMN_COUNT = 3; // minimum count of columns in photostream table. Should be at least 1. const CONST_MAIN_CONTAINER = "Main"; // id of main photostream div const CONST_CELL_WIDTH = 340; // width of a single photostream table cell (Used for AUTO ADJUSTMENT) const CONST_SETS_COLUMNS_WIDTH = 300; // width of the photostream's sets column const CONST_PHOTOSTREAM_WRAPPER = '//div[@class="PhotosColumn"]' // if CONF_AUTO_ADJUST is set to false, the values configured below, // are used to rearrange the photostream table. var CONF_AUTO_ADJUST = true; var CONF_COLUMN_COUNT = 3; // [AUTO ADJUSTED] count of columns. Cannot be set below CONST_MINIMUM_COLUMN_COUNT; var CONF_MAIN_CONTAINER_WIDTH = 1800; // [AUTO ADJUSTED] width of main container. Original width 800. // config for photostream layout "Medium + sets" var CONF_MEDIUM_SIZE_STREAM_RESIZE_ENABLED = true; // allows to disable resize of images in "Medium + sets" layout. var CONF_MEDIUM_SIZE_STREAM_MINIMUM_IMAGE_WIDTH = 340; // minimum size for resized images in "Medium + sets" layout. var CONF_ADD_TOP_PAGER = true; // allows to disable top pager. var CONF_DISPLAY_COMMENTS_AS_LEFT_COLUMN = true; // experimental: displays comments as left column on photo page // Flickr - TopPager CONFIGURATION (should not be changed) const CONST_PAGINATED_CONTENT_XPATH_PHOTOSTREAM = '//div[starts-with(@class,"PhotoStream")]'; const CONST_PAGINATED_CONTENT_XPATH_GROUP = '//div[@class="HoldPhotos"]'; const CONST_PAGINATED_CONTENT_ID_FAVORITES = 'favoriteThumbs'; // --------------- // --------------- // SCRIPT-MAIN // --------------- // 0. Prepare everything // init logging if(typeof console === "undefined" || !CONST_ENABLE_FIREBUG_LOGGING) { console = { log: function() { }, info: function() {}, debug: function() { } , warn: function() {}, error: function() {} }; } // add top pager if(CONF_ADD_TOP_PAGER) tryAddTopPager(); computeAdjustments(); // compute column resize parameters // I. Adjust main div width var mainEl = document.getElementById(CONST_MAIN_CONTAINER); if(mainEl == null) { // on some pages the main-container is named "Main" and on newer ones "main". mainEl = document.getElementById(CONST_MAIN_CONTAINER.toLowerCase()); } if(mainEl !== null) { mainEl.style.width = CONF_MAIN_CONTAINER_WIDTH + "px"; } // II.a Rearrange photostream ("Small + sets" layout) var elPhotoColumn = getElement(CONST_PHOTOSTREAM_WRAPPER); if(elPhotoColumn !== null) { elPhotoColumn.style.setProperty("width", (CONF_COLUMN_COUNT * CONST_CELL_WIDTH) + "px","important"); } // II.b Rearrange photostream ("Big wo sets" layout) elPhotoColumn = getElement('//div[@class="PhotosColumn Big5Column Big5NoSets"]'); if(elPhotoColumn !== null) { rearrangeLargeSizeLayoutPhotoStream(elPhotoColumn); } // // II.c Rearrange photostream in "Medium + sets" layout // oMediumSizeImageDivs = getElementSnapshots('//div[starts-with(@class,"StreamView Big5Photo")]'); // if(null != oMediumSizeImageDivs) // { // console.info("PageInfo: Photostream Medium + sets column"); // rearrangeMediumSizeLayoutPhotoStream(oMediumSizeImageDivs); // } // III. Remove width from favorites container, to adjust to new width of CONST_MAIN_CONTAINER. var oFavoritesContainer = document.getElementById('favoriteThumbs'); if(null != oFavoritesContainer) { console.info("PageInfo: Favorites"); oFavoritesContainer.style.width = "auto"; } // IV. Adjust width on set page var oSetContainer = document.getElementById('ViewSet'); if(null != oSetContainer) { console.info("PageInfo: Single set overview"); oSetContainer.style.width = "auto"; var el = getElement('//div[@class="vsThumbs"]'); el.style.width = (CONF_MAIN_CONTAINER_WIDTH-CONST_SETS_COLUMNS_WIDTH) + "px"; } // V. Handle Sets-Overview Page if(isSetsPage(document.URL)) { console.info("PageInfo: Set overview"); oBreaks = getElementSnapshots('//div[@class="Sets"]/following-sibling::br[@clear="all"]'); if(oBreaks != null) { for(i = 0; i < oBreaks.snapshotLength-3; i++) { obreakElement = oBreaks.snapshotItem(i); obreakElement.parentNode.removeChild(obreakElement); } } } // VI. Insert Widescreen next to Flickr logo insertLogo(); // VII. Experimental new photopage adjustment mainElNewPhotPage = document.getElementById("main"); if(null !== mainElNewPhotPage) { //console.info("PageInfo: New Photopage"); experimentalNewPhotoPageAdjust(mainElNewPhotPage); } // =============== // FUNCTION LIB // =============== function computeAdjustments() { // 0. auto config if(CONF_AUTO_ADJUST) { // compute count of fitting columns CONF_COLUMN_COUNT = Math.floor(window.innerWidth/CONST_CELL_WIDTH); console.debug("Computed count of columns fitting the window: " + CONF_COLUMN_COUNT); // by adjusting the width, the main content container on the photostream is moved to the left. // Otherwise the table with more columns, would be growing out of the main window to the right. CONF_MAIN_CONTAINER_WIDTH = (CONF_COLUMN_COUNT * CONST_CELL_WIDTH); // consider sets column. If sets column exists, the CONF_COLUMN_COUNT needs to be reduced by one. if(additionalRightColumnExists()) { CONF_COLUMN_COUNT = CONF_COLUMN_COUNT -1; console.debug("Additional right column exists. Count of fitting columns was reduced to " + CONF_COLUMN_COUNT); } } // apply minimum column count if(CONF_COLUMN_COUNT < CONST_MINIMUM_COLUMN_COUNT) CONF_COLUMN_COUNT = CONST_MINIMUM_COLUMN_COUNT } function additionalRightColumnExists() { return (collectionsColumnExists() || setsColumnExists()); } function setsColumnExists() { return elementExists('//*[@class="SetsColumn"]'); } function collectionsColumnExists() { return elementExists('//*[@class="CollectionsColumn"]'); } function isSetsPage(psUrl) { bResult = false; iUrlLength = psUrl.length; // main sets page wo pagination bNoPagination = psUrl.indexOf("/sets/") == iUrlLength-6; bResult = bNoPagination; console.debug("Is main set overview page: " + bNoPagination); if(!bNoPagination) { // is main sets page on a certain page iLastEqual = psUrl.lastIndexOf("="); sTestForSetsPaginated = "/sets/?&page"; sToTest = psUrl.substr(iLastEqual - sTestForSetsPaginated.length, sTestForSetsPaginated.length); bWithPagination = (sToTest == sTestForSetsPaginated); console.debug("Is main set overview page on a specific page: " + bWithPagination); bResult = bWithPagination; } return bResult; } function getOrignialPhotostreamTableElement() { // get orignal photostream table position return getElement('//td[@class="PhotosColumn"]//table'); } function rearrangeTable(poTableElement, piNewColumnCount) { var allHeaderCells = getAllPhotostreamHeaderCells(poTableElement); var allImgCells = getAllPhotostreamImageCells(poTableElement); // create new table element and replace orginal elTable = document.createElement("table"); elTable.innerHTML = buildTable(allHeaderCells, allImgCells, piNewColumnCount); return elTable; } function getAllPhotostreamHeaderCells(poTable) { return getElementSnapshotsFromContext(poTable, './/tr[@valign="bottom"]//td'); } function getAllPhotostreamImageCells(poTable) { return getElementSnapshotsFromContext(poTable,'.//tr[@valign="top"]//td'); } function buildTable(paAllHeaderCells, paAllImgCells, piColumnCount) { var tmpTableString = '