Source for "Flickr: Show all images by a user in his/her groups"

By LouCypher
Has 84 other scripts.


// ==UserScript==
// @name           Flickr: Show all images by a user in his/her groups
// @namespace      http://loucypher.wordpress.com/
// @include        http://www.flickr.com/photos/*/*
// @include        http://flickr.com/photos/*/*
// ==/UserScript==

// Last updated: 2008-02-08

/*----------------------------------------------------------------------
    Discuss this script at:
    - http://userscripts.org/scripts/show/13160
    - http://flickr.com/groups/flickrhacks/discuss/72157602571419643/

    Inspired by Steeev's Show all images in pool by user GM script
    http://flickr.com/groups/flickrhacks/discuss/72157594144967671/
    http://userscripts.org/scripts/show/4366
  ----------------------------------------------------------------------*/

({
  stringBundle: [
    "All photos by this user in this pool", // en-us
    "Alle Fotos dieses Benutzers in diesem Pool", // de-de
      // Thanks to http://www.flickr.com/people/wolfman2/
    "Fotos de este usuario en este mural", // es-us
      // Thanks to http://www.flickr.com/people/lucamar/
    "Toutes les photos de cet utilisateur dans le pool", // fr-fr
    "Tutte le foto del utente in questo pool", // it-it
      // Thanks to http://www.flickr.com/people/mortimer/
    "", // reserved for ko-kr
    "", // reserved for pt-br
    ""  // reserved for zh-hk
  ],

  getLanguage: function() {
    var cookie = (typeof unsafeWindow == "object")
                  ? unsafeWindow._get_cookie("cookie_l10n")
                  : window._get_cookie("cookie_l10n");
    //GM_log(cookie);
    if (cookie) {
      return cookie.toString().replace(/\;\w+$/, "")
    } else {
      return null;
    }
  },

  getString: function() {
    var lang = this.getLanguage();
    switch (lang) {
      case "de-de": return this.stringBundle[1];
      case "es-us": return this.stringBundle[2];
      case "fr-fr": return this.stringBundle[3];
      case "it-it": return this.stringBundle[4];
      case "ko-kr": return this.stringBundle[5];
      case "pt-br": return this.stringBundle[6];
      case "zh-hk": return this.stringBundle[7];
      default: return this.stringBundle[0];
    }
  },

  getPools: function() {
    return document.evaluate("//a[starts-with(@id, 'contextLink_pool')]",
                             document, null, 6, null);
  },

  getBuddyIcon: function() {
    return document.evaluate("//div[@class='Widget']/a" +
                             "/img[@class='rightSideContactChanger'" +
                             " and contains(@src, 'buddyicon')]",
                             document, null, 9, null).singleNodeValue;
  },

  getUserID: function() {
    return this.getBuddyIcon()
      ? this.getBuddyIcon().src.split("#")[1]
      : null;
  },

  addLink: function(aNode, aURL) {
    var link = aNode.appendChild(document.createElement("a"));
    link.href = aURL;
    link.className = "Plain";
    link.style.fontSize = "smaller";
    link.appendChild(document.createTextNode(this.getString()))
  },

  needL10n: function(aNode) {
    if (this.getString() != "") return;
    var link = aNode.appendChild(document.createElement("a"));
    link.className = "Plain";
    link.style.fontSize = "smaller";
    link.style.marginLeft = ".5em";
    link.href = "/groups/flickrhacks/discuss/" +
                "72157602571419643/72157603610054214/";
    link.title = "Translate this to your language";
    link.appendChild(document.createTextNode("[?]"));
    link.previousSibling.textContent = this.stringBundle[0];
  },

  init: function() {
    var pools = this.getPools();
    var userID = this.getUserID();
    if (!(pools || userID || pools.snapshotLength)) return;
    var pool, url, group;
    for (var i = 0; i < pools.snapshotLength; i++) {
      pool = pools.snapshotItem(i);
      group = pool.parentNode;
      group.appendChild(document.createElement("br"))
      url = pool.href + userID;
      this.addLink(group, url);
      this.needL10n(group);
    }
  }

}).init()