User:WindPower/Spai.js

From Team Fortress Wiki
< User:WindPower
Revision as of 20:17, 11 December 2010 by WindPower (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
var twitter = {
  widgets: [],
  ids: 0,
  init:function() {
    s = document.createElement('script');
    s.setAttribute('src', 'http://widgets.twimg.com/j/2/widget.js');
    document.getElementsByTagName('body')[0].appendChild(s);
    twitter.waitForTwitter();
  },
  waitForTwitter:function() {
      if(!window.TWTR) {
          setTimeout(twitter.waitForTwitter, 50);
      } else {
          twitter.findAll();
      }
  },
  findAll:function() {
      var allDivs = document.getElementsByTagName('div');
      var twits = []; // Gotta make static list, otherwise adding them as we go messes up d
      for(var i = 0; i < allDivs.length; i++) {
          if(!allDivs[i].getAttribute('class')) {
              continue;
          }
          if(allDivs[i].getAttribute('class').indexOf('twitterfeed-') != -1) {
              twits.push(allDivs[i]);
          }
      }
      for(i = 0; i < twits.length; i++) {
          twitter.create(twits[i]);
      }
  },
  create:function(d) {
      var newID = 'tf2twitterfeed-' + twitter.ids.toString();
      twitter.ids++;
      d.setAttribute('id', newID);
      var user = d.getAttribute('class').substr(d.getAttribute('class').indexOf('twitterfeed-') + 12);
      var w = new TWTR.Widget({
          id: newID,
          version: 2,
          type: 'profile',
          rpp: 16,
          interval: 6000,
          width: 300,
          height: 300,
          theme: {
              shell: {
                  background: '#333333',
                  color: '#ffffff'
              },
              tweets: {
                  background: '#000000',
                  color: '#ffffff',
                  links: '#4aed05'
              }
          },
          features: {
              scrollbar: true,
              loop: false,
              live: true,
              hashtags: true,
              timestamp: true,
              avatars: false,
              behavior: 'all'
          }
      });
      w.render().setUser(user).start();
      twitter.widgets.push(w);
  }
}
addOnloadHook(twitter.init);